blockchain

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2019 License: GPL-3.0 Imports: 41 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 // Maximum cap on the size of a protocol message

Variables

View Source
var (
	ErrSideBlock = errors.New("write side block and state")

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

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

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

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

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

func (bc *BlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash

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

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

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

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

func (*BlockGenerator) TxNonce

func (bg *BlockGenerator) TxNonce(name common.Name) uint64

TxNonce retrun nonce

type BlockchainStation

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

func (*BlockchainStation) Stop added in v0.0.15

func (bs *BlockchainStation) Stop()

type ChainEvent

type ChainEvent struct {
	Block *types.Block
	Hash  common.Hash
	Logs  []*types.Log
}

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 added in v0.0.15

func (dl *Downloader) Stop()

Stop stop the downloader

type Error added in v0.0.20

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

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

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 NewTxsEvent

type NewTxsEvent struct{ Txs []*types.Transaction }

NewTxsEvent is posted when a batch of transactions enter the transaction pool.

type PendingLogsEvent

type PendingLogsEvent struct {
	Logs []*types.Log
}

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

type RemovedLogsEvent struct{ Logs []*types.Log }

RemovedLogsEvent is posted when a reorg happens

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 added in v0.0.8

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