Documentation ¶
Index ¶
- Constants
- Variables
- func NewForkController(cfg *ForkConfig, chaincfg *params.ChainConfig) *forkController
- func SetupGenesisBlock(db fdb.Database, genesis *Genesis) (*params.ChainConfig, *dpos.Config, common.Hash, error)
- type BlockChain
- func (bc *BlockChain) BadBlocks() []*types.Block
- func (bc *BlockChain) CheckForkID(header *types.Header) error
- func (bc *BlockChain) Config() *params.ChainConfig
- func (bc *BlockChain) CurrentBlock() *types.Block
- func (bc *BlockChain) CurrentHeader() *types.Header
- func (bc *BlockChain) Export(w io.Writer) error
- func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error
- func (bc *BlockChain) FillForkID(header *types.Header, statedb *state.StateDB) error
- func (bc *BlockChain) ForkStatus(statedb *state.StateDB) (*ForkConfig, ForkInfo, error)
- func (bc *BlockChain) ForkUpdate(block *types.Block, statedb *state.StateDB) error
- func (bc *BlockChain) Genesis() *types.Block
- func (bc *BlockChain) GetBlock(hash common.Hash, number uint64) *types.Block
- func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block
- func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block
- func (bc *BlockChain) GetBlockNumber(hash common.Hash) *uint64
- func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.Block)
- func (bc *BlockChain) GetBody(hash common.Hash) *types.Body
- func (bc *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue
- func (bc *BlockChain) GetForkID(statedb *state.StateDB) (uint64, uint64, error)
- func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.Header
- func (bc *BlockChain) GetHeaderByHash(hash common.Hash) *types.Header
- func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header
- func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) []*types.Receipt
- func (bc *BlockChain) GetTd(hash common.Hash, number uint64) *big.Int
- func (bc *BlockChain) GetTdByHash(hash common.Hash) *big.Int
- func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool
- func (bc *BlockChain) HasBlockAndState(hash common.Hash, number uint64) bool
- func (bc *BlockChain) HasState(hash common.Hash) bool
- func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error)
- func (bc *BlockChain) IrreversibleNumber() uint64
- func (bc *BlockChain) Processor() processor.Processor
- func (bc *BlockChain) Reset() error
- func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) error
- func (bc *BlockChain) SetLastSnapshot(block *types.Block) error
- func (bc *BlockChain) SetProcessor(processor processor.Processor)
- func (bc *BlockChain) SetValidator(validator processor.Validator)
- func (bc *BlockChain) State() (*state.StateDB, error)
- func (bc *BlockChain) StateAt(hash common.Hash) (*state.StateDB, error)
- func (bc *BlockChain) StatePruning(enable bool) (bool, uint64)
- func (bc *BlockChain) Stop()
- func (bc *BlockChain) Validator() processor.Validator
- func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) (isCanon bool, err error)
- func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (err error)
- func (bc *BlockChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error
- type Downloader
- type Error
- type ForkConfig
- type ForkInfo
- type Genesis
- type GenesisAccount
- type GenesisAsset
- type GenesisCandidate
- type GenesisMismatchError
- type NewBlockHashesData
- type NewMinedBlockEvent
- type TxSenderCacher
- type WriteStateToDB
Constants ¶
const ( ErrMsgTooLarge = iota ErrDecode ErrInvalidMsgCode ErrProtocolVersionMismatch ErrNetworkIDMismatch ErrGenesisBlockMismatch ErrNoStatusMsg ErrExtraStatusMsg ErrSuspendedPeer )
const (
//BlockChainVersion ensures that an incompatible database forces a resync from scratch.
BlockChainVersion = 0
)
const ProtocolMaxMsgSize = 10 * 1024 * 1024
ProtocolMaxMsgSize Maximum cap on the size of a protocol message
Variables ¶
var ( // ErrNoGenesis genesis block not found in chain db. ErrNoGenesis = errors.New("Genesis not found in chain") // ErrBlacklistedHash is returned if a block to import is on the blacklist. ErrBlacklistedHash = errors.New("blacklisted hash") )
Functions ¶
func NewForkController ¶
func NewForkController(cfg *ForkConfig, chaincfg *params.ChainConfig) *forkController
NewForkController return a new fork controller.
Types ¶
type BlockChain ¶
type BlockChain struct {
// contains filtered or unexported fields
}
BlockChain represents the canonical chain given a database with a genesis block. The Blockchain manages chain imports, reverts, chain reorganisations.
func NewBlockChain ¶
func NewBlockChain(db fdb.Database, statePruning bool, vmConfig vm.Config, chainConfig *params.ChainConfig, badhashes []string, startNumber uint64, senderCacher TxSenderCacher) (*BlockChain, error)
NewBlockChain returns a fully initialised block chain using information available in the database.
func (*BlockChain) BadBlocks ¶
func (bc *BlockChain) BadBlocks() []*types.Block
BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network
func (*BlockChain) CheckForkID ¶
func (bc *BlockChain) CheckForkID(header *types.Header) error
CheckForkID Checks the validity of forkID
func (*BlockChain) Config ¶
func (bc *BlockChain) Config() *params.ChainConfig
Config retrieves the blockchain's chain configuration.
func (*BlockChain) CurrentBlock ¶
func (bc *BlockChain) CurrentBlock() *types.Block
CurrentBlock retrieves the current head block of the canonical chain.
func (*BlockChain) CurrentHeader ¶
func (bc *BlockChain) CurrentHeader() *types.Header
CurrentHeader retrieves the current head header of the canonical chain.
func (*BlockChain) Export ¶
func (bc *BlockChain) Export(w io.Writer) error
Export writes the active chain to the given writer.
func (*BlockChain) FillForkID ¶
FillForkID fills the current and next forkID
func (*BlockChain) ForkStatus ¶
func (bc *BlockChain) ForkStatus(statedb *state.StateDB) (*ForkConfig, ForkInfo, error)
ForkStatus returns current fork status.
func (*BlockChain) ForkUpdate ¶
ForkUpdate update fork status.
func (*BlockChain) Genesis ¶
func (bc *BlockChain) Genesis() *types.Block
Genesis retrieves the chain's genesis block.
func (*BlockChain) GetBlock ¶
GetBlock retrieves a block from the database by hash and number, caching it if found.
func (*BlockChain) GetBlockByHash ¶
func (bc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block
GetBlockByHash retrieves a block from the database by hash, caching it if found.
func (*BlockChain) GetBlockByNumber ¶
func (bc *BlockChain) GetBlockByNumber(number uint64) *types.Block
GetBlockByNumber retrieves a block from the database by number, caching it if found.
func (*BlockChain) GetBlockNumber ¶
func (bc *BlockChain) GetBlockNumber(hash common.Hash) *uint64
GetBlockNumber retrieves the block number belonging to the given hash from the cache or database
func (*BlockChain) GetBlocksFromHash ¶
GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
func (*BlockChain) GetBody ¶
func (bc *BlockChain) GetBody(hash common.Hash) *types.Body
GetBody retrieves a block body (transactions ) from the database by hash, caching it if found.
func (*BlockChain) GetBodyRLP ¶
func (bc *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue
GetBodyRLP retrieves a block body in RLP encoding from the database by hash, caching it if found.
func (*BlockChain) GetHeader ¶
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) *types.Header
GetHeaderByHash retrieves a block header from the database by hash, caching it if found.
func (*BlockChain) GetHeaderByNumber ¶
func (bc *BlockChain) GetHeaderByNumber(number uint64) *types.Header
GetHeaderByNumber retrieves a block header from the database by number.
func (*BlockChain) GetReceiptsByHash ¶
func (bc *BlockChain) GetReceiptsByHash(hash common.Hash) []*types.Receipt
GetReceiptsByHash retrieves the receipts for all transactions in a given block.
func (*BlockChain) GetTd ¶
GetTd retrieves a block's total difficulty in the canonical chain from the database by hash and number, caching it if found.
func (*BlockChain) GetTdByHash ¶
func (bc *BlockChain) GetTdByHash(hash common.Hash) *big.Int
GetTdByHash retrieves a block's total difficulty in the canonical chain from the database by hash, caching it if found.
func (*BlockChain) HasBlock ¶
func (bc *BlockChain) HasBlock(hash common.Hash, number uint64) bool
HasBlock checks if a block is fully present in the database or not.
func (*BlockChain) HasBlockAndState ¶
func (bc *BlockChain) HasBlockAndState(hash common.Hash, number uint64) bool
HasBlockAndState checks if a block and state is fully present in the database or not.
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) InsertChain ¶
func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error)
InsertChain attempts to insert the given batch of blocks in to the canonical chain or, otherwise, create a fork.
func (*BlockChain) IrreversibleNumber ¶
func (bc *BlockChain) IrreversibleNumber() uint64
IrreversibleNumber retrieves the irreversible block number of the canonical chain.
func (*BlockChain) Processor ¶
func (bc *BlockChain) Processor() processor.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 *types.Block) error
ResetWithGenesisBlock purges the entire blockchain, restoring it to the specified genesis state.
func (*BlockChain) SetLastSnapshot ¶
func (bc *BlockChain) SetLastSnapshot(block *types.Block) error
SetLastSnapshot rewinds the local chain to a last snapshot.
func (*BlockChain) SetProcessor ¶
func (bc *BlockChain) SetProcessor(processor processor.Processor)
SetProcessor sets the processor required for making state modifications.
func (*BlockChain) SetValidator ¶
func (bc *BlockChain) SetValidator(validator processor.Validator)
SetValidator sets the processor validator.
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 ¶
StateAt returns a new mutable state based on a particular point in time.
func (*BlockChain) StatePruning ¶
func (bc *BlockChain) StatePruning(enable bool) (bool, uint64)
StatePruning enable/disable state pruning
func (*BlockChain) Stop ¶
func (bc *BlockChain) Stop()
Stop stops the blockchain service. If any imports are currently in progress it will abort them using the procInterrupt.
func (*BlockChain) Validator ¶
func (bc *BlockChain) Validator() processor.Validator
Validator returns the current validator.
func (*BlockChain) WriteBlockWithState ¶
func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types.Receipt, state *state.StateDB) (isCanon bool, err error)
WriteBlockWithState writes the block and all associated state to the database.
func (*BlockChain) WriteBlockWithoutState ¶
WriteBlockWithoutState writes only the block and its metadata to the database, but does not write any state.
type Downloader ¶
type Downloader struct {
// contains filtered or unexported fields
}
Downloader for blockchain sync block.
func NewDownloader ¶
func NewDownloader(chain *BlockChain) *Downloader
NewDownloader create a new downloader
func (*Downloader) AddStation ¶
func (dl *Downloader) AddStation(station router.Station, td *big.Int, number uint64, hash common.Hash)
AddStation .
func (*Downloader) DelStation ¶
func (dl *Downloader) DelStation(station router.Station)
DelStation .
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represent error by downloader
type ForkConfig ¶
ForkConfig fork config
type ForkInfo ¶
type ForkInfo struct { CurForkID uint64 NextForkID uint64 CurForkIDBlockNum uint64 NextForkIDBlockNum uint64 }
ForkInfo store in state db.
type Genesis ¶
type Genesis struct { Config *params.ChainConfig `json:"config,omitempty"` Timestamp uint64 `json:"timestamp,omitempty"` GasLimit uint64 `json:"gasLimit,omitempty" ` Difficulty *big.Int `json:"difficulty,omitempty" ` AllocAccounts []*GenesisAccount `json:"allocAccounts,omitempty"` AllocCandidates []*GenesisCandidate `json:"allocCandidates,omitempty"` AllocAssets []*GenesisAsset `json:"allocAssets,omitempty"` Remark string `json:"remark,omitempty"` ForkID uint64 `json:"forkID,omitempty"` }
Genesis specifies the header fields, state of a genesis block.
func DefaultGenesis ¶
func DefaultGenesis() *Genesis
DefaultGenesis returns the set net genesis block.
type GenesisAccount ¶
type GenesisAccount struct { Name string `json:"name,omitempty"` Founder string `json:"founder,omitempty"` PubKey common.PubKey `json:"pubKey,omitempty"` }
GenesisAccount is an account in the state of the genesis block.
func DefaultGenesisAccounts ¶
func DefaultGenesisAccounts() []*GenesisAccount
DefaultGenesisAccounts returns the set net genesis accounts.
type GenesisAsset ¶
type GenesisAsset struct { Name string `json:"name,omitempty"` Symbol string `json:"symbol,omitempty"` Amount *big.Int `json:"amount,omitempty"` Decimals uint64 `json:"decimals,omitempty"` Founder string `json:"founder,omitempty"` Owner string `json:"owner,omitempty"` UpperLimit *big.Int `json:"upperLimit,omitempty"` }
GenesisAsset is an asset in the state of the genesis block.
func DefaultGenesisAssets ¶
func DefaultGenesisAssets() []*GenesisAsset
DefaultGenesisAssets returns the set net genesis assets.
type GenesisCandidate ¶
type GenesisCandidate struct { Name string `json:"name,omitempty"` Info string `json:"info,omitempty"` Stake *big.Int `json:"stake,omitempty"` }
GenesisCandidate is an candidate in the state of the genesis block.
func DefaultGenesisCandidates ¶
func DefaultGenesisCandidates() []*GenesisCandidate
DefaultGenesisCandidates returns the set net genesis candidates.
type GenesisMismatchError ¶
GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.
func (*GenesisMismatchError) Error ¶
func (e *GenesisMismatchError) Error() string
type NewBlockHashesData ¶
type NewBlockHashesData struct { Hash common.Hash // Hash of one particular block being announced Number uint64 // Number of one particular block being announced TD *big.Int Completed bool // block is completed or just hash }
NewBlockHashesData is the network packet for the block announcements.
type NewMinedBlockEvent ¶
NewMinedBlockEvent is posted when a block has been imported.
type TxSenderCacher ¶
TxSenderCacher ecovers the senders from a batch of blocks and caches them back into the same data structures.