posv

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: GPL-3.0 Imports: 29 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 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

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

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) NextTurn added in v0.2.0

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

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 {
	HookGetMasterNodes      func(number *big.Int) (MasterNodes, error)
	HookValidator           func(number *big.Int, masters []common.Address) ([]common.Address, error)
	HookPenalty             func(chain consensus.ChainHeaderReader, header *types.Header) ([]common.Address, error)
	HookReward              func(chain consensus.ChainHeaderReader, state *state.StateDB, header *types.Header) (map[string]interface{}, error)
	HookGetBlockSigners     func(chain consensus.ChainHeaderReader, stateBlock *state.StateDB, header *types.Header) (map[common.Address]int, error)
	HookBlockSign           func(signer common.Address, toSign, current *types.Header) error
	HookSetRandomizeSecret  func(signer common.Address, header *types.Header) error
	HookSetRandomizeOpening func(signer common.Address, header *types.Header) error
	// 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, epoch uint64) (*Epoch, error)

func (*PoSV) LastEpoch added in v0.2.0

func (c *PoSV) LastEpoch(number uint64) uint64

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) SetEpoch added in v0.2.0

func (c *PoSV) SetEpoch(epoch uint64, extra *Extra)

func (*PoSV) SetIPCEndpoint added in v0.2.0

func (c *PoSV) SetIPCEndpoint(endpoint string)

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