parlia

package
v1.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2020 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcDifficulty

func CalcDifficulty(snap *Snapshot, signer common.Address) *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 FindAncientHeader

func FindAncientHeader(header *types.Header, ite uint64, chain consensus.ChainReader, candidateParents []*types.Header) *types.Header

func ParliaRLP

func ParliaRLP(header *types.Header, chainId *big.Int) []byte

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.

func ParseValidators

func ParseValidators(validatorsBytes []byte) ([]common.Address, error)

func SealHash

func SealHash(header *types.Header, chainId *big.Int) (hash common.Hash)

=========================== utility function ========================== SealHash returns the hash of a block prior to it being sealed.

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) GetSnapshot

func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetSnapshotAtHash

func (api *API) GetSnapshotAtHash(hash common.Hash) (*Snapshot, error)

GetSnapshotAtHash retrieves the state snapshot at a given block.

func (*API) GetValidators

func (api *API) GetValidators(number *rpc.BlockNumber) ([]common.Address, error)

GetValidators retrieves the list of validators at the specified block.

func (*API) GetValidatorsAtHash

func (api *API) GetValidatorsAtHash(hash common.Hash) ([]common.Address, error)

GetValidatorsAtHash retrieves the list of validators at the specified block.

type Parlia

type Parlia struct {
	// contains filtered or unexported fields
}

Parlia is the consensus engine of BSC

func New

func New(
	chainConfig *params.ChainConfig,
	db ethdb.Database,
	ethAPI *ethapi.PublicBlockChainAPI,
) *Parlia

New creates a Parlia consensus engine.

func (*Parlia) APIs

func (p *Parlia) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to query snapshot.

func (*Parlia) Author

func (p *Parlia) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the SystemAddress

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) CalcDifficulty

func (p *Parlia) CalcDifficulty(chain consensus.ChainReader, 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

func (p *Parlia) Close() error

Close implements consensus.Engine. It's a noop for parlia as there are no background threads.

func (*Parlia) Finalize

func (p *Parlia) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs *[]*types.Transaction,
	uncles []*types.Header, receipts *[]*types.Receipt, systemTxs *[]*types.Transaction, usedGas *uint64) error

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given.

func (*Parlia) FinalizeAndAssemble

func (p *Parlia) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB,
	txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*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) IsSystemContract

func (p *Parlia) IsSystemContract(to *common.Address) bool

func (*Parlia) IsSystemTransaction

func (p *Parlia) IsSystemTransaction(tx *types.Transaction, header *types.Header) (bool, error)

func (*Parlia) Prepare

func (p *Parlia) Prepare(chain consensus.ChainReader, header *types.Header) error

Prepare implements consensus.Engine, preparing all the consensus fields of the header for running the transactions on top.

func (*Parlia) Seal

func (p *Parlia) Seal(chain consensus.ChainReader, 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

func (p *Parlia) SealHash(header *types.Header) common.Hash

SealHash returns the hash of a block prior to it being sealed.

func (*Parlia) VerifyHeader

func (p *Parlia) VerifyHeader(chain consensus.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*Parlia) VerifyHeaders

func (p *Parlia) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, seals []bool) (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) VerifySeal

func (p *Parlia) VerifySeal(chain consensus.ChainReader, header *types.Header) error

VerifySeal implements consensus.Engine, checking whether the signature contained in the header satisfies the consensus protocol requirements.

func (*Parlia) VerifyUncles

func (p *Parlia) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles implements consensus.Engine, always returning an error for any uncles as this consensus mechanism doesn't permit uncles.

type SignerFn

type SignerFn func(accounts.Account, string, []byte) ([]byte, error)

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
	Validators map[common.Address]struct{} `json:"validators"` // Set of authorized validators at this moment
	Recents    map[uint64]common.Address   `json:"recents"`    // Set of recent validators for spam protections
	// contains filtered or unexported fields
}

Snapshot is the state of the validatorSet at a given point.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL