Skip to content

Commit

Permalink
refactor(error): return inner error message
Browse files Browse the repository at this point in the history
  • Loading branch information
RainFallsSilent committed Jun 10, 2022
1 parent b17cec1 commit cbf900c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/transaction/transactionchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (t *DefaultChecker) SanityCheck(params interfaces.Parameters) elaerr.ELAErr

if err := t.parameters.Transaction.HeightVersionCheck(); err != nil {
log.Warn("[HeightVersionCheck],", err)
return elaerr.Simple(elaerr.ErrTxHeightVersion, nil)
return elaerr.Simple(elaerr.ErrTxHeightVersion, err)
}

if err := t.parameters.Transaction.CheckTransactionSize(); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion errors/errcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ type SimpleErr struct {

func (e *SimpleErr) Error() string {
if len(e.message) == 0 {
return fmt.Sprintf("%s", ErrMap[e.code])
if e.inner != nil {
return fmt.Sprintf("%s:%s", ErrMap[e.code], e.inner.Error())
} else {
return fmt.Sprintf("%s", ErrMap[e.code])
}
} else {
return e.message
}
Expand Down
20 changes: 10 additions & 10 deletions mempool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,30 @@ func (mp *TxPool) appendToTxPool(tx interfaces.Transaction) elaerr.ELAError {
return elaerr.Simple(elaerr.ErrBlockIneffectiveCoinbase, nil)
}

if errCode := chain.CheckTransactionSanity(bestHeight+1, tx); errCode != nil {
if err := chain.CheckTransactionSanity(bestHeight+1, tx); err != nil {
log.Warn("[TxPool CheckTransactionSanity] failed", tx.Hash())
return errCode
return err
}
if _, errCode := chain.CheckTransactionContext(
bestHeight+1, tx, mp.proposalsUsedAmount, 0); errCode != nil {
if _, err := chain.CheckTransactionContext(
bestHeight+1, tx, mp.proposalsUsedAmount, 0); err != nil {
log.Warnf("[TxPool CheckTransactionContext] failed, hash: %s, err: %s", tx.Hash(),
errCode)
return errCode
err)
return err
}
//verify transaction by pool with lock
if errCode := mp.verifyTransactionWithTxnPool(tx); errCode != nil {
if err := mp.verifyTransactionWithTxnPool(tx); err != nil {
log.Warn("[TxPool verifyTransactionWithTxnPool] failed", tx.Hash())
return errCode
return err
}

size := tx.GetSize()
if mp.txFees.OverSize(uint64(size)) {
log.Warn("TxPool check transactions size failed", tx.Hash())
return elaerr.Simple(elaerr.ErrTxPoolOverCapacity, nil)
}
if errCode := mp.AppendTx(tx); errCode != nil {
if err := mp.AppendTx(tx); err != nil {
log.Warn("[TxPool verifyTransactionWithTxnPool] failed", tx.Hash())
return errCode
return err
}
// Add the transaction to mem pool
if err := mp.doAddTransaction(tx); err != nil {
Expand Down

0 comments on commit cbf900c

Please sign in to comment.