Documentation ¶
Index ¶
- Variables
- type Chain
- func (c *Chain) BestBlockHash() *bc.Hash
- func (c *Chain) BlockExist(hash *bc.Hash) bool
- func (c *Chain) BlockSoonWaiter(ctx context.Context, height uint64) <-chan error
- func (c *Chain) BlockWaiter(height uint64) <-chan struct{}
- func (c *Chain) ConnectBlock(block *legacy.Block) error
- func (c *Chain) GetBlockByHash(hash *bc.Hash) (*legacy.Block, error)
- func (c *Chain) GetBlockByHeight(height uint64) (*legacy.Block, error)
- func (c *Chain) Height() uint64
- func (c *Chain) ProcessBlock(block *legacy.Block) (bool, error)
- func (c *Chain) Recover(ctx context.Context) (*legacy.Block, *state.Snapshot, error)
- func (c *Chain) SaveBlock(block *legacy.Block) error
- func (c *Chain) State() (*legacy.Block, *state.Snapshot)
- func (c *Chain) TimestampMS() uint64
- func (c *Chain) ValidateBlock(block, prev *legacy.Block) error
- func (c *Chain) ValidateTx(tx *legacy.Tx) error
- type OrphanManage
- type Store
- type TxDesc
- type TxPool
- func (mp *TxPool) AddErrCache(txHash *bc.Hash, err error)
- func (mp *TxPool) AddTransaction(tx *legacy.Tx, height, fee uint64) *TxDesc
- func (mp *TxPool) Count() int
- func (mp *TxPool) GetErrCache(txHash *bc.Hash) error
- func (mp *TxPool) GetNewTxCh() chan *legacy.Tx
- func (mp *TxPool) GetTransaction(txHash *bc.Hash) (*TxDesc, error)
- func (mp *TxPool) GetTransactions() []*TxDesc
- func (mp *TxPool) HaveTransaction(txHash *bc.Hash) bool
- func (mp *TxPool) IsTransactionInErrCache(txHash *bc.Hash) bool
- func (mp *TxPool) IsTransactionInPool(txHash *bc.Hash) bool
- func (mp *TxPool) RemoveTransaction(txHash *bc.Hash)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBadBlock is returned when a block is invalid. ErrBadBlock = errors.New("invalid block") // ErrStaleState is returned when the Chain does not have a current // blockchain state. ErrStaleState = errors.New("stale blockchain state") // ErrBadStateRoot is returned when the computed assets merkle root // disagrees with the one declared in a block header. ErrBadStateRoot = errors.New("invalid state merkle root") )
var ErrBadTx = errors.New("invalid transaction")
ErrBadTx is returned for transactions failing validation
var ( // ErrTheDistantFuture is returned when waiting for a blockheight // too far in excess of the tip of the blockchain. ErrTheDistantFuture = errors.New("block height too far in future") )
var ( // ErrTransactionNotExist is the pre-defined error message ErrTransactionNotExist = errors.New("transaction are not existed in the mempool") )
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct { InitialBlockHash bc.Hash MaxIssuanceWindow time.Duration // only used by generators // contains filtered or unexported fields }
Chain provides a complete, minimal blockchain database. It delegates the underlying storage to other objects, and uses validation logic from package validation to decide what objects can be safely stored.
func (*Chain) BestBlockHash ¶ added in v0.1.4
func (*Chain) BlockExist ¶ added in v0.1.4
BlockExist check is a block in chain or orphan
func (*Chain) BlockSoonWaiter ¶
BlockSoonWaiter returns a channel that waits for the block at the given height, but it is an error to wait for a block far in the future. WaitForBlockSoon will timeout if the context times out. To wait unconditionally, the caller should use WaitForBlock.
func (*Chain) BlockWaiter ¶
BlockWaiter returns a channel that waits for the block at the given height.
func (*Chain) ConnectBlock ¶ added in v0.1.4
ConnectBlock append block to end of chain
func (*Chain) GetBlockByHash ¶ added in v0.1.4
GetBlockByHash return a block by given hash
func (*Chain) GetBlockByHeight ¶ added in v0.1.4
GetBlockByHeight return a block by given height
func (*Chain) ProcessBlock ¶ added in v0.1.4
ProcessBlock is the entry for handle block insert
func (*Chain) Recover ¶
Recover performs crash recovery, restoring the blockchain to a complete state. It returns the latest confirmed block and the corresponding state snapshot.
If the blockchain is empty (missing initial block), this function returns a nil block and an empty snapshot.
func (*Chain) State ¶
State returns the most recent state available. It will not be current unless the current process is the leader. Callers should examine the returned block header's height if they need to verify the current state.
func (*Chain) TimestampMS ¶
TimestampMS returns the latest known block timestamp.
func (*Chain) ValidateBlock ¶
ValidateBlock validates an incoming block in advance of applying it to a snapshot (with ApplyValidBlock) and committing it to the blockchain (with CommitAppliedBlock).
type OrphanManage ¶ added in v0.1.4
type OrphanManage struct {
// contains filtered or unexported fields
}
OrphanManage is use to handle all the orphan block
func NewOrphanManage ¶ added in v0.1.4
func NewOrphanManage() *OrphanManage
NewOrphanManage return a new orphan block
func (*OrphanManage) Add ¶ added in v0.1.4
func (o *OrphanManage) Add(block *legacy.Block)
Add will add the block to OrphanManage
func (*OrphanManage) BlockExist ¶ added in v0.1.4
func (o *OrphanManage) BlockExist(hash *bc.Hash) bool
BlockExist check is the block in OrphanManage
func (*OrphanManage) Delete ¶ added in v0.1.4
func (o *OrphanManage) Delete(hash *bc.Hash)
Delete will delelte the block from OrphanManage
type Store ¶
type Store interface { BlockExist(*bc.Hash) bool GetBlock(*bc.Hash) (*legacy.Block, error) GetMainchain(*bc.Hash) (map[uint64]*bc.Hash, error) GetSnapshot(*bc.Hash) (*state.Snapshot, error) GetStoreStatus() txdb.BlockStoreStateJSON SaveBlock(*legacy.Block) error SaveMainchain(map[uint64]*bc.Hash, *bc.Hash) error SaveSnapshot(*state.Snapshot, *bc.Hash) error SaveStoreStatus(uint64, *bc.Hash) }
Store provides storage for blockchain data: blocks and state tree snapshots.
Note, this is different from a state snapshot. A state snapshot provides access to the state at a given point in time -- outputs and issuance memory. The Chain type uses Store to load state from storage and persist validated data.
type TxDesc ¶
type TxDesc struct { Tx *legacy.Tx Added time.Time Height uint64 Weight uint64 Fee uint64 FeePerKB uint64 }
TxDesc store tx and related info for mining strategy
type TxPool ¶
type TxPool struct {
// contains filtered or unexported fields
}
TxPool is use for store the unconfirmed transaction
func (*TxPool) AddErrCache ¶
AddErrCache add a failed transaction record to lru cache
func (*TxPool) AddTransaction ¶
AddTransaction add a verified transaction to pool
func (*TxPool) GetErrCache ¶
GetErrCache return the error of the transaction
func (*TxPool) GetNewTxCh ¶
GetNewTxCh return a unconfirmed transaction feed channel
func (*TxPool) GetTransaction ¶
GetTransaction return the TxDesc by hash
func (*TxPool) GetTransactions ¶
GetTransactions return all the transactions in the pool
func (*TxPool) HaveTransaction ¶
HaveTransaction IsTransactionInErrCache check is transaction in errCache or pool
func (*TxPool) IsTransactionInErrCache ¶
IsTransactionInErrCache check wheather a transaction in errCache or not
func (*TxPool) IsTransactionInPool ¶
IsTransactionInPool check wheather a transaction in pool or not
func (*TxPool) RemoveTransaction ¶
RemoveTransaction remove a transaction from the pool
Directories ¶
Path | Synopsis |
---|---|
Package bc is a generated protocol buffer package.
|
Package bc is a generated protocol buffer package. |
bctest
Package bctest provides utilities for constructing blockchain data structures.
|
Package bctest provides utilities for constructing blockchain data structures. |
Package patricia computes the Merkle Patricia Tree Hash of a set of bit strings, as described in the Chain Protocol spec.
|
Package patricia computes the Merkle Patricia Tree Hash of a set of bit strings, as described in the Chain Protocol spec. |