Documentation ¶
Index ¶
- Variables
- func EqualityRLP(header *types.Header) []byte
- func SealHash(header *types.Header) (hash common.Hash)
- type API
- func (api *API) GetAddress(address common.Address, number *rpc.BlockNumber) (rpcCandidateInfo, error)
- func (api *API) GetCandidates(number *rpc.BlockNumber) ([]rpcCandidate, error)
- func (api *API) GetCandidatesCount(number *rpc.BlockNumber) (rpcCandidatesCount, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]rpcValidator, error)
- type Candidate
- type Equality
- func (e *Equality) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (e *Equality) Author(header *types.Header) (common.Address, error)
- func (e *Equality) Authorize(signer common.Address, signFn SignerFn)
- func (e *Equality) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (e *Equality) Close() error
- func (e *Equality) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...)
- func (e *Equality) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, error)
- func (e *Equality) InTurn(lastBlockHeader *types.Header, now uint64) bool
- func (e *Equality) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (e *Equality) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (e *Equality) SealHash(header *types.Header) (hash common.Hash)
- func (e *Equality) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
- func (e *Equality) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
- func (e *Equality) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error
- func (e *Equality) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- type EventBecomeCandidate
- type EventCancelCandidate
- type HeaderExtra
- type Root
- type SignerFn
- type Snapshot
- func (snap *Snapshot) BecomeCandidate(candidateAddr common.Address, blockNumber uint64, security *big.Int, ...) (exist bool, err error)
- func (snap *Snapshot) CancelCandidate(candidateAddr common.Address) (exist bool, security *big.Int, err error)
- func (snap *Snapshot) Commit(root Root) error
- func (snap *Snapshot) CountMinted(epoch uint64) (SortableAddresses, error)
- func (snap *Snapshot) EnoughCandidates(n int) (int, bool)
- func (snap *Snapshot) GetCandidate(candidateAddr common.Address) (*Candidate, error)
- func (snap *Snapshot) GetCandidates() (map[common.Address]Candidate, error)
- func (snap *Snapshot) GetChainConfig() (params.EqualityConfig, error)
- func (snap *Snapshot) GetValidators() ([]common.Address, error)
- func (snap *Snapshot) MintBlock(epoch, number uint64, validator common.Address) error
- func (snap *Snapshot) RandCandidates(seed int64, n int) ([]common.Address, error)
- func (snap *Snapshot) Root() (root Root, err error)
- func (snap *Snapshot) SetChainConfig(config params.EqualityConfig) error
- func (snap *Snapshot) SetValidators(validators []common.Address) error
- type SortableAddress
- type SortableAddresses
- type Transaction
- type TransactionType
- type Trie
- func (t *Trie) Commit(onleaf trie.LeafCallback) (root common.Hash, err error)
- func (t *Trie) Delete(key []byte)
- func (t *Trie) Get(key []byte) []byte
- func (t *Trie) Hash() common.Hash
- func (t *Trie) NodeIterator(start []byte) trie.NodeIterator
- func (t *Trie) PrefixIterator(prefix []byte) trie.NodeIterator
- func (t *Trie) TryDelete(key []byte) error
- func (t *Trie) TryGet(key []byte) ([]byte, error)
- func (t *Trie) TryUpdate(key, value []byte) error
- func (t *Trie) Update(key, value []byte)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTimestamp is returned if the timestamp of a block is lower than // the previous block's timestamp + the minimum block period. ErrInvalidTimestamp = errors.New("invalid timestamp") // ErrChainConfigMissing is returned if the chain config is missing ErrChainConfigMissing = errors.New("chain config missing") )
Various error messages to mark blocks invalid. These should be private to prevent engine specific errors from being referenced in the remainder of the codebase, inherently breaking if the engine is swapped out. Please put common error types into the consensus package.
Functions ¶
func EqualityRLP ¶
EqualityRLP returns the rlp bytes which needs to be signed for the proof-of-equality sealing. The RLP to sign consists of the entire header apart from the 65 byte signature contained at the end of the extra data.
Note, the method requires the extra data to be at least 65 bytes, otherwise it panics. This is done to avoid accidentally using both forms (signature present or not), which could be abused to produce different hashes for the same header.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API is a user facing RPC API to allow controlling the signer and voting mechanisms of the proof-of-equality scheme.
func (*API) GetAddress ¶
func (api *API) GetAddress(address common.Address, number *rpc.BlockNumber) (rpcCandidateInfo, error)
GetAddress retrieves the candidate information of the address
func (*API) GetCandidates ¶
func (api *API) GetCandidates(number *rpc.BlockNumber) ([]rpcCandidate, error)
GetCandidates retrieves the list of the candidates at specified block
func (*API) GetCandidatesCount ¶
func (api *API) GetCandidatesCount(number *rpc.BlockNumber) (rpcCandidatesCount, error)
GetCandidatesCount retrieves number of the candidates at specified block
func (*API) GetValidators ¶
func (api *API) GetValidators(number *rpc.BlockNumber) ([]rpcValidator, error)
GetValidators retrieves the list of the validators at specified block
type Equality ¶
type Equality struct {
// contains filtered or unexported fields
}
Equality is the proof-of-equality consensus engine.
func New ¶
func New(config *params.EqualityConfig, db ethdb.Database) *Equality
New creates a Equality proof-of-equality consensus engine with the initial signers set to the ones provided by the user.
func (*Equality) APIs ¶
func (e *Equality) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs returns the RPC APIs this consensus engine provides.
func (*Equality) Author ¶
Author retrieves the Ethereum address of the account that minted the given block, which may be different from the header's coinbase if a consensus engine is based on signatures.
func (*Equality) Authorize ¶
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Equality) CalcDifficulty ¶
func (e *Equality) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have.
func (*Equality) Close ¶
Close terminates any background threads maintained by the consensus engine.
func (*Equality) Finalize ¶
func (e *Equality) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)
Finalize runs any post-transaction state modifications (e.g. block rewards) but does not assemble the block.
Note: The block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).
func (*Equality) FinalizeAndAssemble ¶
func (e *Equality) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)
FinalizeAndAssemble runs any post-transaction state modifications (e.g. block rewards) and assembles the final block.
Note: The block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).
func (*Equality) Prepare ¶
Prepare initializes the consensus fields of a block header according to the rules of a particular engine. The changes are executed inline.
func (*Equality) Seal ¶
func (e *Equality) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
Seal generates a new sealing request for the given input block and pushes the result into the given channel.
Note, the method returns immediately and will send the result async. More than one result may also be returned depending on the consensus algorithm.
func (*Equality) VerifyHeader ¶
func (e *Equality) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
VerifyHeader checks whether a header conforms to the consensus rules of a given engine. Verifying the seal may be done optionally here, or explicitly via the VerifySeal method.
func (*Equality) VerifyHeaders ¶
func (e *Equality) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)
VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. The method returns a quit channel to abort the operations and a results channel to retrieve the async verifications (the order is that of the input slice).
func (*Equality) VerifySeal ¶
VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.
func (*Equality) VerifyUncles ¶
VerifyUncles verifies that the given block's uncles conform to the consensus rules of a given engine.
type EventBecomeCandidate ¶
EventBecomeCandidate apply to become Candidate. data like "equality:1:event:candidate" Sender will become a Candidate
func (*EventBecomeCandidate) Action ¶
func (event *EventBecomeCandidate) Action() string
func (*EventBecomeCandidate) Decode ¶
func (event *EventBecomeCandidate) Decode(tx *types.Transaction, data []byte) error
func (*EventBecomeCandidate) Type ¶
func (event *EventBecomeCandidate) Type() TransactionType
type EventCancelCandidate ¶
EventCancelCandidate apply to cancel Candidate. data like "equality:1:event:delegator" Sender will cancel Candidate status
func (*EventCancelCandidate) Action ¶
func (event *EventCancelCandidate) Action() string
func (*EventCancelCandidate) Decode ¶
func (event *EventCancelCandidate) Decode(tx *types.Transaction, data []byte) error
func (*EventCancelCandidate) Type ¶
func (event *EventCancelCandidate) Type() TransactionType
type HeaderExtra ¶
type HeaderExtra struct { Root Root Epoch uint64 EpochBlock uint64 CurrentBlockCandidates []common.Address CurrentBlockKickOutCandidates []common.Address CurrentBlockCancelCandidates []common.Address CurrentEpochValidators []common.Address ChainConfig []params.EqualityConfig }
HeaderExtra is the struct of info in header.Extra[extraVanity:len(header.extra)-extraSeal]. HeaderExtra is the current struct.
func DecodeHeaderExtra ¶
func DecodeHeaderExtra(header *types.Header) (HeaderExtra, error)
func NewHeaderExtra ¶
func NewHeaderExtra(data []byte) (HeaderExtra, error)
NewHeaderExtra new HeaderExtra from rlp bytes.
func (HeaderExtra) Encode ¶
func (headerExtra HeaderExtra) Encode() ([]byte, error)
Encode encode header extra as rlp bytes.
func (HeaderExtra) Equal ¶
func (headerExtra HeaderExtra) Equal(other HeaderExtra) bool
Equal compares two HeaderExtras for equality.
type Root ¶
type Root struct { EpochHash common.Hash CandidateHash common.Hash MintCntHash common.Hash ConfigHash common.Hash }
Root is the state tree root.
func (Root) PrintDifference ¶
type Snapshot ¶
type Snapshot struct {
// contains filtered or unexported fields
}
Snapshot is the state of the authorization voting at a given block number.
func (*Snapshot) BecomeCandidate ¶
func (snap *Snapshot) BecomeCandidate( candidateAddr common.Address, blockNumber uint64, security *big.Int, force ...bool) (exist bool, err error)
BecomeCandidate add a new candidate, return a bool value means address already is or not a candidate
func (*Snapshot) CancelCandidate ¶
func (snap *Snapshot) CancelCandidate(candidateAddr common.Address) (exist bool, security *big.Int, err error)
CancelCandidate remove a candidate
func (*Snapshot) CountMinted ¶
func (snap *Snapshot) CountMinted(epoch uint64) (SortableAddresses, error)
CountMinted count the minted of each validator.
func (*Snapshot) EnoughCandidates ¶
EnoughCandidates count of candidates is greater than or equal to n.
func (*Snapshot) GetCandidate ¶
GetCandidate returns specified candidate information.
func (*Snapshot) GetCandidates ¶
GetCandidates returns all candidates.
func (*Snapshot) GetChainConfig ¶
func (snap *Snapshot) GetChainConfig() (params.EqualityConfig, error)
GetChainConfig returns chain config from snapshot.
func (*Snapshot) GetValidators ¶
GetValidators returns validators of current epoch.
func (*Snapshot) RandCandidates ¶
RandCandidates random return n candidates.
func (*Snapshot) SetChainConfig ¶
func (snap *Snapshot) SetChainConfig(config params.EqualityConfig) error
SetChainConfig write chain config to snapshot.
type SortableAddress ¶
type SortableAddress struct { Address common.Address `json:"address"` Weight *big.Int `json:"weight"` }
SortableAddress sorted by votes.
type SortableAddresses ¶
type SortableAddresses []SortableAddress
SortableAddresses sorting in descending order by weight.
func (SortableAddresses) Len ¶
func (p SortableAddresses) Len() int
func (SortableAddresses) Less ¶
func (p SortableAddresses) Less(i, j int) bool
func (SortableAddresses) String ¶
func (p SortableAddresses) String() string
func (SortableAddresses) Swap ¶
func (p SortableAddresses) Swap(i, j int)
type Transaction ¶
type Transaction interface { Type() TransactionType Action() string Decode(*types.Transaction, []byte) error }
Transaction custom transaction interface.
func NewTransaction ¶
func NewTransaction(tx *types.Transaction) (Transaction, error)
NewTransaction new custom transaction from transaction data. data format: equality:version:type:action:data
type TransactionType ¶
type TransactionType string
TransactionType custom transaction type enums.
const (
EventTransactionType TransactionType = "event"
)
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
PrefixTrie is a Merkle Patricia Trie.
func NewTrieWithPrefix ¶
New creates a trie with an existing root node from db.
func (*Trie) Commit ¶
Commit writes all nodes to the trie's database. Nodes are stored with their sha3 hash as the key. // // Committing flushes nodes from memory. // Subsequent Get calls will load nodes from the database.
func (*Trie) Get ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*Trie) Hash ¶
Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one.
func (*Trie) NodeIterator ¶
func (t *Trie) NodeIterator(start []byte) trie.NodeIterator
NodeIterator returns an iterator that returns nodes of the trie. Iteration starts at the key after the given start key.
func (*Trie) PrefixIterator ¶
func (t *Trie) PrefixIterator(prefix []byte) trie.NodeIterator
PrefixIterator returns an iterator that returns nodes of the trie which has the prefix path specificed Iteration starts at the key after the given start key.
func (*Trie) TryDelete ¶
TryDelete removes any existing value for key from the trie. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryGet ¶
TryGet returns the value for key stored in the trie. The value bytes must not be modified by the caller. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryUpdate ¶
TryUpdate associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) Update ¶
Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.