core

package
v0.0.0-...-8ad5b9e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHashFn

func GetHashFn(ref *types.Header, chain ChainContext) func(n uint64) common.Hash

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func NewEVMBlockContext

func NewEVMBlockContext(header *types.Header, chain *BlockChain, author *common.Address, config *params.ChainConfig) vm.BlockContext

NewEVMBlockContext creates a new context for use in the EVM.

func SetupGenesisBlockWithOverride

func SetupGenesisBlockWithOverride(ctx context.Context, db ethdb.Database, triedb *trie.Database, genesis *Genesis, overrides *core.ChainOverrides, ethClient *ethclient.Client) (*params.ChainConfig, common.Hash, error)

func TransactionToMessage

func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.Int, config *params.ChainConfig) (*core.Message, error)

TransactionToMessage converts a transaction into a Message.

Types

type BlockChain

type BlockChain struct {
	// contains filtered or unexported fields
}

func NewBlockChain

func NewBlockChain(db ethdb.Database, cacheConfig *core.CacheConfig, genesis *Genesis, overrides *core.ChainOverrides, engine miveconsensus.Engine, vmConfig vm.Config, ethClient *ethclient.Client) (*BlockChain, error)

func (*BlockChain) Config

func (bc *BlockChain) Config() *miveparams.ChainConfig

Config retrieves the chain's fork configuration.

func (*BlockChain) CurrentBlock

func (bc *BlockChain) CurrentBlock() *mivetypes.Header

CurrentBlock retrieves the current head block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentFinalBlock

func (bc *BlockChain) CurrentFinalBlock() *mivetypes.Header

CurrentFinalBlock retrieves the current finalized block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentHeader

func (bc *BlockChain) CurrentHeader() *mivetypes.Header

CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.

func (*BlockChain) CurrentSafeBlock

func (bc *BlockChain) CurrentSafeBlock() *mivetypes.Header

CurrentSafeBlock retrieves the current safe block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) CurrentSnapBlock

func (bc *BlockChain) CurrentSnapBlock() *mivetypes.Header

CurrentSnapBlock retrieves the current snap-sync head block of the canonical chain. The block is retrieved from the blockchain's internal cache.

func (*BlockChain) Engine

func (bc *BlockChain) Engine() miveconsensus.Engine

Engine retrieves the blockchain's consensus engine.

func (*BlockChain) EthCurrentHeader

func (bc *BlockChain) EthCurrentHeader() *types.Header

func (*BlockChain) EthGetHeader

func (bc *BlockChain) EthGetHeader(hash common.Hash, number uint64) *types.Header

EthGetHeader retrieves a block header from the database by hash and number.

func (*BlockChain) EthGetHeaderByHash

func (bc *BlockChain) EthGetHeaderByHash(hash common.Hash) *types.Header

func (*BlockChain) EthGetHeaderByNumber

func (bc *BlockChain) EthGetHeaderByNumber(number uint64) *types.Header

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *mivetypes.Header

Genesis retrieves the chain's genesis header.

func (*BlockChain) GetAncestor

func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)

GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the number of blocks to be individually checked before we reach the canonical chain.

Note: ancestor == 0 returns the same block, 1 returns its parent and so on.

func (*BlockChain) GetBlock

func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block

GetBlock retrieves a block by hash and number, caching it if found.

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block

GetBlockByHash retrieves a block by hash, caching it if found.

func (*BlockChain) GetBlockByNumber

func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block

GetBlockByNumber retrieves a block by number, caching it (associated with its hash) if found.

func (*BlockChain) GetCanonicalHash

func (bc *BlockChain) GetCanonicalHash(number uint64) common.Hash

GetCanonicalHash returns the canonical hash for a given block number

func (*BlockChain) GetHeader

func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *mivetypes.Header

GetHeader retrieves a block header from the database by hash and number, caching it if found.

func (*BlockChain) GetHeaderByHash

func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *mivetypes.Header

GetHeaderByHash retrieves a block header from the database by hash, caching it if found.

func (*BlockChain) GetHeaderByNumber

func (bc *BlockChain) GetHeaderByNumber(number uint64) *mivetypes.Header

GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.

func (*BlockChain) GetHeadersFrom

func (bc *BlockChain) GetHeadersFrom(number, count uint64) []rlp.RawValue

