engine_v2

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: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUM_OF_FORENSICS_QC = 3
)

Variables

This section is empty.

Functions

func GetVoteSignerAddresses

func GetVoteSignerAddresses(vote *types.Vote) (common.Address, error)

func UniqueSignatures

func UniqueSignatures(signatureSlice []types.Signature) ([]types.Signature, []types.Signature)

Types

type Forensics

type Forensics struct {
	HighestCommittedQCs []types.QuorumCert
	// contains filtered or unexported fields
}

Forensics instance. Placeholder for future properties to be added

func NewForensics

func NewForensics() *Forensics

Initiate a forensics process

func (*Forensics) DetectEquivocationInVotePool

func (f *Forensics) DetectEquivocationInVotePool(vote *types.Vote, votePool *utils.Pool)

func (*Forensics) FindAncestorBlockHash

func (f *Forensics) FindAncestorBlockHash(chain consensus.ChainReader, firstBlockInfo *types.BlockInfo, secondBlockInfo *types.BlockInfo) (common.Hash, []string, []string, error)

func (*Forensics) ForensicsMonitoring

func (f *Forensics) ForensicsMonitoring(chain consensus.ChainReader, engine *XDPoS_v2, headerQcToBeCommitted []types.Header, incomingQC types.QuorumCert) error

func (*Forensics) ProcessForensics

func (f *Forensics) ProcessForensics(chain consensus.ChainReader, engine *XDPoS_v2, incomingQC types.QuorumCert) error

Entry point for processing forensics. Triggered once processQC is successfully. Forensics runs in a seperate go routine as its no system critical Link to the flow diagram: https://hashlabs.atlassian.net/wiki/spaces/HASHLABS/pages/97878029/Forensics+Diagram+flow

func (*Forensics) ProcessVoteEquivocation

func (f *Forensics) ProcessVoteEquivocation(chain consensus.ChainReader, engine *XDPoS_v2, incomingVote *types.Vote) error

Entry point for processing vote equivocation. Triggered once handle vote is successfully. Forensics runs in a seperate go routine as its no system critical Link to the flow diagram: https://hashlabs.atlassian.net/wiki/spaces/HASHLABS/pages/99516417/Vote+Equivocation+detection+specification

func (*Forensics) SendForensicProof

func (f *Forensics) SendForensicProof(chain consensus.ChainReader, engine *XDPoS_v2, firstQc types.QuorumCert, secondQc types.QuorumCert) error

Last step of forensics which sends out detailed proof to report service.

func (*Forensics) SendVoteEquivocationProof

func (f *Forensics) SendVoteEquivocationProof(vote1, vote2 *types.Vote, signer common.Address) error

func (*Forensics) SetCommittedQCs

func (f *Forensics) SetCommittedQCs(headers []types.Header, incomingQC types.QuorumCert) error

Set the forensics committed QCs list. The order is from grandparent to current header. i.e it shall follow the QC in its header as follow [hcqc1, hcqc2, hcqc3]

func (*Forensics) SubscribeForensicsEvent

func (f *Forensics) SubscribeForensicsEvent(ch chan<- types.ForensicsEvent) event.Subscription

SubscribeForensicsEvent registers a subscription of ForensicsEvent and starts sending event to the given channel.

type SnapshotV2

type SnapshotV2 struct {
	Number uint64      `json:"number"` // Block number where the snapshot was created
	Hash   common.Hash `json:"hash"`   // Block hash where the snapshot was created

	// MasterNodes will get assigned on updateM1
	NextEpochMasterNodes []common.Address `json:"masterNodes"` // Set of authorized master nodes at this moment for next epoch
}

Snapshot is the state of the smart contract validator list The validator list is used on next epoch master nodes If we don't have the snapshot, then we have to trace back the gap block smart contract state which is very costly

func (*SnapshotV2) GetMappedMasterNodes

func (s *SnapshotV2) GetMappedMasterNodes() map[common.Address]struct{}

retrieves master nodes list in map type

func (*SnapshotV2) IsMasterNodes

func (s *SnapshotV2) IsMasterNodes(address common.Address) bool

type XDPoS_v2

type XDPoS_v2 struct {
	BroadcastCh chan interface{}

	HookReward  func(chain consensus.ChainReader, state *state.StateDB, parentState *state.StateDB, header *types.Header) (map[string]interface{}, error)
	HookPenalty func(chain consensus.ChainReader, number *big.Int, parentHash common.Hash, candidates []common.Address) ([]common.Address, error)

	ForensicsProcessor *Forensics
	// contains filtered or unexported fields
}

