blockchain

package
v0.0.0-...-471f645 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: GPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgTooLarge = iota
	ErrDecode
	ErrInvalidMsgCode
	ErrProtocolVersionMismatch
	ErrNetworkIDMismatch
	ErrGenesisBlockMismatch
	ErrNoStatusMsg
	ErrExtraStatusMsg
	ErrSuspendedPeer
)
View Source
const (

	//BlockChainVersion ensures that an incompatible database forces a resync from scratch.
	BlockChainVersion = 0
)
View Source
const ProtocolMaxMsgSize = 10 * 1024 * 1024

ProtocolMaxMsgSize Maximum cap on the size of a protocol message

Variables

View Source
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.

func SetupGenesisBlock

func SetupGenesisBlock(db fdb.Database, genesis *Genesis) (*params.ChainConfig, *dpos.Config, common.Hash, error)

SetupGenesisBlock The returned chain configuration is never nil.

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) ExportN

func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error

ExportN writes a subset of the active chain to the given writer.

func (*BlockChain) FillForkID

func (bc *BlockChain) FillForkID(header *types.Header, statedb *state.StateDB) error

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

func (bc *BlockChain) ForkUpdate(block *types.Block, statedb *state.StateDB) error

ForkUpdate update fork status.

func (*BlockChain) Genesis

func (bc *BlockChain) Genesis() *types.Block

Genesis retrieves the chain's genesis block.

func (*BlockChain) GetBlock

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

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

func (bc *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.Block)

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) GetForkID

func (bc *BlockChain) GetForkID(statedb *state.StateDB) (uint64, uint64, error)

GetForkID returns the last current fork ID.

func (*BlockChain) GetHeader

func (bc *BlockChain) GetHeader(hash common.Hash, number uint64) *types.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) *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

func (bc *BlockChain) GetTd(hash common.Hash, number uint64) *big.Int

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

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

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

func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (err error)

WriteBlockWithoutState writes only the block and its metadata to the database, but does not write any state.

func (*BlockChain) WriteTd

func (bc *BlockChain) WriteTd(hash common.Hash, number uint64, td *big.Int) error

WriteTd stores a block's total difficulty into the database, also caching it along the way.

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 .

func (*Downloader) Stop

func (dl *Downloader) Stop()

Stop stop the downloader

type Error

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

Error represent error by downloader

type ForkConfig

type ForkConfig struct {
	ForkBlockNum   uint64
	Forkpercentage uint64
}

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.

func (*Genesis) Commit

func (g *Genesis) Commit(db fdb.Database) (*types.Block, error)

Commit writes the block and state of a genesis specification to the database. The block is committed as the canonical head block.

func (*Genesis) ToBlock

func (g *Genesis) ToBlock(db fdb.Database) (*types.Block, []*types.Receipt, error)

ToBlock creates the genesis block and writes state of a genesis specification to the given database (or discards it if nil).

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

type GenesisMismatchError struct {
	Stored, New common.Hash
}

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

type NewMinedBlockEvent struct{ Block *types.Block }

NewMinedBlockEvent is posted when a block has been imported.

type TxSenderCacher

type TxSenderCacher interface {
	RecoverFromBlocks(signer types.Signer, blocks []*types.Block)
}

TxSenderCacher ecovers the senders from a batch of blocks and caches them back into the same data structures.

type WriteStateToDB

type WriteStateToDB struct {
	Root        common.Hash
	Number      uint64
	WriteDbFlag bool
}

Jump to

Keyboard shortcuts

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