GetHeadersFrom returns a contiguous segment of headers, in rlp-form, going backwards from the given number.

func (*BlockChain) GetReceiptsByHash

func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) types.Receipts

GetReceiptsByHash retrieves the receipts for all transactions in a given block.

func (*BlockChain) GetVMConfig

func (bc *BlockChain) GetVMConfig() *vm.Config

GetVMConfig returns the block chain VM config.

func (*BlockChain) HasBlockAndState

func (bc *BlockChain) HasBlockAndState(hash common.Hash, number uint64) bool

HasBlockAndState checks if a block and associated state trie is fully present in the database or not, caching it if present.

func (*BlockChain) HasHeader

func (bc *BlockChain) HasHeader(hash common.Hash, number uint64) bool

HasHeader checks if a block header is present in the database or not, caching it if present.

func (*BlockChain) HasState

func (bc *BlockChain) HasState(hash common.Hash) bool

HasState checks if state trie is fully present in the database or not.

func (*BlockChain) Processor

func (bc *BlockChain) Processor() core.Processor

Processor returns the current processor.

func (*BlockChain) Reset

func (bc *BlockChain) Reset() error

Reset purges the entire blockchain, restoring it to its genesis state.

func (*BlockChain) ResetWithGenesisBlock

func (bc *BlockChain) ResetWithGenesisBlock(genesis *mivetypes.Header) error

ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.

func (*BlockChain) SetFinalized

func (bc *BlockChain) SetFinalized(header *mivetypes.Header)

SetFinalized sets the finalized block.

func (*BlockChain) SetHead

func (bc *BlockChain) SetHead(head uint64) error

SetHead rewinds the local chain to a new head. Depending on whether the node was snap synced or full synced and in which state, the method will try to delete minimal data from disk whilst retaining chain consistency.

func (*BlockChain) SetHeadWithTimestamp

func (bc *BlockChain) SetHeadWithTimestamp(timestamp uint64) error

SetHeadWithTimestamp rewinds the local chain to a new head that has at max the given timestamp. Depending on whether the node was snap synced or full synced and in which state, the method will try to delete minimal data from disk whilst retaining chain consistency.

func (*BlockChain) SetSafe

func (bc *BlockChain) SetSafe(header *mivetypes.Header)

SetSafe sets the safe block.

func (*BlockChain) Snapshots

func (bc *BlockChain) Snapshots() *snapshot.Tree

Snapshots returns the blockchain snapshot tree.

func (*BlockChain) State

func (bc *BlockChain) State() (*state.StateDB, error)

State returns a new mutable state based on the current HEAD block.

func (*BlockChain) StateAt

func (bc *BlockChain) StateAt(root common.Hash) (*state.StateDB, error)

StateAt returns a new mutable state based on a particular point in time.

func (*BlockChain) StateCache

func (bc *BlockChain) StateCache() state.Database

StateCache returns the caching database underpinning the blockchain instance.

func (*BlockChain) StopInsert

func (bc *BlockChain) StopInsert()

StopInsert interrupts all insertion methods, causing them to return errInsertionInterrupted as soon as possible. Insertion is permanently disabled after calling this method.

func (*BlockChain) SubscribeBlockProcessingEvent

func (bc *BlockChain) SubscribeBlockProcessingEvent(ch chan<- bool) event.Subscription

SubscribeBlockProcessingEvent registers a subscription of bool where true means block processing has started while false means it has stopped.

func (*BlockChain) SubscribeChainEvent

func (bc *BlockChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription

SubscribeChainEvent registers a subscription of ChainEvent.

func (*BlockChain) SubscribeChainHeadEvent

func (bc *BlockChain) SubscribeChainHeadEvent(ch chan<- core.ChainHeadEvent) event.Subscription

SubscribeChainHeadEvent registers a subscription of ChainHeadEvent.

func (*BlockChain) SubscribeChainSideEvent

func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- core.ChainSideEvent) event.Subscription

SubscribeChainSideEvent registers a subscription of ChainSideEvent.

func (*BlockChain) SubscribeLogsEvent

func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription

SubscribeLogsEvent registers a subscription of []*types.Log.

func (*BlockChain) SubscribeRemovedLogsEvent

