Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions common/yerror/basic_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ var NoKvdbType = errors.New("no kvdb type")
var NoSqlDbType = errors.New("no sqlDB type")

var (
PoolOverflow error = errors.New("pool size is full")
TxnTimeoutErr error = errors.New("Txn time out")
TxnTooLarge error = errors.New("the size of txn is too large")
TxnDuplicated error = errors.New("Transaction duplicated")
PoolOverflow error = errors.New("pool size is full")
TxnTimeoutErr error = errors.New("Txn time out")
TxnTooLarge error = errors.New("the size of txn is too large")
TxnDuplicated error = errors.New("Transaction duplicated")
ChainIDIllegal error = errors.New("chain id illegal")
)

var ErrBlockNotFound error = errors.New("block not found")
Expand Down
21 changes: 13 additions & 8 deletions core/kernel/handle_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ func (k *Kernel) handleTxnLocally(stxn *SignedTxn, topic string) error {
return err
}
}
if k.CheckReplayAttack(stxn) {
return yerror.TxnDuplicated
err := k.CheckReplayAttack(stxn)
if err != nil {
return err
}
err := k.Pool.CheckTxn(stxn)
err = k.Pool.CheckTxn(stxn)
if err != nil {
return err
}
Expand All @@ -97,14 +98,18 @@ func (k *Kernel) HandleReading(rdCall *common.RdCall) (*context.ResponseData, er
return ctx.Response(), nil
}

func (k *Kernel) CheckReplayAttack(txn *SignedTxn) bool {
func (k *Kernel) CheckReplayAttack(txn *SignedTxn) error {
if k.Chain.ChainID() != txn.ChainID() {
return yerror.ChainIDIllegal
}
if k.Pool.Exist(txn.TxnHash) {
return true
return yerror.TxnDuplicated
}
if k.Chain.ChainID() != txn.ChainID() {
return true

if k.TxDB.ExistTxn(txn.TxnHash) {
return yerror.TxnDuplicated
}
return k.TxDB.ExistTxn(txn.TxnHash)
return nil
}

//func getRdFromHttp(req *http.Request, params string) (rdCall *RdCall, err error) {
Expand Down
4 changes: 2 additions & 2 deletions core/kernel/kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (k *Kernel) AcceptUnpackedTxns() error {
}

for _, txn := range writings {
if k.CheckReplayAttack(txn) {
if err := k.CheckReplayAttack(txn); err != nil {
continue
}
txn.FromP2P = true
Expand Down Expand Up @@ -130,7 +130,7 @@ func (k *Kernel) AcceptUnpackedTxns() error {
if txn == nil {
continue
}
if k.CheckReplayAttack(txn) {
if err := k.CheckReplayAttack(txn); err != nil {
continue
}
txn.FromP2P = true
Expand Down
Loading