Documentation ¶
Index ¶
- Constants
- Variables
- func AppendNewTestHeaders(headers []*types.Header, n int) []*types.Header
- func AppendNewTestheadersWithSeed(headers []*types.Header, n int, seed uint64) []*types.Header
- func HeadersToBlocks(headers []*types.Header) []*types.Block
- func NewTestHeaders(n int) []*types.Header
- func NewTestHeadersWithSeed(genesis *types.Header, n int, seed uint64) []*types.Header
- type BlockResult
- type Blockchain
- func NewBlockchain(logger hclog.Logger, config *chain.Chain, priceBottomLimit uint64, ...) (*Blockchain, error)
- func NewMockBlockchain(callbackMap map[TestCallbackType]interface{}) (*Blockchain, error)
- func NewTestBlockchain(t *testing.T, headers []*types.Header) *Blockchain
- func TestBlockchain(t *testing.T, genesis *chain.Genesis) *Blockchain
- func (b *Blockchain) CalculateGasLimit(number uint64) (uint64, error)
- func (b *Blockchain) ChainID() uint64
- func (b *Blockchain) Close() error
- func (b *Blockchain) ComputeGenesis() error
- func (b *Blockchain) Config() *chain.Params
- func (b *Blockchain) CurrentTD() *big.Int
- func (b *Blockchain) Empty() bool
- func (b *Blockchain) ForksInTime(number uint64) chain.ForksInTime
- func (b *Blockchain) Genesis() types.Hash
- func (b *Blockchain) GetBlock(hash types.Hash, number uint64, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBlockByHash(hash types.Hash, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBlockByNumber(blockNumber uint64, full bool) (*types.Block, bool)
- func (b *Blockchain) GetBodyByHash(hash types.Hash) (*types.Body, bool)
- func (b *Blockchain) GetChainTD() (*big.Int, bool)
- func (b *Blockchain) GetConsensus() Verifier
- func (b *Blockchain) GetForks() ([]types.Hash, error)
- func (b *Blockchain) GetHashByNumber(blockNumber uint64) types.Hash
- func (b *Blockchain) GetHashHelper(header *types.Header) func(i uint64) (res types.Hash)
- func (b *Blockchain) GetHeader(hash types.Hash, number uint64) (*types.Header, bool)
- func (b *Blockchain) GetHeaderByHash(hash types.Hash) (*types.Header, bool)
- func (b *Blockchain) GetHeaderByNumber(n uint64) (*types.Header, bool)
- func (b *Blockchain) GetHeaderHash() (types.Hash, bool)
- func (b *Blockchain) GetHeaderNumber() (uint64, bool)
- func (b *Blockchain) GetParent(header *types.Header) (*types.Header, bool)
- func (b *Blockchain) GetReceiptsByHash(hash types.Hash) ([]*types.Receipt, error)
- func (b *Blockchain) GetTD(hash types.Hash) (*big.Int, bool)
- func (b *Blockchain) Header() *types.Header
- func (b *Blockchain) ReadTxLookup(hash types.Hash) (types.Hash, bool)
- func (b *Blockchain) SetConsensus(c Verifier)
- func (b *Blockchain) SubscribeEvents() Subscription
- func (b *Blockchain) VerifyFinalizedBlock(block *types.Block) error
- func (b *Blockchain) VerifyPotentialBlock(block *types.Block) error
- func (b *Blockchain) WriteBlock(block *types.Block, source string) error
- func (b *Blockchain) WriteHeaders(headers []*types.Header) error
- func (b *Blockchain) WriteHeadersWithBodies(headers []*types.Header) error
- type Event
- type EventType
- type Executor
- type Metrics
- func (m *Metrics) BlockExecutionSecondsObserve(v float64)
- func (m *Metrics) BlockWrittenSecondsObserve(v float64)
- func (m *Metrics) GasPriceAverageObserve(v float64)
- func (m *Metrics) GasUsedObserve(v float64)
- func (m *Metrics) MaxGasPriceObserve(v float64)
- func (m *Metrics) SetBlockHeight(v float64)
- func (m *Metrics) TransactionNumObserve(v float64)
- type MockSubscription
- type MockVerifier
- func (m *MockVerifier) GetBlockCreator(header *types.Header) (types.Address, error)
- func (m *MockVerifier) HookGetBlockCreator(fn getBlockCreatorDelegate)
- func (m *MockVerifier) HookPreStateCommit(fn preStateCommitDelegate)
- func (m *MockVerifier) HookProcessHeaders(fn processHeadersDelegate)
- func (m *MockVerifier) HookVerifyHeader(fn verifyHeaderDelegate)
- func (m *MockVerifier) IsSystemTransaction(height uint64, coinbase types.Address, tx *types.Transaction) bool
- func (m *MockVerifier) PreStateCommit(header *types.Header, txn *state.Transition) error
- func (m *MockVerifier) ProcessHeaders(headers []*types.Header) error
- func (m *MockVerifier) VerifyHeader(header *types.Header) error
- type Subscription
- type TestCallbackType
- type Verifier
Constants ¶
const (
BlockGasTargetDivisor uint64 = 1024 // The bound divisor of the gas limit, used in update calculations
)
Variables ¶
var ( ErrNoBlock = errors.New("no block data passed in") ErrNoBlockHeader = errors.New("no block header data passed in") ErrParentNotFound = errors.New("parent block not found") ErrInvalidParentHash = errors.New("parent block hash is invalid") ErrParentHashMismatch = errors.New("invalid parent block hash") ErrInvalidBlockSequence = errors.New("invalid block sequence") ErrInvalidSha3Uncles = errors.New("invalid block sha3 uncles root") ErrInvalidTxRoot = errors.New("invalid block transactions root") ErrInvalidReceiptsSize = errors.New("invalid number of receipts") ErrInvalidStateRoot = errors.New("invalid block state root") ErrInvalidGasUsed = errors.New("invalid block gas used") ErrInvalidReceiptsRoot = errors.New("invalid block receipts root") ErrNilStorageBuilder = errors.New("nil storage builder") ErrClosed = errors.New("blockchain is closed") )
Functions ¶
func AppendNewTestHeaders ¶ added in v0.5.3
AppendNewTestHeaders creates n new headers from an already existing chain
func AppendNewTestheadersWithSeed ¶ added in v0.5.3
AppendNewTestheadersWithSeed creates n new headers from an already existing chain
func NewTestHeaders ¶ added in v0.5.3
NewTestHeaders creates a chain of valid headers
Types ¶
type BlockResult ¶
type Blockchain ¶
type Blockchain struct {
// contains filtered or unexported fields
}
Blockchain is a blockchain reference
func NewBlockchain ¶
func NewBlockchain( logger hclog.Logger, config *chain.Chain, priceBottomLimit uint64, storageBuilder storage.StorageBuilder, consensus Verifier, executor Executor, metrics *Metrics, ) (*Blockchain, error)
NewBlockchain creates a new blockchain object
func NewMockBlockchain ¶ added in v0.5.3
func NewMockBlockchain( callbackMap map[TestCallbackType]interface{}, ) (*Blockchain, error)
NewMockBlockchain constructs a new mock blockchain
func NewTestBlockchain ¶
func NewTestBlockchain(t *testing.T, headers []*types.Header) *Blockchain
NewTestBlockchain creates a new dummy blockchain for testing
func TestBlockchain ¶
func TestBlockchain(t *testing.T, genesis *chain.Genesis) *Blockchain
func (*Blockchain) CalculateGasLimit ¶
func (b *Blockchain) CalculateGasLimit(number uint64) (uint64, error)
CalculateGasLimit returns the gas limit of the next block after parent
func (*Blockchain) ChainID ¶ added in v1.2.4
func (b *Blockchain) ChainID() uint64
func (*Blockchain) ComputeGenesis ¶
func (b *Blockchain) ComputeGenesis() error
ComputeGenesis computes the genesis hash, and updates the blockchain reference
func (*Blockchain) Config ¶
func (b *Blockchain) Config() *chain.Params
Config returns the blockchain configuration
func (*Blockchain) CurrentTD ¶
func (b *Blockchain) CurrentTD() *big.Int
CurrentTD returns the current total difficulty (atomic)
func (*Blockchain) Empty ¶
func (b *Blockchain) Empty() bool
Empty checks if the blockchain is empty
func (*Blockchain) ForksInTime ¶ added in v1.2.4
func (b *Blockchain) ForksInTime(number uint64) chain.ForksInTime
func (*Blockchain) Genesis ¶
func (b *Blockchain) Genesis() types.Hash
Genesis returns the genesis block
func (*Blockchain) GetBlockByHash ¶
GetBlockByHash returns the block using the block hash
func (*Blockchain) GetBlockByNumber ¶
GetBlockByNumber returns the block using the block number
func (*Blockchain) GetBodyByHash ¶
GetBodyByHash returns the body by their hash
func (*Blockchain) GetChainTD ¶
func (b *Blockchain) GetChainTD() (*big.Int, bool)
GetChainTD returns the latest difficulty
func (*Blockchain) GetConsensus ¶
func (b *Blockchain) GetConsensus() Verifier
func (*Blockchain) GetForks ¶
func (b *Blockchain) GetForks() ([]types.Hash, error)
GetForks returns the forks
func (*Blockchain) GetHashByNumber ¶
func (b *Blockchain) GetHashByNumber(blockNumber uint64) types.Hash
GetHashByNumber returns the block hash using the block number
func (*Blockchain) GetHashHelper ¶
GetHashHelper is used by the EVM, so that the SC can get the hash of the header number
func (*Blockchain) GetHeaderByHash ¶
GetHeaderByHash returns the header by his hash
func (*Blockchain) GetHeaderByNumber ¶
func (b *Blockchain) GetHeaderByNumber(n uint64) (*types.Header, bool)
GetHeaderByNumber returns the header using the block number
func (*Blockchain) GetHeaderHash ¶ added in v1.2.2
func (b *Blockchain) GetHeaderHash() (types.Hash, bool)
GetHeaderHash returns the current header hash
func (*Blockchain) GetHeaderNumber ¶ added in v1.2.2
func (b *Blockchain) GetHeaderNumber() (uint64, bool)
GetHeaderNumber returns the current header number
func (*Blockchain) GetReceiptsByHash ¶
GetReceiptsByHash returns the receipts by their hash
func (*Blockchain) Header ¶
func (b *Blockchain) Header() *types.Header
Header returns the current header (atomic)
func (*Blockchain) ReadTxLookup ¶
ReadTxLookup returns the block hash using the transaction hash
func (*Blockchain) SetConsensus ¶
func (b *Blockchain) SetConsensus(c Verifier)
SetConsensus sets the consensus
func (*Blockchain) SubscribeEvents ¶
func (b *Blockchain) SubscribeEvents() Subscription
SubscribeEvents returns a blockchain event subscription
func (*Blockchain) VerifyFinalizedBlock ¶ added in v0.5.3
func (b *Blockchain) VerifyFinalizedBlock(block *types.Block) error
VerifyFinalizedBlock verifies that the block is valid by performing a series of checks. It is assumed that the block status is sealed (committed)
func (*Blockchain) VerifyPotentialBlock ¶ added in v0.5.3
func (b *Blockchain) VerifyPotentialBlock(block *types.Block) error
VerifyPotentialBlock does the minimal block verification without consulting the consensus layer. Should only be used if consensus checks are done outside the method call
func (*Blockchain) WriteBlock ¶
func (b *Blockchain) WriteBlock(block *types.Block, source string) error
WriteBlock writes a single block
func (*Blockchain) WriteHeaders ¶
func (b *Blockchain) WriteHeaders(headers []*types.Header) error
WriteHeaders writes an array of headers
func (*Blockchain) WriteHeadersWithBodies ¶
func (b *Blockchain) WriteHeadersWithBodies(headers []*types.Header) error
WriteHeadersWithBodies writes a batch of headers
type Event ¶
type Event struct { // Old chain (removed headers) if there was a reorg OldChain []*types.Header // New part of the chain (or a fork) NewChain []*types.Header // Difficulty is the new difficulty created with this event Difficulty *big.Int // Type is the type of event Type EventType // Source is the source that generated the blocks for the event // right now it can be either the Sealer or the Syncer Source string }
Event is the blockchain event that gets passed to the listeners
func (*Event) AddNewHeader ¶
AddNewHeader appends a header to the event's NewChain array
func (*Event) AddOldHeader ¶
AddOldHeader appends a header to the event's OldChain array
func (*Event) SetDifficulty ¶
SetDifficulty sets the event difficulty
type Executor ¶
type Executor interface { BeginTxn(parentRoot types.Hash, header *types.Header, coinbase types.Address) (*state.Transition, error) //nolint:lll ProcessTransactions(transition *state.Transition, gasLimit uint64, transactions []*types.Transaction) (*state.Transition, error) Stop() }
type Metrics ¶ added in v1.2.0
type Metrics struct {
// contains filtered or unexported fields
}
Metrics represents the blockchain metrics
func GetPrometheusMetrics ¶ added in v1.2.0
GetPrometheusMetrics return the blockchain metrics instance
func NewDummyMetrics ¶ added in v1.2.0
NewDummyMetrics will return the no nil blockchain metrics TODO: use generic replace this in golang 1.18
func NilMetrics ¶ added in v1.2.0
func NilMetrics() *Metrics
NilMetrics will return the non operational blockchain metrics
func (*Metrics) BlockExecutionSecondsObserve ¶ added in v1.2.2
func (*Metrics) BlockWrittenSecondsObserve ¶ added in v1.2.2
func (*Metrics) GasPriceAverageObserve ¶ added in v1.2.2
func (*Metrics) GasUsedObserve ¶ added in v1.2.2
func (*Metrics) MaxGasPriceObserve ¶ added in v1.2.4
func (*Metrics) SetBlockHeight ¶ added in v1.2.2
func (*Metrics) TransactionNumObserve ¶ added in v1.2.2
type MockSubscription ¶
type MockSubscription struct {
// contains filtered or unexported fields
}
func NewMockSubscription ¶
func NewMockSubscription() *MockSubscription
func (*MockSubscription) GetEvent ¶
func (m *MockSubscription) GetEvent() <-chan *Event
func (*MockSubscription) IsClosed ¶ added in v1.2.4
func (m *MockSubscription) IsClosed() bool
func (*MockSubscription) Push ¶
func (m *MockSubscription) Push(e *Event)
func (*MockSubscription) Unsubscribe ¶ added in v1.2.4
func (m *MockSubscription) Unsubscribe()
type MockVerifier ¶
type MockVerifier struct {
// contains filtered or unexported fields
}
func (*MockVerifier) GetBlockCreator ¶
func (*MockVerifier) HookGetBlockCreator ¶ added in v0.5.3
func (m *MockVerifier) HookGetBlockCreator(fn getBlockCreatorDelegate)
func (*MockVerifier) HookPreStateCommit ¶ added in v0.5.3
func (m *MockVerifier) HookPreStateCommit(fn preStateCommitDelegate)
func (*MockVerifier) HookProcessHeaders ¶ added in v0.5.3
func (m *MockVerifier) HookProcessHeaders(fn processHeadersDelegate)
func (*MockVerifier) HookVerifyHeader ¶ added in v0.5.3
func (m *MockVerifier) HookVerifyHeader(fn verifyHeaderDelegate)
func (*MockVerifier) IsSystemTransaction ¶ added in v1.2.0
func (m *MockVerifier) IsSystemTransaction(height uint64, coinbase types.Address, tx *types.Transaction) bool
func (*MockVerifier) PreStateCommit ¶
func (m *MockVerifier) PreStateCommit(header *types.Header, txn *state.Transition) error
func (*MockVerifier) ProcessHeaders ¶
func (m *MockVerifier) ProcessHeaders(headers []*types.Header) error
func (*MockVerifier) VerifyHeader ¶
func (m *MockVerifier) VerifyHeader(header *types.Header) error
type Subscription ¶
Subscription is the blockchain subscription interface
type TestCallbackType ¶ added in v0.5.3
type TestCallbackType string
const ( VerifierCallback TestCallbackType = "VerifierCallback" ExecutorCallback TestCallbackType = "ExecutorCallback" ChainCallback TestCallbackType = "ChainCallback" StorageCallback TestCallbackType = "StorageCallback" )
type Verifier ¶
type Verifier interface { VerifyHeader(header *types.Header) error ProcessHeaders(headers []*types.Header) error GetBlockCreator(header *types.Header) (types.Address, error) PreStateCommit(header *types.Header, txn *state.Transition) error IsSystemTransaction(height uint64, coinbase types.Address, tx *types.Transaction) bool }