func New

func New(chainConfig *params.ChainConfig, db ethdb.Database, minePeriodCh chan int) *XDPoS_v2

func (*XDPoS_v2) Author

func (x *XDPoS_v2) Author(header *types.Header) (common.Address, error)

func (*XDPoS_v2) Authorize

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

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

func (*XDPoS_v2) AuthorizeFaker

func (x *XDPoS_v2) AuthorizeFaker(signer common.Address)

Fake the signer address, the signing function is incompatible

func (*XDPoS_v2) CalcDifficulty

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

func (x *XDPoS_v2) 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_v2) FindParentBlockToAssign

func (x *XDPoS_v2) FindParentBlockToAssign(chain consensus.ChainReader) *types.Block

func (*XDPoS_v2) GetCurrentEpochSwitchBlock

func (x *XDPoS_v2) GetCurrentEpochSwitchBlock(chain consensus.ChainReader, blockNum *big.Int) (uint64, uint64, error)

func (*XDPoS_v2) GetCurrentRoundFaker

func (x *XDPoS_v2) GetCurrentRoundFaker() types.Round

Utils for test to check currentRound value

func (*XDPoS_v2) GetForensicsFaker

func (x *XDPoS_v2) GetForensicsFaker() *Forensics

func (*XDPoS_v2) GetLatestCommittedBlockInfo

func (x *XDPoS_v2) GetLatestCommittedBlockInfo() *types.BlockInfo

func (*XDPoS_v2) GetMasternodes

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

Given header, get master node from the epoch switch block of that epoch

func (*XDPoS_v2) GetMasternodesByHash

func (x *XDPoS_v2) GetMasternodesByHash(chain consensus.ChainReader, hash common.Hash) []common.Address

Given hash, get master node from the epoch switch block of the epoch

func (*XDPoS_v2) GetMasternodesFromEpochSwitchHeader

func (x *XDPoS_v2) GetMasternodesFromEpochSwitchHeader(epochSwitchHeader *types.Header) []common.Address

Get master nodes over extra data of epoch switch block.

func (*XDPoS_v2) GetPenalties

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

Given header, get master node from the epoch switch block of that epoch

func (*XDPoS_v2) GetPreviousPenaltyByHash

func (x *XDPoS_v2) GetPreviousPenaltyByHash(chain consensus.ChainReader, hash common.Hash, limit int) []common.Address

Given hash, get master node from the epoch switch block of the previous `limit` epoch

func (*XDPoS_v2) GetPropertiesFaker

WARN: This function is designed for testing purpose only! Utils for test to check currentRound values

func (*XDPoS_v2) GetRoundNumber

func (x *XDPoS_v2) GetRoundNumber(header *types.Header) (types.Round, error)

func (*XDPoS_v2) GetSignersFromSnapshot added in v1.4.8

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

func (*XDPoS_v2) GetSnapshot

func (x *XDPoS_v2) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*SnapshotV2, error)

func (*XDPoS_v2) GetStandbynodes

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

func (*XDPoS_v2) GetTimeoutPoolKeyListFaker

func (x *XDPoS_v2) GetTimeoutPoolKeyListFaker() []string

func (*XDPoS_v2) GetTimeoutPoolSizeFaker

func (x *XDPoS_v2) GetTimeoutPoolSizeFaker(timeout *types.Timeout) int

Utils for test to get Timeout Pool Size

func (*XDPoS_v2) GetVotePoolKeyListFaker

func (x *XDPoS_v2) GetVotePoolKeyListFaker() []string

func (*XDPoS_v2) GetVotePoolSizeFaker

func (x *XDPoS_v2) GetVotePoolSizeFaker(vote *types.Vote) int

Utils for test to get current Pool size

func (*XDPoS_v2) HygieneTimeoutPoolFaker

func (x *XDPoS_v2) HygieneTimeoutPoolFaker()

func (*XDPoS_v2) HygieneVotePoolFaker

func (x *XDPoS_v2) HygieneVotePoolFaker()

func (*XDPoS_v2) Initial

func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header) error

Initial V2 related parameters

func (*XDPoS_v2) IsAuthorisedAddress

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

func (*XDPoS_v2) IsEpochSwitch

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

