Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // 当验证块需要未知的祖先时,将返回ErrUnknownAncestor。 ErrUnknownAncestor = errors.New("unknown ancestor") // 根据当前节点,当块的时间戳在未来时,将返回ErrFutureBlock。 ErrFutureBlock = errors.New("block in the future") // 如果块的编号不等于其父块的编号加1,则返回ErrInvalidNumber。 ErrInvalidNumber = errors.New("invalid block number") //当验证块需要已知但状态不可用的祖先时,返回ErrPrunedAncestor。 ErrPrunedAncestor = errors.New("pruned ancestor") // 如果块wrt无效,则返回ErrInvalidTerminalBlock。终端总难度。 ErrInvalidTerminalBlock = errors.New("invalid terminal block") )
Functions ¶
This section is empty.
Types ¶
type ChainHeaderReader ¶
type ChainHeaderReader interface {
// Config检索区块链的链配置。
Config() *entity.ChainConfig
// 从本地链检索当前头
CurrentHeader() *block2.Header
// 通过hash和数字从数据库检索块头
GetHeader(hash entity.Hash, number uint64) *block2.Header
// 按编号从数据库检索块头
GetHeaderByNumber(number uint64) *block2.Header
// 通过其hash从数据库中检索块头
GetHeaderByHash(hash entity.Hash) *block2.Header
// 通过hash和数字从数据库中检索总难度
GetTd(hash entity.Hash, number uint64) *big.Int
}
该接口定义了验证期间访问本地本地区块两所需的一小部分方法
type Engine ¶
type Engine interface {
Author(header *block2.Header) (entity.Address, error)
// VerifyHeader检查标头是否符合给定引擎的共识规则。
//可以在此处选择验证密封,也可以通过VerifySeal方法明确验证密封。
VerifyHeader(chain ChainHeaderReader, header *block2.Header, seal bool) error
//表头验证器,该方法返回退出通道以终止操作,验证顺序为切片排序
VerifyHeaders(chain ChainHeaderReader, headers []*block2.Header, seals []bool) (chan<- struct{}, <-chan error)
// Prepare根据特定引擎的规则初始化块标头的一致性字段。更改以内联方式执行。
Prepare(chain ChainHeaderReader, header *block2.Header) error
// FinalizeAndAssemble运行任何交易后状态修改(例如区块奖励)并组装最终区块。
//注意:可能会更新区块标题和状态数据库,以反映最终确定时发生的任何共识规则(例如区块奖励)。
FinalizeAndAssemble(chain ChainHeaderReader, header *block2.Header, state *operationdb.OperationDB, txs []*block2.Transaction,
uncles []*block2.Header, receipts []*block2.Receipt) (*block2.Block, error)
//Seal为给定的输入块生成新的密封请求,并将结果推送到给定的通道中。
//注意,该方法立即返回,并将异步发送结果。根据一致性算法,还可能返回多个结果。
Seal(chain ChainHeaderReader, block *block2.Block, results chan<- *block2.Block, stop <-chan struct{}) error
// SealHash返回块在被密封之前的哈希值。
SealHash(header *block2.Header) entity.Hash
// CalcDifficulty是难度调整算法。它返回新块应该具有的难度。
CalcDifficulty(chain ChainHeaderReader, time uint64, parent *block2.Header) *big.Int
// API返回此一致性引擎提供的RPC API。
APIs(chain ChainHeaderReader) []rpc.API
// Close终止共识引擎维护的任何后台线程。
Close() error
}
共识引擎接口
type Merger ¶
type Merger struct {
// contains filtered or unexported fields
}
Merger is an internal help structure used to track the eth1/2 transition status. It's a common structure can be used in both full node and light client.
func NewMerger ¶
func NewMerger(db typedb.KeyValueStore) *Merger
NewMerger creates a new Merger which stores its transition status in the provided db.
func (*Merger) FinalizePoS ¶
func (m *Merger) FinalizePoS()
FinalizePoS is called whenever the first FinalisedBlock message received from the consensus-layer.
func (*Merger) PoSFinalized ¶
PoSFinalized reports whether the chain has entered the PoS stage.
func (*Merger) ReachTTD ¶
func (m *Merger) ReachTTD()
ReachTTD is called whenever the first NewHead message received from the consensus-layer.
func (*Merger) TDDReached ¶
TDDReached reports whether the chain has left the PoW stage.
Click to show internal directories.
Click to hide internal directories.