func (bc *BlockChain) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) event.Subscription

SubscribeRemovedLogsEvent registers a subscription of RemovedLogsEvent.

func (*BlockChain) TrieDB

func (bc *BlockChain) TrieDB() *trie.Database

TrieDB retrieves the low level trie database used for data storage.

func (*BlockChain) Validator

func (bc *BlockChain) Validator() core.Validator

Validator returns the current validator.

type BlockChainWrapper

type BlockChainWrapper struct {
	*BlockChain
}

func (*BlockChainWrapper) Engine

func (bc *BlockChainWrapper) Engine() consensus.Engine

func (*BlockChainWrapper) GetHeader

func (bc *BlockChainWrapper) GetHeader(hash common.Hash, number uint64) *types.Header

type ChainContext

type ChainContext interface {
	// Engine retrieves the chain's consensus engine.
	Engine() miveconsensus.Engine

	// GetHeader returns the header corresponding to the hash/number argument pair.
	GetHeader(common.Hash, uint64) *mivetypes.Header
}

ChainContext supports retrieving headers and consensus parameters from the current blockchain to be used during transaction processing.

type DeleteBlockContentCallback

type DeleteBlockContentCallback = core.DeleteBlockContentCallback

DeleteBlockContentCallback is a callback function that is called by SetHead before each header is deleted.

type Genesis

type Genesis struct {
	Config *params.ChainConfig `json:"config"`
	Alloc  GenesisAlloc        `json:"alloc" gencodec:"required"`
}

func DefaultGenesisBlock

func DefaultGenesisBlock() *Genesis

DefaultGenesisBlock returns the Mive genesis block for the Ethereum mainnet.

func (*Genesis) Commit

func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database, block *types.Block) (*mivetypes.Header, error)

func (*Genesis) IsVerkle

func (g *Genesis) IsVerkle(block *types.Block) bool

IsVerkle indicates whether the state is already stored in a verkle tree at genesis time.

func (*Genesis) ToHeader

func (g *Genesis) ToHeader(block *types.Block) *mivetypes.Header

ToHeader returns the genesis block header according to genesis specification.

type GenesisAlloc

type GenesisAlloc core.GenesisAlloc

GenesisAlloc specifies the initial state that is part of the genesis block.

func (*GenesisAlloc) UnmarshalJSON

func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error

type HeaderChain

type HeaderChain struct {
	// contains filtered or unexported fields
}

HeaderChain implements the basic block header chain logic that is used by BlockChain.

HeaderChain is responsible for maintaining the header chain including the header query and updating.

The components maintained by headerchain includes: (1) header (2) block hash -> number mapping (3) canonical number -> hash mapping and (4) head header flag.

It is not thread safe either, the encapsulating chain structures should do the necessary mutex locking/unlocking.

func NewHeaderChain

func NewHeaderChain(chainDb ethdb.Database, config *params.ChainConfig, engine miveconsensus.Engine, procInterrupt func() bool) (*HeaderChain, error)

NewHeaderChain creates a new HeaderChain structure. ProcInterrupt points to the parent's interrupt semaphore.

func (*HeaderChain) Config

func (hc *HeaderChain) Config() *params.ChainConfig

Config retrieves the header chain's chain configuration.

func (*HeaderChain) CurrentHeader

func (hc *HeaderChain) CurrentHeader() *mivetypes.Header

CurrentHeader retrieves the current head header of the canonical chain. The header is retrieved from the HeaderChain's internal cache.

func (*HeaderChain) GetAncestor

func (hc *HeaderChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)

GetAncestor retrieves the Nth ancestor of a given block. It assumes that either the given block or a close ancestor of it is canonical. maxNonCanonical points to a downwards counter limiting the number of blocks to be individually checked before we reach the canonical chain.

Note: ancestor == 0 returns the same block, 1 returns its parent and so on.

func (*HeaderChain) GetBlockNumber

func (hc *HeaderChain) GetBlockNumber(hash common.Hash) *uint64

GetBlockNumber retrieves the block number belonging to the given hash from the cache or database

func (*HeaderChain) GetCanonicalHash

func (hc *HeaderChain) GetCanonicalHash(number uint64) common.Hash

func (*HeaderChain) GetHeader

