Documentation ¶
Index ¶
- Variables
- func GetSelfNodeID() []byte
- func GetSelfNodeKey() *ecdsa.PrivateKey
- func GetTermIndexByHeight(height uint32) uint32
- func IsRewardBlock(height uint32) bool
- func IsSnapshotBlock(height uint32) bool
- func SetSelfNodeKey(key *ecdsa.PrivateKey)
- type DeputyNode
- type DeputyNodes
- type DeputySalary
- type Manager
- func (m *Manager) GetDeputiesByHeight(height uint32) DeputyNodes
- func (m *Manager) GetDeputiesCount(height uint32) int
- func (m *Manager) GetDeputyByAddress(height uint32, addr common.Address) *DeputyNode
- func (m *Manager) GetDeputyByNodeID(height uint32, nodeID []byte) *DeputyNode
- func (m *Manager) GetMyDeputyInfo(height uint32) *DeputyNode
- func (m *Manager) GetMyMinerAddress(height uint32) (common.Address, bool)
- func (m *Manager) GetTermByHeight(height uint32) (*TermRecord, error)
- func (m *Manager) IsEvilDeputyNode(minerAddress common.Address, currentHeight uint32) bool
- func (m *Manager) IsNodeDeputy(height uint32, nodeID []byte) bool
- func (m *Manager) IsSelfDeputyNode(height uint32) bool
- func (m *Manager) PutEvilDeputyNode(minerAddress common.Address, blockHeight uint32)
- func (m *Manager) SaveSnapshot(snapshotHeight uint32, nodes DeputyNodes)
- func (m *Manager) TwoThirdDeputyCount(height uint32) uint32
- type TermRecord
Constants ¶
This section is empty.
Variables ¶
var ( ErrMinerAddressInvalid = errors.New("incorrect field: 'MinerAddress'") ErrNodeIDInvalid = errors.New("incorrect field: 'NodeID'") ErrRankInvalid = errors.New("max deputy node's rank is 65535") ErrVotesInvalid = errors.New("min deputy node's votes are 0") )
var ( ErrNoDeputyInBlock = errors.New("there is no deputy nodes in snapshot block") ErrInvalidDeputyRank = errors.New("deputy nodes should be sorted by rank and start from 0") ErrInvalidDeputyVotes = errors.New("there is a conflict between deputy node' rank and votes") ErrMissingTerm = errors.New("some term is missing") ErrInvalidSnapshotHeight = errors.New("invalid snapshot block height") ErrNoTerms = errors.New("can't access deputy nodes before SaveSnapshot") ErrQueryFutureTerm = errors.New("can't query future term") )
Functions ¶
func GetSelfNodeID ¶
func GetSelfNodeID() []byte
func GetSelfNodeKey ¶
func GetSelfNodeKey() *ecdsa.PrivateKey
func GetTermIndexByHeight ¶ added in v1.2.0
GetTermIndexByHeight return the index of the term which in charge of consensus the specific block
0 term start at height 0 1 term start at 100W+1K+1 2 term start at 200W+1K+1 ...
func SetSelfNodeKey ¶
func SetSelfNodeKey(key *ecdsa.PrivateKey)
Types ¶
type DeputyNode ¶
type DeputyNode struct { MinerAddress common.Address `json:"minerAddress" gencodec:"required"` // candidate account address NodeID []byte `json:"nodeID" gencodec:"required"` Rank uint32 `json:"rank" gencodec:"required"` // start from 0 Votes *big.Int `json:"votes" gencodec:"required"` }
DeputyNode
func NewDeputyNode ¶ added in v1.3.0
func (*DeputyNode) Check ¶
func (d *DeputyNode) Check() error
func (*DeputyNode) Copy ¶ added in v1.2.0
func (d *DeputyNode) Copy() *DeputyNode
func (*DeputyNode) Hash ¶
func (d *DeputyNode) Hash() (h common.Hash)
func (DeputyNode) MarshalJSON ¶
func (d DeputyNode) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*DeputyNode) UnmarshalJSON ¶
func (d *DeputyNode) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.
type DeputyNodes ¶
type DeputyNodes []*DeputyNode
func (DeputyNodes) MerkleRootSha ¶ added in v1.2.0
func (nodes DeputyNodes) MerkleRootSha() common.Hash
MerkleRootSha compute the root hash of deputy nodes merkle trie
func (DeputyNodes) String ¶ added in v1.1.1
func (nodes DeputyNodes) String() string
type DeputySalary ¶
type Manager ¶
type Manager struct { DeputyCount int // Max deputy count. Not include candidate nodes // contains filtered or unexported fields }
Manager 代理节点管理器
func NewManager ¶ added in v1.2.0
NewManager creates a new Manager. It is used to maintain term record list
func (*Manager) GetDeputiesByHeight ¶ added in v1.1.1
func (m *Manager) GetDeputiesByHeight(height uint32) DeputyNodes
GetDeputiesByHeight 通过height获取对应的节点列表
func (*Manager) GetDeputiesCount ¶
GetDeputiesCount 获取共识节点数量
func (*Manager) GetDeputyByAddress ¶
func (m *Manager) GetDeputyByAddress(height uint32, addr common.Address) *DeputyNode
GetDeputyByAddress 获取address对应的节点
func (*Manager) GetDeputyByNodeID ¶
func (m *Manager) GetDeputyByNodeID(height uint32, nodeID []byte) *DeputyNode
GetDeputyByNodeID 根据nodeID获取对应的节点
func (*Manager) GetMyDeputyInfo ¶ added in v1.3.0
func (m *Manager) GetMyDeputyInfo(height uint32) *DeputyNode
GetMyDeputyInfo 获取自己在某一届高度的共识节点信息
func (*Manager) GetMyMinerAddress ¶ added in v1.3.0
GetMyMinerAddress 获取自己在某一届高度的矿工账号
func (*Manager) GetTermByHeight ¶ added in v1.2.0
func (m *Manager) GetTermByHeight(height uint32) (*TermRecord, error)
GetTermByHeight 通过height获取对应的任期信息
func (*Manager) IsEvilDeputyNode ¶ added in v1.3.0
IsEvilDeputyNode currentHeight is current block height
func (*Manager) IsNodeDeputy ¶ added in v1.0.2
IsNodeDeputy
func (*Manager) IsSelfDeputyNode ¶
IsSelfDeputyNode
func (*Manager) PutEvilDeputyNode ¶ added in v1.3.0
SetAbnormalDeputyNode height is block height
func (*Manager) SaveSnapshot ¶ added in v1.2.0
func (m *Manager) SaveSnapshot(snapshotHeight uint32, nodes DeputyNodes)
SaveSnapshot add deputy nodes record by snapshot block data
func (*Manager) TwoThirdDeputyCount ¶ added in v1.3.0
TwoThirdDeputyCount return the deputy nodes count * 2/3
type TermRecord ¶ added in v1.2.0
type TermRecord struct { TermIndex uint32 `json:"termIndex"` // start from 0 Nodes DeputyNodes `json:"nodes"` // include deputy nodes and candidate nodes }
func NewTermRecord ¶ added in v1.2.0
func NewTermRecord(snapshotHeight uint32, nodes DeputyNodes) *TermRecord
func (*TermRecord) GetDeputies ¶ added in v1.2.0
func (t *TermRecord) GetDeputies(count int) DeputyNodes
GetDeputies return deputy nodes. They are top items in t.Nodes
func (*TermRecord) GetTotalVotes ¶ added in v1.2.0
func (t *TermRecord) GetTotalVotes() *big.Int
func (TermRecord) MarshalJSON ¶ added in v1.2.0
func (t TermRecord) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*TermRecord) UnmarshalJSON ¶ added in v1.2.0
func (t *TermRecord) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.