func (*XDPoS_v2) OnCountdownTimeout

func (x *XDPoS_v2) OnCountdownTimeout(time time.Time, chain interface{}) error

Function that will be called by timer when countdown reaches its threshold. In the engine v2, we would need to broadcast timeout messages to other peers

func (*XDPoS_v2) Prepare

func (x *XDPoS_v2) 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_v2) ProcessQCFaker

func (x *XDPoS_v2) ProcessQCFaker(chain consensus.ChainReader, qc *types.QuorumCert) error

for test only

func (*XDPoS_v2) ProposedBlockHandler

func (x *XDPoS_v2) ProposedBlockHandler(chain consensus.ChainReader, blockHeader *types.Header) error

Proposed Block workflow

func (*XDPoS_v2) ReceivedTimeouts

func (x *XDPoS_v2) ReceivedTimeouts() map[string]map[common.Hash]utils.PoolObj

func (*XDPoS_v2) ReceivedVotes

func (x *XDPoS_v2) ReceivedVotes() map[string]map[common.Hash]utils.PoolObj

func (*XDPoS_v2) Seal

func (x *XDPoS_v2) 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_v2) SetNewRoundFaker

func (x *XDPoS_v2) SetNewRoundFaker(blockChainReader consensus.ChainReader, newRound types.Round, resetTimer bool)

func (*XDPoS_v2) SetPropertiesFaker

func (x *XDPoS_v2) SetPropertiesFaker(highestQC *types.QuorumCert, highestTC *types.TimeoutCert)

WARN: This function is designed for testing purpose only! Utils for tests to set engine specific values

func (*XDPoS_v2) SignHash

func (x *XDPoS_v2) SignHash(header *types.Header) (hash common.Hash)
V2 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.

func (*XDPoS_v2) SyncInfoHandler

func (x *XDPoS_v2) SyncInfoHandler(chain consensus.ChainReader, syncInfo *types.SyncInfo) error

func (*XDPoS_v2) TimeoutHandler

func (x *XDPoS_v2) TimeoutHandler(blockChainReader consensus.ChainReader, timeout *types.Timeout) error

Entry point for handling timeout message to process below:

func (*XDPoS_v2) UpdateMasternodes

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

func (*XDPoS_v2) UpdateParams

func (x *XDPoS_v2) UpdateParams(header *types.Header)

func (*XDPoS_v2) VerifyBlockInfo

func (x *XDPoS_v2) VerifyBlockInfo(blockChainReader consensus.ChainReader, blockInfo *types.BlockInfo, blockHeader *types.Header) error

To be used by different message verification. Verify local DB block info against the received block information(i.e hash, blockNum, round)

func (*XDPoS_v2) VerifyHeader

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

func (*XDPoS_v2) VerifyHeaders

func (x *XDPoS_v2) VerifyHeaders(chain consensus.ChainReader, headers []*types.Header, fullVerifies []bool, abort <-chan struct{}, results chan<- error)

Verify a list of headers

func (*XDPoS_v2) VerifySyncInfoMessage

func (x *XDPoS_v2) VerifySyncInfoMessage(chain consensus.ChainReader, syncInfo *types.SyncInfo) (bool, error)
SyncInfo workflow

Verify syncInfo and trigger process QC or TC if successful

func (*XDPoS_v2) VerifyTimeoutMessage

func (x *XDPoS_v2) VerifyTimeoutMessage(chain consensus.ChainReader, timeoutMsg *types.Timeout) (bool, error)
Timeout workflow

Verify timeout message type from peers in bft.go

  1. Get master node list by timeout msg round
  2. Check signature: - Use ecRecover to get the public key - Use the above public key to find out the xdc address - Use the above xdc address to check against the master node list from step 1(For the running epoch)
  3. Broadcast(Not part of consensus)

func (*XDPoS_v2) VerifyVoteMessage

func (x *XDPoS_v2) VerifyVoteMessage(chain consensus.ChainReader, vote *types.Vote) (bool, error)

Vote workflow

func (*XDPoS_v2) VoteHandler

func (x *XDPoS_v2) VoteHandler(chain consensus.ChainReader, voteMsg *types.Vote) error

Consensus entry point for processing vote message to produce QC

func (*XDPoS_v2) YourTurn

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

Check if it's my turn to mine a block. Note: The second return value `preIndex` is useless in V2 engine

Jump to

Keyboard shortcuts

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