Documentation ¶
Index ¶
- Constants
- Variables
- 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) ForkUpdate(block *types.Block, statedb *state.StateDB) error
- func (bc *BlockChain) GasLimit() uint64
- func (bc *BlockChain) Genesis() *types.Block
- func (bc *BlockChain) GetAncestor(hash common.Hash, number, ancestor uint64, maxNonCanonical *uint64) (common.Hash, uint64)
- 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) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash
- 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) HasHeader(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 BlockGenerator
- func (bg *BlockGenerator) AddTx(tx *types.Transaction)
- func (bg *BlockGenerator) AddTxWithChain(tx *types.Transaction)
- func (bg *BlockGenerator) CurrentHeader() *types.Header
- func (bg *BlockGenerator) OffsetTime(seconds int64)
- func (bg *BlockGenerator) SetCoinbase(name common.Name)
- func (bg *BlockGenerator) TxNonce(name common.Name) uint64
- type BlockchainStation
- type ChainEvent
- type Downloader
- type Error
- type ForkConfig
- type ForkController
- type ForkInfo
- type Genesis
- type GenesisAccount
- type GenesisAsset
- type GenesisCandidate
- type GenesisMismatchError
- type NewBlockHashesData
- type NewMinedBlockEvent
- type NewTxsEvent
- type PendingLogsEvent
- type PendingStateEvent
- type RemovedLogsEvent
- 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 // Maximum cap on the size of a protocol message
Variables ¶
Functions ¶
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 ¶ added in v0.0.7
func (bc *BlockChain) Export(w io.Writer) error
Export writes the active chain to the given writer.
func (*BlockChain) ExportN ¶ added in v0.0.7
ExportN writes a subset of the active chain to the given writer.
func (*BlockChain) FillForkID ¶
FillForkID fills the current and next forkID
func (*BlockChain) ForkUpdate ¶
ForkUpdate .
func (*BlockChain) GasLimit ¶
func (bc *BlockChain) GasLimit() uint64
GasLimit returns the gas limit of the current HEAD block.
func (*BlockChain) Genesis ¶
func (bc *BlockChain) Genesis() *types.Block
Genesis retrieves the chain's genesis block.
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.
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) GetBlockHashesFromHash ¶
GetBlockHashesFromHash retrieves a number of block hashes starting at a given hash, fetching towards the genesis block.
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) HasHeader ¶
func (bc *BlockChain) HasHeader(hash common.Hash, number uint64) bool
HasHeader checks if a block header is 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 ¶ added in v0.0.7
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 ¶ added in v0.0.20
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 ¶ added in v0.0.8
func (bc *BlockChain) StatePruning(enable bool) (bool, uint64)
StatePruning enale/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 BlockGenerator ¶
type BlockGenerator struct { *BlockChain // contains filtered or unexported fields }
BlockGenerator creates blocks for testing.
func (*BlockGenerator) AddTx ¶
func (bg *BlockGenerator) AddTx(tx *types.Transaction)
AddTx adds a transaction to the generated block.
func (*BlockGenerator) AddTxWithChain ¶
func (bg *BlockGenerator) AddTxWithChain(tx *types.Transaction)
AddTxWithChain adds a transaction to the generated block.
func (*BlockGenerator) CurrentHeader ¶ added in v0.0.7
func (bg *BlockGenerator) CurrentHeader() *types.Header
CurrentHeader return current header
func (*BlockGenerator) OffsetTime ¶
func (bg *BlockGenerator) OffsetTime(seconds int64)
OffsetTime modifies the time instance of a block
func (*BlockGenerator) SetCoinbase ¶
func (bg *BlockGenerator) SetCoinbase(name common.Name)
SetCoinbase sets the coinbase of the generated block.
type BlockchainStation ¶
type BlockchainStation struct {
// contains filtered or unexported fields
}
func (*BlockchainStation) Stop ¶ added in v0.0.15
func (bs *BlockchainStation) Stop()
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 ¶ added in v0.0.20
type Error struct {
// contains filtered or unexported fields
}
Error represent error by downloader
type ForkConfig ¶
ForkConfig fork config
type ForkController ¶
type ForkController struct {
// contains filtered or unexported fields
}
ForkController control the hard forking.
func NewForkController ¶
func NewForkController(cfg *ForkConfig, chaincfg *params.ChainConfig) *ForkController
NewForkController return a new fork controller.
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 ft 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 ft net genesis accounts.
type GenesisAsset ¶ added in v0.0.7
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 ft net genesis assets.
type GenesisCandidate ¶ added in v0.0.8
type GenesisCandidate struct { Name string `json:"name,omitempty"` URL string `json:"url,omitempty"` Stake *big.Int `json:"stake,omitempty"` }
GenesisCandidate is an cadicate in the state of the genesis block.
func DefaultGenesisCandidates ¶ added in v0.0.8
func DefaultGenesisCandidates() []*GenesisCandidate
DefaultGenesisCandidates returns the ft 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 NewTxsEvent ¶
type NewTxsEvent struct{ Txs []*types.Transaction }
NewTxsEvent is posted when a batch of transactions enter the transaction pool.
type PendingLogsEvent ¶
PendingLogsEvent is posted pre mining and notifies of pending logs.
type PendingStateEvent ¶
type PendingStateEvent struct{}
PendingStateEvent is posted pre mining and notifies of pending state changes.
type RemovedLogsEvent ¶
RemovedLogsEvent is posted when a reorg happens
type TxSenderCacher ¶
TxSenderCacher ecovers the senders from a batch of blocks and caches them back into the same data structures.