func (hc *HeaderChain) GetHeader(hash common.Hash, number uint64) *mivetypes.Header

GetHeader retrieves a block header from the database by hash and number, caching it if found.

func (*HeaderChain) GetHeaderByHash

func (hc *HeaderChain) GetHeaderByHash(hash common.Hash) *mivetypes.Header

GetHeaderByHash retrieves a block header from the database by hash, caching it if found.

func (*HeaderChain) GetHeaderByNumber

func (hc *HeaderChain) GetHeaderByNumber(number uint64) *mivetypes.Header

GetHeaderByNumber retrieves a block header from the database by number, caching it (associated with its hash) if found.

func (*HeaderChain) GetHeadersFrom

func (hc *HeaderChain) GetHeadersFrom(number, count uint64) []rlp.RawValue

GetHeadersFrom returns a contiguous segment of headers, in rlp-form, going backwards from the given number. If the 'number' is higher than the highest local header, this method will return a best-effort response, containing the headers that we do have.

func (*HeaderChain) HasHeader

func (hc *HeaderChain) HasHeader(hash common.Hash, number uint64) bool

HasHeader checks if a block header is present in the database or not. In theory, if header is present in the database, all relative components like td and hash->number should be present too.

func (*HeaderChain) InsertHeaderChain

func (hc *HeaderChain) InsertHeaderChain(chain []*mivetypes.Header, start time.Time) (core.WriteStatus, error)

InsertHeaderChain inserts the given headers and does the reorganisations.

The validity of the headers is NOT CHECKED by this method, i.e. they need to be validated by ValidateHeaderChain before calling InsertHeaderChain.

This insert is all-or-nothing. If this returns an error, no headers were written, otherwise they were all processed successfully.

The returned 'write status' says if the inserted headers are part of the canonical chain or a side chain.

func (*HeaderChain) Reorg

func (hc *HeaderChain) Reorg(headers []*mivetypes.Header) error

Reorg reorgs the local canonical chain into the specified chain. The reorg can be classified into two cases: (a) extend the local chain (b) switch the head to the given header.

func (*HeaderChain) SetCurrentHeader

func (hc *HeaderChain) SetCurrentHeader(head *mivetypes.Header)

SetCurrentHeader sets the in-memory head header marker of the canonical chan as the given header.

func (*HeaderChain) SetGenesis

func (hc *HeaderChain) SetGenesis(head *mivetypes.Header)

SetGenesis sets a new genesis block header for the chain

func (*HeaderChain) SetHead

func (hc *HeaderChain) SetHead(head uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback)

SetHead rewinds the local chain to a new head. Everything above the new head will be deleted and the new one set.

func (*HeaderChain) SetHeadWithTimestamp

func (hc *HeaderChain) SetHeadWithTimestamp(time uint64, updateFn UpdateHeadBlocksCallback, delFn DeleteBlockContentCallback)

SetHeadWithTimestamp rewinds the local chain to a new head timestamp. Everything above the new head will be deleted and the new one set.

func (*HeaderChain) ValidateHeaderChain

func (hc *HeaderChain) ValidateHeaderChain(chain []*mivetypes.Header) (int, error)

func (*HeaderChain) WriteHeaders

func (hc *HeaderChain) WriteHeaders(headers []*mivetypes.Header) (int, error)

WriteHeaders writes a chain of headers into the local chain, given that the parents are already known. The chain head header won't be updated in this function, the additional SetCanonical is expected in order to finish the entire procedure.

type StateProcessor

type StateProcessor struct {
	// contains filtered or unexported fields
}

StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.

StateProcessor implements Processor.

func NewStateProcessor

func NewStateProcessor(config *miveparams.ChainConfig, bc *BlockChain, engine miveconsensus.Engine) *StateProcessor

NewStateProcessor initialises a new StateProcessor.

func (*StateProcessor) Process

func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, []*types.Log, uint64, error)

type UpdateHeadBlocksCallback

type UpdateHeadBlocksCallback func(ethdb.KeyValueWriter, *mivetypes.Header) (*mivetypes.Header, bool)

UpdateHeadBlocksCallback is a callback function that is called by SetHead before head header is updated. The method will return the actual block it updated the head to (missing state) and a flag if setHead should continue rewinding till that forcefully (exceeded ancient limits)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL