posv

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package posv implements the Proof-of-Stake Voting consensus engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcReward added in v0.2.6

func CalcReward(cfg *params.PoSVConfig, checkpoint uint64) *big.Int

CalcReward return reward of current epoch

func CliqueRLP

func CliqueRLP(header *types.Header) []byte

CliqueRLP returns the rlp bytes which needs to be signed for the proof-of-authority 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 SealHash

func SealHash(header *types.Header) (hash common.Hash)

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 the signer and epoch mechanisms of the proof-of-stake voting scheme.

func (*API) GetEpoch added in v0.2.0

func (api *API) GetEpoch(number *rpc.BlockNumber) ([]byte, error)

func (*API) GetSigner

func (api *API) GetSigner(rlpOrBlockNr *blockNumberOrHashOrRLP) (common.Address, error)

GetSigner returns the signer for a specific posv block. Can be called with either a blocknumber, blockhash or an rlp encoded blob. The RLP encoded blob can either be a block or a header.

func (*API) GetSigners

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

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

func (*API) GetSignersAtHash

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

GetSignersAtHash retrieves the list of authorized signers at the specified block.

type Epoch added in v0.2.0

type Epoch struct {
	Checkpoint uint64           `json:"checkpoint"`
	M1s        MasterNodes      `json:"m1s"` // max 99
	M2s        []common.Address `json:"m2s"` // max 150
	Reward     *big.Int         `json:"reward"`
	Penalties  []common.Address `json:"penalties"`
}

func (*Epoch) FromBytes added in v0.2.0

func (e *Epoch) FromBytes(b []byte) error

func (*Epoch) IsM1 added in v0.2.0

func (e *Epoch) IsM1(address common.Address) bool

func (*Epoch) IsM2 added in v0.2.1

func (e *Epoch) IsM2(address common.Address) bool

func (*Epoch) M1 added in v0.2.0

func (e *Epoch) M1(epochLength uint64, number uint64) common.Address

M1 return the block sealer in order

func (*Epoch) M1Index added in v0.2.0

func (e *Epoch) M1Index(signer common.Address) int

func (*Epoch) M1Length added in v0.2.0

func (e *Epoch) M1Length() int

func (*Epoch) M1NextTurn added in v0.2.2

func (e *Epoch) M1NextTurn(epochLength uint64, number uint64, m1 common.Address) uint64

M1NextTurn return the next block should be seal by m1

func (*Epoch) M1Slice added in v0.2.0

func (e *Epoch) M1Slice() []common.Address

func (*Epoch) M2 added in v0.2.0

func (e *Epoch) M2(epochLength uint64, number uint64) []common.Address

M2 return the block signers in order

func (*Epoch) M2Length added in v0.2.0

func (e *Epoch) M2Length() int

func (*Epoch) M2Slice added in v0.2.0

func (e *Epoch) M2Slice() []common.Address

func (*Epoch) String added in v0.2.0

func (e *Epoch) String() string

func (*Epoch) ToBytes added in v0.2.0

func (e *Epoch) ToBytes() []byte

type Extra added in v0.2.0

type Extra struct {
	Vanity    [extraVanity]byte `json:"vanity"`
	Epoch     Epoch             `json:"epoch"`
	Signature [extraSeal]byte   `json:"signature"`
}

func (*Extra) FromBytes added in v0.2.0

func (e *Extra) FromBytes(b []byte) error

func (*Extra) ToBytes added in v0.2.0

func (e *Extra) ToBytes() []byte

type MasterNode added in v0.2.0

type MasterNode struct {
	Address common.Address `json:"address"`
	Stake   *big.Int       `json:"stake"`
}

type MasterNodes added in v0.2.0

type MasterNodes []MasterNode

func (MasterNodes) Len added in v0.2.0

func (ms MasterNodes) Len() int

func (MasterNodes) Less added in v0.2.0

func (ms MasterNodes) Less(i, j int) bool

func (MasterNodes) Swap added in v0.2.0

func (ms MasterNodes) Swap(i, j int)

type PoSV

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

PoSV is the proof-of-authority consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.

func New

func New(config *params.PoSVConfig, db ethdb.Database) *PoSV

New creates a PoSV proof-of-authority consensus engine with the initial signers set to the ones provided by the user.

