Documentation
¶
Index ¶
- func CalcDifficulty(snap *Snapshot, signer common.Address) *big.Int
- func FindAncientHeader(header *types.Header, ite uint64, chain consensus.ChainHeaderReader, ...) *types.Header
- func ParliaRLP(header *types.Header, chainId *big.Int) []byte
- type API
- func (api *API) GetFinalizedNumber(number *rpc.BlockNumber) (uint64, error)
- func (api *API) GetJustifiedNumber(number *rpc.BlockNumber) (uint64, error)
- func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
- func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)
- func (api *API) GetTurnLength(number *rpc.BlockNumber) (uint8, error)
- func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)
- func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)
- type Parlia
- func (p *Parlia) APIs(chain consensus.ChainHeaderReader) []rpc.API
- func (p *Parlia) AddNodeIDs(nodeIDs []enode.ID, nonce uint64) (*types.Transaction, error)
- func (p *Parlia) Author(header *types.Header) (common.Address, error)
- func (p *Parlia) Authorize(val common.Address, signFn SignerFn, signTxFn SignerTxFn)
- func (p *Parlia) BlockInterval(chain consensus.ChainHeaderReader, header *types.Header) (uint64, error)
- func (p *Parlia) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int
- func (p *Parlia) Close() error
- func (p *Parlia) ConsensusAddress() common.Address
- func (p *Parlia) Delay(chain consensus.ChainReader, header *types.Header, leftOver *time.Duration) *time.Duration
- func (p *Parlia) EnoughDistance(chain consensus.ChainReader, header *types.Header) bool
- func (p *Parlia) EstimateGasReservedForSystemTxs(chain consensus.ChainHeaderReader, header *types.Header) uint64
- func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state vm.StateDB, ...) error
- func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, ...) (*types.Block, []*types.Receipt, error)
- func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *types.Header) *types.Header
- func (p *Parlia) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, headers []*types.Header) (uint64, common.Hash, error)
- func (p *Parlia) GetNodeIDs() ([]enode.ID, error)
- func (p *Parlia) GetNodeIDsMap() (map[common.Address][]enode.ID, error)
- func (p *Parlia) GetValidators(offset, limit *big.Int) ([]common.Address, []common.Address, *big.Int, error)
- func (p *Parlia) IsActiveValidatorAt(chain consensus.ChainHeaderReader, header *types.Header, ...) bool
- func (p *Parlia) IsLocalBlock(header *types.Header) bool
- func (p *Parlia) IsSystemContract(to *common.Address) bool
- func (p *Parlia) IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)
- func (p *Parlia) NextInTurnValidator(chain consensus.ChainHeaderReader, header *types.Header) (common.Address, error)
- func (p *Parlia) NextProposalBlock(chain consensus.ChainHeaderReader, header *types.Header, ...) (uint64, uint64, error)
- func (p *Parlia) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error
- func (p *Parlia) RemoveNodeIDs(nodeIDs []enode.ID, nonce uint64) (*types.Transaction, error)
- func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, ...) error
- func (p *Parlia) SealHash(header *types.Header) (hash common.Hash)
- func (p *Parlia) SignRecently(chain consensus.ChainReader, parent *types.Header) (bool, error)
- func (p *Parlia) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header) error
- func (p *Parlia) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error)
- func (p *Parlia) VerifyRequests(header *types.Header, Requests [][]byte) error
- func (p *Parlia) VerifySeal(chain consensus.ChainReader, header *types.Header) error
- func (p *Parlia) VerifyUncles(chain consensus.ChainReader, block *types.Block) error
- func (p *Parlia) VerifyVote(chain consensus.ChainHeaderReader, vote *types.VoteEnvelope) error
- type SignerFn
- type SignerTxFn
- type Snapshot
- type ValidatorHeap
- type ValidatorInfo
- type ValidatorItem
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcDifficulty ¶
CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty that a new block should have based on the previous blocks in the chain and the current signer.
func FindAncientHeader ¶
func ParliaRLP ¶
ParliaRLP returns the rlp bytes which needs to be signed for the parlia 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 query snapshot and validators
func (*API) GetFinalizedNumber ¶ added in v1.0.4
func (api *API) GetFinalizedNumber(number *rpc.BlockNumber) (uint64, error)
func (*API) GetJustifiedNumber ¶ added in v1.0.4
func (api *API) GetJustifiedNumber(number *rpc.BlockNumber) (uint64, error)
func (*API) GetSnapshot ¶
func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)
GetSnapshot retrieves the state snapshot at a given block.
func (*API) GetSnapshotAtHash ¶
GetSnapshotAtHash retrieves the state snapshot at a given block.
func (*API) GetTurnLength ¶ added in v1.0.4
func (api *API) GetTurnLength(number *rpc.BlockNumber) (uint8, error)
func (*API) GetValidators ¶
GetValidators retrieves the list of validators at the specified block.
type Parlia ¶
Parlia is the consensus engine of BSC
func New ¶
func New( chainConfig *params.ChainConfig, db ethdb.Database, ethAPI *ethapi.BlockChainAPI, genesisHash common.Hash, ) *Parlia
New creates a Parlia consensus engine.
func (*Parlia) APIs ¶
func (p *Parlia) APIs(chain consensus.ChainHeaderReader) []rpc.API
APIs implements consensus.Engine, returning the user facing RPC API to query snapshot.
func (*Parlia) AddNodeIDs ¶ added in v1.0.4
AddNodeIDs creates a signed transaction to add node IDs to the StakeHub contract
func (*Parlia) Authorize ¶
func (p *Parlia) Authorize(val common.Address, signFn SignerFn, signTxFn SignerTxFn)
Authorize injects a private key into the consensus engine to mint new blocks with.
func (*Parlia) BlockInterval ¶ added in v1.0.4
func (p *Parlia) BlockInterval(chain consensus.ChainHeaderReader, header *types.Header) (uint64, error)
BlockInterval returns the block interval in milliseconds for the given header
func (*Parlia) CalcDifficulty ¶
func (p *Parlia) 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 based on the previous blocks in the chain and the current signer.
func (*Parlia) Close ¶
Close implements consensus.Engine. It's a noop for parlia as there are no background threads.
func (*Parlia) ConsensusAddress ¶ added in v1.0.4
ConsensusAddress returns the consensus address of the validator
func (*Parlia) Delay ¶
func (p *Parlia) Delay(chain consensus.ChainReader, header *types.Header, leftOver *time.Duration) *time.Duration
Argument leftOver is the time reserved for block finalize(calculate root, distribute income...)
func (*Parlia) EnoughDistance ¶
func (*Parlia) EstimateGasReservedForSystemTxs ¶ added in v1.0.4
func (*Parlia) Finalize ¶
func (p *Parlia) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state vm.StateDB, txs *[]*types.Transaction, uncles []*types.Header, _ []*types.Withdrawal, receipts *[]*types.Receipt, systemTxs *[]*types.Transaction, usedGas *uint64, tracer *tracing.Hooks) error
Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.
func (*Parlia) FinalizeAndAssemble ¶
func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, body *types.Body, receipts []*types.Receipt, tracer *tracing.Hooks) (*types.Block, []*types.Receipt, error)
FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.
func (*Parlia) GetFinalizedHeader ¶ added in v1.0.4
func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *types.Header) *types.Header
GetFinalizedHeader returns highest finalized block header.
func (*Parlia) GetJustifiedNumberAndHash ¶ added in v1.0.4
func (p *Parlia) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, headers []*types.Header) (uint64, common.Hash, error)
GetJustifiedNumberAndHash retrieves the number and hash of the highest justified block within the branch including `headers` and utilizing the latest element as the head.
func (*Parlia) GetNodeIDs ¶ added in v1.0.4
GetNodeIDs returns a flattened array of all node IDs for current validators
func (*Parlia) GetNodeIDsMap ¶ added in v1.0.4
GetNodeIDsMap returns a map of consensus addresses to their node IDs for all current validators
func (*Parlia) GetValidators ¶ added in v1.0.4
func (p *Parlia) GetValidators(offset, limit *big.Int) ([]common.Address, []common.Address, *big.Int, error)
GetValidators retrieves validators from the StakeHubContract It returns operator addresses, credit addresses, and total length of validators
func (*Parlia) IsActiveValidatorAt ¶ added in v1.0.4
func (p *Parlia) IsActiveValidatorAt(chain consensus.ChainHeaderReader, header *types.Header, checkVoteKeyFn func(bLSPublicKey *types.BLSPublicKey) bool) bool
func (*Parlia) IsSystemTransaction ¶
func (*Parlia) NextInTurnValidator ¶ added in v1.0.4
func (p *Parlia) NextInTurnValidator(chain consensus.ChainHeaderReader, header *types.Header) (common.Address, error)
NextInTurnValidator return the next in-turn validator for header
func (*Parlia) NextProposalBlock ¶ added in v1.0.4
func (*Parlia) Prepare ¶
Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.
func (*Parlia) RemoveNodeIDs ¶ added in v1.0.4
RemoveNodeIDs creates a signed transaction to remove node IDs from the StakeHub contract
func (*Parlia) Seal ¶
func (p *Parlia) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error
Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials.
func (*Parlia) SealHash ¶
SealHash returns the hash of a block without vote attestation prior to it being sealed. So it's not the real hash of a block, just used as unique id to distinguish task
func (*Parlia) SignRecently ¶
func (*Parlia) VerifyHeader ¶
VerifyHeader checks whether a header conforms to the consensus rules.
func (*Parlia) VerifyHeaders ¶
func (p *Parlia) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header) (chan<- struct{}, <-chan error)
VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers. 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 (*Parlia) VerifyRequests ¶ added in v1.0.4
func (*Parlia) VerifySeal ¶
VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.
func (*Parlia) VerifyUncles ¶
VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.
func (*Parlia) VerifyVote ¶ added in v1.0.4
func (p *Parlia) VerifyVote(chain consensus.ChainHeaderReader, vote *types.VoteEnvelope) error
VerifyVote will verify: 1. If the vote comes from valid validators 2. If the vote's sourceNumber and sourceHash are correct
type SignerFn ¶
SignerFn is a signer callback function to request a header to be signed by a backing account.
type SignerTxFn ¶
type SignerTxFn func(accounts.Account, *types.Transaction, *big.Int) (*types.Transaction, error)
type Snapshot ¶
type Snapshot struct {
Number uint64 `json:"number"` // Block number where the snapshot was created
Hash common.Hash `json:"hash"` // Block hash where the snapshot was created
EpochLength uint64 `json:"epoch_length"` // Number of Blocks in one epoch
BlockInterval uint64 `json:"block_interval"` // Block Interval in milliseconds
TurnLength uint8 `json:"turn_length"` // Length of `turn`, meaning the consecutive number of blocks a validator receives priority for block production
Validators map[common.Address]*ValidatorInfo `json:"validators"` // Set of authorized validators at this moment
Recents map[uint64]common.Address `json:"recents"` // Set of recent validators for spam protections
RecentForkHashes map[uint64]string `json:"recent_fork_hashes"` // Set of recent forkHash
Attestation *types.VoteData `json:"attestation:omitempty"` // Attestation for fast finality, but `Source` used as `Finalized`
// contains filtered or unexported fields
}
Snapshot is the state of the validatorSet at a given point.
type ValidatorHeap ¶ added in v1.0.4
type ValidatorHeap []ValidatorItem
An ValidatorHeap is a max-heap of validator's votingPower.
func (*ValidatorHeap) Len ¶ added in v1.0.4
func (h *ValidatorHeap) Len() int
func (*ValidatorHeap) Less ¶ added in v1.0.4
func (h *ValidatorHeap) Less(i, j int) bool
func (*ValidatorHeap) Pop ¶ added in v1.0.4
func (h *ValidatorHeap) Pop() interface{}
func (*ValidatorHeap) Push ¶ added in v1.0.4
func (h *ValidatorHeap) Push(x interface{})
func (*ValidatorHeap) Swap ¶ added in v1.0.4
func (h *ValidatorHeap) Swap(i, j int)
type ValidatorInfo ¶ added in v1.0.4
type ValidatorInfo struct {
Index int `json:"index:omitempty"` // The index should offset by 1
VoteAddress types.BLSPublicKey `json:"vote_address,omitempty"`
}
type ValidatorItem ¶ added in v1.0.4
type ValidatorItem struct {
// contains filtered or unexported fields
}