engine_v1

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SnapshotV1

type SnapshotV1 struct {
	Number  uint64                          `json:"number"`  // Block number where the snapshot was created
	Hash    common.Hash                     `json:"hash"`    // Block hash where the snapshot was created
	Signers map[common.Address]struct{}     `json:"signers"` // Set of authorized signers at this moment
	Recents map[uint64]common.Address       `json:"recents"` // Set of recent signers for spam protections
	Votes   []*clique.Vote                  `json:"votes"`   // List of votes cast in chronological order
	Tally   map[common.Address]clique.Tally `json:"tally"`   // Current vote tally to avoid recalculating
	// contains filtered or unexported fields
}

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

func (*SnapshotV1) GetSigners

func (s *SnapshotV1) GetSigners() []common.Address

signers retrieves the list of authorized signers in ascending order.

type XDPoS_v1

type XDPoS_v1 struct {
	HookReward            func(chain consensus.ChainReader, state *state.StateDB, parentState *state.StateDB, header *types.Header) (error, map[string]interface{})
	HookPenalty           func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error)
	HookPenaltyTIPSigning func(chain consensus.ChainReader, header *types.Header, candidate []common.Address) ([]common.Address, error)
	HookValidator         func(header *types.Header, signers []common.Address) ([]byte, error)
	HookVerifyMNs         func(header *types.Header, signers []common.Address) error

	HookGetSignersFromContract func(blockHash common.Hash) ([]common.Address, error)
	// contains filtered or unexported fields
}

XDPoS is the delegated-proof-of-stake consensus engine proposed to support the Ethereum testnet following the Ropsten attacks.

func New

func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS_v1

New creates a XDPoS delegated-proof-of-stake consensus engine with the initial signers set to the ones provided by the user.

func NewFaker

func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS_v1

func (*XDPoS_v1) Author

func (x *XDPoS_v1) 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 (*XDPoS_v1) Authorize

func (x *XDPoS_v1) Authorize(signer common.Address, signFn clique.SignerFn)

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

func (*XDPoS_v1) CalcDifficulty

func (x *XDPoS_v1) 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 (*XDPoS_v1) Finalize

func (x *XDPoS_v1) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, parentState *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error)

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

func (*XDPoS_v1) GetAuthorisedSignersFromSnapshot

func (x *XDPoS_v1) GetAuthorisedSignersFromSnapshot(chain consensus.ChainReader, header *types.Header) ([]common.Address, error)

func (*XDPoS_v1) GetCurrentEpochSwitchBlock

func (x *XDPoS_v1) GetCurrentEpochSwitchBlock(blockNumber *big.Int) (uint64, uint64, error)

func (*XDPoS_v1) GetDb

func (x *XDPoS_v1) GetDb() ethdb.Database

func (*XDPoS_v1) GetMasternodes

func (x *XDPoS_v1) GetMasternodes(chain consensus.ChainReader, header *types.Header) []common.Address

func (*XDPoS_v1) GetMasternodesFromCheckpointHeader

func (x *XDPoS_v1) GetMasternodesFromCheckpointHeader(checkpointHeader *types.Header) []common.Address

Get master nodes over extra data of checkpoint block.

func (*XDPoS_v1) GetPeriod

func (x *XDPoS_v1) GetPeriod() uint64

func (*XDPoS_v1) GetSnapshot

func (x *XDPoS_v1) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*SnapshotV1, error)

func (*XDPoS_v1) GetValidator

func (x *XDPoS_v1) GetValidator(creator common.Address, chain consensus.ChainReader, header *types.Header) (common.Address, error)

func (*XDPoS_v1) IsAuthorisedAddress

func (x *XDPoS_v1) IsAuthorisedAddress(chain consensus.ChainReader, header *types.Header, address common.Address) bool

func (*XDPoS_v1) IsEpochSwitch

func (x *XDPoS_v1) IsEpochSwitch(header *types.Header) (bool, uint64, error)

Epoch Switch is also known as checkpoint in v1

func (*XDPoS_v1) Prepare

func (x *XDPoS_v1) 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 (*XDPoS_v1) RecoverSigner

func (x *XDPoS_v1) RecoverSigner(header *types.Header) (common.Address, error)

func (*XDPoS_v1) RecoverValidator

func (x *XDPoS_v1) RecoverValidator(header *types.Header) (common.Address, error)

func (*XDPoS_v1) Seal

func (x *XDPoS_v1) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan struct{}) (*types.Block, error)

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

func (*XDPoS_v1) SigHash

func (x *XDPoS_v1) SigHash(header *types.Header) (hash common.Hash)
V1 Block

SignerFn is a signer callback function to request a hash to be signed by a backing account. type SignerFn func(accounts.Account, []byte) ([]byte, error)

sigHash returns the hash which is used as input for the delegated-proof-of-stake signing. It is the hash 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 (*XDPoS_v1) StoreSnapshot

func (x *XDPoS_v1) StoreSnapshot(snap *SnapshotV1) error

func (*XDPoS_v1) UpdateMasternodes

func (x *XDPoS_v1) UpdateMasternodes(chain consensus.ChainReader, header *types.Header, ms []utils.Masternode) error

Update masternodes into snapshot. In V1, truncating ms[:MaxMasternodes] is done in this function.

func (*XDPoS_v1) VerifyHeader

func (x *XDPoS_v1) VerifyHeader(chain consensus.ChainReader, header *types.Header, fullVerify bool) error

VerifyHeader checks whether a header conforms to the consensus rules.

func (*XDPoS_v1) VerifyHeaders

func (x *XDPoS_v1) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, fullVerifies []bool, abort <-chan struct{}, results 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 (*XDPoS_v1) VerifySeal

func (x *XDPoS_v1) 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 (*XDPoS_v1) VerifyUncles

func (x *XDPoS_v1) 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.

func (*XDPoS_v1) YourTurn

func (x *XDPoS_v1) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (bool, error)

Jump to

Keyboard shortcuts

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