quorum

package
v0.0.0-...-e03aae4 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Package quorum implements the proof-of-concept community proof-of-stake consensus engine.

Index

Constants

This section is empty.

Variables

View Source
var (
	FrontierBlockReward       = big.NewInt(5e+18) // Block reward in wei for successfully mining a block
	ByzantiumBlockReward      = big.NewInt(3e+18) // Block reward in wei for successfully mining a block
	ConstantinopleBlockReward = big.NewInt(2e+18) // Block reward in wei for successfully mining a block
)

QuorumEngine proof-of-concept community proof-of-stake protocol constants.

Functions

func CalcDifficulty

func CalcDifficulty(header *types.Header, snap *Snapshot) *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.

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-authority scheme.

func (*API) GetSigner

func (api *API) GetSigner() common.Address

GetSigner retrieves the signer address of the current node.

func (*API) GetSigners

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

GetSigners retrieves the map of authorized signers at the specified block.

func (*API) GetSnapshot

func (api *API) GetSnapshot(number *big.Int) (*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.

type BlockProducer

type BlockProducer struct {
	SequenceNumber uint64 `json:"sequenceNumber"`
}

type QuorumEngine

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

QuorumEngine is the proof-of-concept community proof-of-stake consensus engine

func New

func New(config *params.QuorumEngineConfig, db ethdb.Database, q QuorumService, cposBlock *big.Int) *QuorumEngine

New creates a QuorumEngine proof-of-concept community proof-of-stake consensus engine with the initial signers set to the ones provided in the genesis.json

func (*QuorumEngine) APIs

func (q *QuorumEngine) APIs(chain consensus.ChainReader) []rpc.API

APIs implements consensus.Engine, returning the user facing RPC API to allow controlling the signer voting.

func (*QuorumEngine) Author

func (q *QuorumEngine) Author(header *types.Header) (common.Address, error)

Author implements consensus.Engine, returning the Ethereum address recovered from the signature in the header's extra-data section.

func (*QuorumEngine) AuthorTimestamp

func (q *QuorumEngine) AuthorTimestamp(blockNumber, blockTimestamp *big.Int, signature []byte) (common.Address, error)

AuthorTimestamp extends consensus.Engine, returning the Ethereum address recovered from the signature in the timestamp message's signature field.

func (*QuorumEngine) Authorize

func (q *QuorumEngine) Authorize(signer common.Address, signFn SignerFn)

Authorize injects a private key into the consensus engine to mint new blocks with.

func (*QuorumEngine) CalcDifficulty

func (q *QuorumEngine) CalcDifficulty(chain consensus.ChainReader, _ uint64, parent *types.Header) (res *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 (*QuorumEngine) Checkpoint

func (q *QuorumEngine) Checkpoint(current, parent *types.Header, chain consensus.ChainReader) (bool, error)

Checkpoint gets epochs of header and header's parent and compares them if the header epoch is greater than the parent's epoch isCheckpoint returns true, otherwise - false

func (*QuorumEngine) Close

func (q *QuorumEngine) Close() error

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

func (*QuorumEngine) Config

func (q *QuorumEngine) Config() *params.QuorumEngineConfig

func (*QuorumEngine) Finalize

func (q *QuorumEngine) Finalize(chain consensus.ChainReader,
	header *types.Header, stateDB *state.DB, _ []*types.Transaction, _ []*types.Header)

Finalize implements consensus.Engine, ensuring no uncles are set, nor block rewards given, and returns the final block.

func (*QuorumEngine) FinalizeAndAssemble

func (q *QuorumEngine) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header,
	stateDB *state.DB, txs []*types.Transaction,
	uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

func (*QuorumEngine) GetBlockProducerSequence

func (q *QuorumEngine) GetBlockProducerSequence(miners []common.Address,
	hash common.Hash) map[common.Address]BlockProducer

GetBlockProducers shuffles the miners list using hash as shuffle seed, compacts the list is the form of map[common.Address]BlockProducer

func (*QuorumEngine) GetEpochByTime

func (q *QuorumEngine) GetEpochByTime(t uint64) uint64

func (*QuorumEngine) GetSigner

func (q *QuorumEngine) GetSigner() common.Address

func (*QuorumEngine) Inturn

func (q *QuorumEngine) Inturn(blockNumber, blockTimestamp *big.Int, signature []byte, snapshotHash common.Hash) bool

Inturn returns true if a it's a signer's turn to produce a block at a given timestamp.

func (*QuorumEngine) Prepare

func (q *QuorumEngine) Prepare(chain consensus.ChainReader, header *types.Header) (err error)

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

func (*QuorumEngine) Seal

func (q *QuorumEngine) Seal(chain consensus.ChainReader, block *types.Block, results chan<- *types.Block,
	stop <-chan struct{}) (err error)

Seal implements consensus.Engine, attempting to create a sealed block using the local signing credentials. nolint:funlen

func (*QuorumEngine) SealHash

func (q *QuorumEngine) SealHash(header *types.Header) common.Hash

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

func (*QuorumEngine) Snapshot

func (q *QuorumEngine) Snapshot(header *types.Header) (*Snapshot, error)

Snapshot loads the authorization snapshot at a given point in time.

func (*QuorumEngine) VerifyHeader

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

VerifyHeader checks whether a header conforms to the consensus rules.

func (*QuorumEngine) VerifyHeaders

func (q *QuorumEngine) 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). nolint:gocritic

func (*QuorumEngine) VerifySeal

func (q *QuorumEngine) 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 (*QuorumEngine) VerifyUncles

func (q *QuorumEngine) 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 QuorumService

type QuorumService interface {
	node.Service
	Prepared() bool
	PrepareNodeListAtEpoch(uint64)
	MinerListAtEpoch(uint64) []common.Address
}

type SignerFn

type SignerFn func([]byte) ([]byte, error)

SignerFn is a signer callback function to request a hash to be signed by a backing account.

type Snapshot

type Snapshot struct {
	Epoch   uint64                           `json:"epoch"`
	Signers map[common.Address]BlockProducer `json:"signers"` // Set of authorized signers at this moment
	Recents map[uint64]common.Address        `json:"recents"`
	// contains filtered or unexported fields
}

Snapshot is the state of the authorization voting at a given point in time.

func (*Snapshot) Hash

func (s *Snapshot) Hash() (h common.Hash)

type TimeFrame

type TimeFrame struct {
	Start uint64 `json:"start"`
	End   uint64 `json:"end"`
}

Jump to

Keyboard shortcuts

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