diff --git a/core/blockchain.go b/core/blockchain.go index 61b809319c..e26f999c41 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -18,7 +18,6 @@ package core import ( - "errors" "fmt" "io" "math/big" @@ -42,7 +41,7 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" - "github.com/hashicorp/golang-lru" + lru "github.com/hashicorp/golang-lru" ) var ( @@ -1430,7 +1429,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i // If someone legitimately side-mines blocks, they would still be imported as usual. However, // we cannot risk writing unverified blocks to disk when they obviously target the pruning // mechanism. - return it.index, nil, nil, errors.New("sidechain ghost-state attack") + return it.index, nil, nil, ErrGhostStateAttack } } if externTd == nil { @@ -1473,7 +1472,7 @@ func (bc *BlockChain) insertSideChain(block *types.Block, it *insertIterator) (i parent = bc.GetHeader(parent.ParentHash, parent.Number.Uint64()-1) } if parent == nil { - return it.index, nil, nil, errors.New("missing parent") + return it.index, nil, nil, ErrMissingParent } // Import all the pruned blocks to make the state available var ( diff --git a/core/error.go b/core/error.go index cd4be3d705..005e4bb354 100644 --- a/core/error.go +++ b/core/error.go @@ -35,4 +35,61 @@ var ( // ErrNoGenesis is returned when there is no Genesis Block. ErrNoGenesis = errors.New("genesis not found in chain") + + // ErrGenesisNoConfig is retrurned when setup Genensis Block, if there is no + // ChainConfig. + ErrGenesisNoConfig = errors.New("genesis has no chain configuration") + + // ErrInsufficientBalanceForGas is returned if balance is insufficient to pay + // for gas + ErrInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas") + + // ErrInvalidSender is returned if the transaction contains an invalid signature. + ErrInvalidSender = errors.New("invalid sender") + + // ErrNonceTooLow is returned if the nonce of a transaction is lower than the + // one present in the local chain. + ErrNonceTooLow = errors.New("nonce too low") + + // ErrUnderpriced is returned if a transaction's gas price is below the minimum + // configured for the transaction pool. + ErrUnderpriced = errors.New("transaction underpriced") + + // ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced + // with a different one without the required price bump. + ErrReplaceUnderpriced = errors.New("replacement transaction underpriced") + + // ErrInsufficientFunds is returned if the total cost of executing a transaction + // is higher than the balance of the user's account. + ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value") + + // ErrIntrinsicGas is returned if the transaction is specified to use less gas + // than required to start the invocation. + ErrIntrinsicGas = errors.New("intrinsic gas too low") + + // ErrGasLimit is returned if a transaction's requested gas limit exceeds the + // maximum allowance of the current block. + ErrGasLimit = errors.New("exceeds block gas limit") + + // ErrNegativeValue is a sanity error to ensure noone is able to specify a + // transaction with a negative value. + ErrNegativeValue = errors.New("negative value") + + // ErrOversizedData is returned if the input data of a transaction is greater + // than some meaningful limit a user might use. This is not a consensus error + // making the transaction invalid, rather a DOS protection. + ErrOversizedData = errors.New("oversized data") + + // ErrNoActiveJournal is returned if a transaction is attempted to be inserted + // into the journal, but no such file is currently open. + ErrNoActiveJournal = errors.New("no active journal") + + // ErrGhostStateAttack is returned when sidechain ghost-state attack + ErrGhostStateAttack = errors.New("sidechain ghost-state attack") + + // ErrMissingParent is returned when parent block is nil + ErrMissingParent = errors.New("missing parent") + + // ErrPrematureAbort is returned when chain is terminating + ErrPrematureAbort = errors.New("aborted") ) diff --git a/core/genesis.go b/core/genesis.go index 1f34a3a9ea..96af2b0879 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -20,7 +20,6 @@ import ( "bytes" "encoding/hex" "encoding/json" - "errors" "fmt" "math/big" "strings" @@ -40,8 +39,6 @@ import ( //go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go //go:generate gencodec -type GenesisAccount -field-override genesisAccountMarshaling -out gen_genesis_account.go -var errGenesisNoConfig = errors.New("genesis has no chain configuration") - // Genesis specifies the header fields, state of a genesis block. It also defines hard // fork switch-over blocks through the chain configuration. type Genesis struct { @@ -155,7 +152,7 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig } func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, constantinopleOverride *big.Int) (*params.ChainConfig, common.Hash, error) { if genesis != nil && genesis.Config == nil { - return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig + return params.AllEthashProtocolChanges, common.Hash{}, ErrGenesisNoConfig } // Just commit the new block if there is no stored genesis block. stored := rawdb.ReadCanonicalHash(db, 0) diff --git a/core/headerchain.go b/core/headerchain.go index d0c1987fb5..9222b8f9c1 100644 --- a/core/headerchain.go +++ b/core/headerchain.go @@ -18,7 +18,6 @@ package core import ( crand "crypto/rand" - "errors" "fmt" "math" "math/big" @@ -240,7 +239,7 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int) // If the chain is terminating, stop processing blocks if hc.procInterrupt() { log.Debug("Premature abort during headers verification") - return 0, errors.New("aborted") + return 0, ErrPrematureAbort } // If the header is a banned one, straight out abort if BadHashes[header.Hash()] { @@ -271,7 +270,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa // Short circuit insertion if shutting down if hc.procInterrupt() { log.Debug("Premature abort during headers import") - return i, errors.New("aborted") + return i, ErrPrematureAbort } // If the header's already known, skip it, otherwise store if hc.HasHeader(header.Hash(), header.Number.Uint64()) { diff --git a/core/state_transition.go b/core/state_transition.go index fda081b7d1..2af04fe273 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -17,7 +17,6 @@ package core import ( - "errors" "math" "math/big" @@ -27,10 +26,6 @@ import ( "github.com/ethereum/go-ethereum/params" ) -var ( - errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas") -) - /* The State Transitioning Model @@ -152,7 +147,7 @@ func (st *StateTransition) useGas(amount uint64) error { func (st *StateTransition) buyGas() error { mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice) if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 { - return errInsufficientBalanceForGas + return ErrInsufficientBalanceForGas } if err := st.gp.SubGas(st.msg.Gas()); err != nil { return err diff --git a/core/tx_journal.go b/core/tx_journal.go index 41b5156d4a..792be830b7 100644 --- a/core/tx_journal.go +++ b/core/tx_journal.go @@ -17,7 +17,6 @@ package core import ( - "errors" "io" "os" @@ -27,10 +26,6 @@ import ( "github.com/ethereum/go-ethereum/rlp" ) -// errNoActiveJournal is returned if a transaction is attempted to be inserted -// into the journal, but no such file is currently open. -var errNoActiveJournal = errors.New("no active journal") - // devNull is a WriteCloser that just discards anything written into it. Its // goal is to allow the transaction journal to write into a fake journal when // loading transactions on startup without printing warnings due to no file @@ -119,7 +114,7 @@ func (journal *txJournal) load(add func([]*types.Transaction) []error) error { // insert adds the specified transaction to the local disk journal. func (journal *txJournal) insert(tx *types.Transaction) error { if journal.writer == nil { - return errNoActiveJournal + return ErrNoActiveJournal } if err := rlp.Encode(journal.writer, tx); err != nil { return err diff --git a/core/tx_pool.go b/core/tx_pool.go index 411143aeae..c2c6180386 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -17,7 +17,6 @@ package core import ( - "errors" "fmt" "math" "math/big" @@ -40,44 +39,6 @@ const ( chainHeadChanSize = 10 ) -var ( - // ErrInvalidSender is returned if the transaction contains an invalid signature. - ErrInvalidSender = errors.New("invalid sender") - - // ErrNonceTooLow is returned if the nonce of a transaction is lower than the - // one present in the local chain. - ErrNonceTooLow = errors.New("nonce too low") - - // ErrUnderpriced is returned if a transaction's gas price is below the minimum - // configured for the transaction pool. - ErrUnderpriced = errors.New("transaction underpriced") - - // ErrReplaceUnderpriced is returned if a transaction is attempted to be replaced - // with a different one without the required price bump. - ErrReplaceUnderpriced = errors.New("replacement transaction underpriced") - - // ErrInsufficientFunds is returned if the total cost of executing a transaction - // is higher than the balance of the user's account. - ErrInsufficientFunds = errors.New("insufficient funds for gas * price + value") - - // ErrIntrinsicGas is returned if the transaction is specified to use less gas - // than required to start the invocation. - ErrIntrinsicGas = errors.New("intrinsic gas too low") - - // ErrGasLimit is returned if a transaction's requested gas limit exceeds the - // maximum allowance of the current block. - ErrGasLimit = errors.New("exceeds block gas limit") - - // ErrNegativeValue is a sanity error to ensure noone is able to specify a - // transaction with a negative value. - ErrNegativeValue = errors.New("negative value") - - // ErrOversizedData is returned if the input data of a transaction is greater - // than some meaningful limit a user might use. This is not a consensus error - // making the transaction invalid, rather a DOS protection. - ErrOversizedData = errors.New("oversized data") -) - var ( evictionInterval = time.Minute // Time interval to check for evictable transactions statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats