Documentation ¶
Overview ¶
Package forkid implements EIP-2124 (https://eips.ethereum.org/EIPS/eip-2124). NewID 获取当前链的ID对象 NewFilter 获取一个过滤器
给返回的过滤器输入远程节点的ID对象,如果有err!=nil说明两个节点不匹配
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRemoteStale is returned by the validator if a remote fork checksum is a // subset of our already applied forks, but the announced next fork block is // not on our already passed chain. // 远程节点是之前的版本返回这个错误 ErrRemoteStale = errors.New("remote needs update") // ErrLocalIncompatibleOrStale is returned by the validator if a remote fork // checksum does not match any local checksum variation, signalling that the // two chains have diverged in the past at some point (possibly at genesis). // 和远程节点的校验和不匹配,而且校验和也不在之前版本中 ErrLocalIncompatibleOrStale = errors.New("local incompatible or needs update") )
Functions ¶
This section is empty.
Types ¶
type Blockchain ¶
type Blockchain interface { // Config retrieves the chain's fork configuration. Config() *params.ChainConfig // Genesis retrieves the chain's genesis block. Genesis() *types.Block // CurrentHeader retrieves the current head header of the canonical chain. CurrentHeader() *types.Header }
Blockchain defines all necessary method to build a forkID. 实现了Config、Genesis、CurrentHeader三个方法的对象可以直接生成区块链标识符
type Filter ¶
Filter is a fork id filter to validate a remotely advertised ID. 验证远程节点的区块链标识符是否和本地匹配
func NewFilter ¶
func NewFilter(chain Blockchain) Filter
NewFilter creates a filter that returns if a fork ID should be rejected or not based on the local chain's status. 生成一个判断远程节点标识符是否匹配的过滤器 生成的过滤器会随着本地区块高度的变化动态的修改返回结果 也就是每次调用过滤器都会返回本地区块链当前状态与远程节点匹配的结果
func NewStaticFilter ¶
func NewStaticFilter(config *params.ChainConfig, genesis common.Hash) Filter
NewStaticFilter creates a filter at block zero. 生成一个永远保持在创世区块的标识符过滤器
type ID ¶
type ID struct { Hash [4]byte // CRC32 checksum of the genesis block and passed fork block numbers Next uint64 // Block number of the next upcoming fork, or 0 if no forks are known }
ID is a fork identifier as defined by EIP-2124. 代表一个区块链标识符
func NewID ¶
NewID calculates the Ethereum fork ID from the chain config, genesis hash, and head. 根据区块链配置、创世区块以及当前区块高度创建区块链标识符
func NewIDWithChain ¶
func NewIDWithChain(chain Blockchain) ID
NewIDWithChain calculates the Ethereum fork ID from an existing chain instance. 基于BlockChain对象生成区块链标识符