func (*PoSV) APIs

func (c *PoSV) APIs(chain consensus.ChainHeaderReader) []rpc.API

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

func (*PoSV) Author

func (c *PoSV) 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 (*PoSV) Authorize

func (c *PoSV) Authorize(signer common.Address, signFn SignerFn)

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

func (*PoSV) CalcDifficulty

func (c *PoSV) 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: * DIFF_NOTURN(2) if BLOCK_NUMBER % SIGNER_COUNT != SIGNER_INDEX * DIFF_INTURN(1) if BLOCK_NUMBER % SIGNER_COUNT == SIGNER_INDEX

func (*PoSV) Close

func (c *PoSV) Close() error

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

func (*PoSV) Config added in v0.2.0

func (c *PoSV) Config() *params.PoSVConfig

func (*PoSV) Finalize

func (c *PoSV) Finalize(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header)

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

func (*PoSV) FinalizeAndAssemble

func (c *PoSV) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

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

func (*PoSV) GetEpoch added in v0.2.0

func (c *PoSV) GetEpoch(chain consensus.ChainHeaderReader, checkpoint uint64) (*Epoch, error)

GetEpoch return the epoch data at checkpoint header,the param checkpoint must be checkpoint number

func (*PoSV) HookBlockSign added in v0.2.0

func (c *PoSV) HookBlockSign(signer common.Address, toSign, current *types.Header) error

func (*PoSV) HookGetBlockSigners added in v0.2.0

func (c *PoSV) HookGetBlockSigners(chain consensus.ChainHeaderReader, stateBlock *state.StateDB, header *types.Header) (map[common.Address]int, error)

func (*PoSV) HookGetCandidates added in v0.2.6

func (c *PoSV) HookGetCandidates(state *state.StateDB) MasterNodes

HookGetCandidates Read the candidate list and candidate votes from the contract, sort and return according to the rules; sorting rules: the one with the larger votes is first, and the candidate with the smaller address is the first when the votes are the same

func (*PoSV) HookPenalty added in v0.2.0

func (c *PoSV) HookPenalty(chain consensus.ChainHeaderReader, number uint64) ([]common.Address, error)

func (*PoSV) HookRandomizeSigners added in v0.2.2

func (c *PoSV) HookRandomizeSigners(statedb *state.StateDB, masternodes []common.Address) ([]common.Address, error)

func (*PoSV) HookReward added in v0.2.0

func (c *PoSV) HookReward(chain consensus.ChainHeaderReader, stateBlock *state.StateDB, header *types.Header, nextEpoch *Epoch) (map[string]interface{}, error)

func (*PoSV) HookSetRandomizeOpening added in v0.2.0

func (c *PoSV) HookSetRandomizeOpening(signer common.Address, header *types.Header) error

func (*PoSV) HookSetRandomizeSecret added in v0.2.0

func (c *PoSV) HookSetRandomizeSecret(signer common.Address, header *types.Header) error

func (*PoSV) LastCheckpoint added in v0.2.6

func (c *PoSV) LastCheckpoint(currentNumber uint64) uint64

LastCheckpoint return the epoch checkpoint number

func (*PoSV) Prepare

func (c *PoSV) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error

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

func (*PoSV) Seal

func (c *PoSV) 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 (*PoSV) SealHash

func (c *PoSV) SealHash(header *types.Header) common.Hash

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

func (*PoSV) SetAccountManager added in v0.2.6

func (c *PoSV) SetAccountManager(acm *accounts.Manager)

func (*PoSV) SetChainID added in v0.2.6

func (c *PoSV) SetChainID(chainID *big.Int)

func (*PoSV) SetTxPool added in v0.2.6

func (c *PoSV) SetTxPool(txPool *core.TxPool)

func (*PoSV) VerifyHeader

func (c *PoSV) VerifyHeader(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*PoSV) VerifyHeaders

func (c *PoSV) VerifyHeaders(chain consensus.ChainHeaderReader, 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 (*PoSV) VerifyUncles

func (c *PoSV) 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(signer accounts.Account, mimeType string, message []byte) ([]byte, error)

SignerFn hashes and signs the data to be signed by a backing account.

Jump to

Keyboard shortcuts

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