mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
move error variable to error.go
This commit is contained in:
parent
07d2d83c31
commit
4756ef5373
7 changed files with 65 additions and 62 deletions
|
|
@ -18,7 +18,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -42,7 +41,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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,
|
// 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
|
// we cannot risk writing unverified blocks to disk when they obviously target the pruning
|
||||||
// mechanism.
|
// mechanism.
|
||||||
return it.index, nil, nil, errors.New("sidechain ghost-state attack")
|
return it.index, nil, nil, ErrGhostStateAttack
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if externTd == nil {
|
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)
|
parent = bc.GetHeader(parent.ParentHash, parent.Number.Uint64()-1)
|
||||||
}
|
}
|
||||||
if parent == nil {
|
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
|
// Import all the pruned blocks to make the state available
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,61 @@ var (
|
||||||
|
|
||||||
// ErrNoGenesis is returned when there is no Genesis Block.
|
// ErrNoGenesis is returned when there is no Genesis Block.
|
||||||
ErrNoGenesis = errors.New("genesis not found in chain")
|
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")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
@ -40,8 +39,6 @@ import (
|
||||||
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
|
//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
|
//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
|
// Genesis specifies the header fields, state of a genesis block. It also defines hard
|
||||||
// fork switch-over blocks through the chain configuration.
|
// fork switch-over blocks through the chain configuration.
|
||||||
type Genesis struct {
|
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) {
|
func SetupGenesisBlockWithOverride(db ethdb.Database, genesis *Genesis, constantinopleOverride *big.Int) (*params.ChainConfig, common.Hash, error) {
|
||||||
if genesis != nil && genesis.Config == nil {
|
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.
|
// Just commit the new block if there is no stored genesis block.
|
||||||
stored := rawdb.ReadCanonicalHash(db, 0)
|
stored := rawdb.ReadCanonicalHash(db, 0)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
crand "crypto/rand"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -240,7 +239,7 @@ func (hc *HeaderChain) ValidateHeaderChain(chain []*types.Header, checkFreq int)
|
||||||
// If the chain is terminating, stop processing blocks
|
// If the chain is terminating, stop processing blocks
|
||||||
if hc.procInterrupt() {
|
if hc.procInterrupt() {
|
||||||
log.Debug("Premature abort during headers verification")
|
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 the header is a banned one, straight out abort
|
||||||
if BadHashes[header.Hash()] {
|
if BadHashes[header.Hash()] {
|
||||||
|
|
@ -271,7 +270,7 @@ func (hc *HeaderChain) InsertHeaderChain(chain []*types.Header, writeHeader WhCa
|
||||||
// Short circuit insertion if shutting down
|
// Short circuit insertion if shutting down
|
||||||
if hc.procInterrupt() {
|
if hc.procInterrupt() {
|
||||||
log.Debug("Premature abort during headers import")
|
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 the header's already known, skip it, otherwise store
|
||||||
if hc.HasHeader(header.Hash(), header.Number.Uint64()) {
|
if hc.HasHeader(header.Hash(), header.Number.Uint64()) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
|
@ -27,10 +26,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
errInsufficientBalanceForGas = errors.New("insufficient balance to pay for gas")
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
The State Transitioning Model
|
The State Transitioning Model
|
||||||
|
|
||||||
|
|
@ -152,7 +147,7 @@ func (st *StateTransition) useGas(amount uint64) error {
|
||||||
func (st *StateTransition) buyGas() error {
|
func (st *StateTransition) buyGas() error {
|
||||||
mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice)
|
mgval := new(big.Int).Mul(new(big.Int).SetUint64(st.msg.Gas()), st.gasPrice)
|
||||||
if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 {
|
if st.state.GetBalance(st.msg.From()).Cmp(mgval) < 0 {
|
||||||
return errInsufficientBalanceForGas
|
return ErrInsufficientBalanceForGas
|
||||||
}
|
}
|
||||||
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
|
if err := st.gp.SubGas(st.msg.Gas()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -27,10 +26,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"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
|
// 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
|
// 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
|
// 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.
|
// insert adds the specified transaction to the local disk journal.
|
||||||
func (journal *txJournal) insert(tx *types.Transaction) error {
|
func (journal *txJournal) insert(tx *types.Transaction) error {
|
||||||
if journal.writer == nil {
|
if journal.writer == nil {
|
||||||
return errNoActiveJournal
|
return ErrNoActiveJournal
|
||||||
}
|
}
|
||||||
if err := rlp.Encode(journal.writer, tx); err != nil {
|
if err := rlp.Encode(journal.writer, tx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -40,44 +39,6 @@ const (
|
||||||
chainHeadChanSize = 10
|
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 (
|
var (
|
||||||
evictionInterval = time.Minute // Time interval to check for evictable transactions
|
evictionInterval = time.Minute // Time interval to check for evictable transactions
|
||||||
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
|
statsReportInterval = 8 * time.Second // Time interval to report transaction pool stats
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue