backend

package
v24.4.4 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NewBlockMsg = 0x07
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API is a user facing RPC API to dump Istanbul state

func (*API) Candidates

func (api *API) Candidates() map[common.Address]bool

Candidates returns the current candidates the node tries to uphold and vote on.

func (*API) Discard

func (api *API) Discard(address common.Address)

Discard drops a currently running candidate, stopping the validator from casting further votes (either for or against).

func (*API) GetSignersFromBlock

func (api *API) GetSignersFromBlock(number *rpc.BlockNumber) (*BlockSigners, error)

GetSignersFromBlock returns the signers and minter for a given block number, or the latest block available if none is specified

func (*API) GetSignersFromBlockByHash

func (api *API) GetSignersFromBlockByHash(hash common.Hash) (*BlockSigners, error)

GetSignersFromBlockByHash returns the signers and minter for a given block hash

func (*API) GetSnapshot

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

func (*API) GetValidators

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

GetValidators retrieves the list of authorized validators at the specified block.

func (*API) GetValidatorsAtHash

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

GetValidatorsAtHash retrieves the state snapshot at a given block.

func (*API) IsValidator

func (api *API) IsValidator(blockNum *rpc.BlockNumber) (bool, error)

func (*API) NodeAddress

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

NodeAddress returns the public address that is used to sign block headers in IBFT

func (*API) Propose

func (api *API) Propose(address common.Address, auth bool)

Propose injects a new authorization candidate that the validator will attempt to push through.

func (*API) Status

func (api *API) Status(startBlockNum *rpc.BlockNumber, endBlockNum *rpc.BlockNumber) (*Status, error)

type Backend

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

func New

func New(config *istanbul.Config, privateKey *ecdsa.PrivateKey, db ethdb.Database) *Backend

New creates an Ethereum backend for Istanbul core engine.

func (*Backend) APIs

func (sb *Backend) APIs(chain consensus.ChainHeaderReader) []rpc.API

APIs returns the RPC APIs this consensus engine provides.

func (*Backend) Address

func (sb *Backend) Address() common.Address

Address implements istanbul.Backend.Address

func (*Backend) Author

func (sb *Backend) Author(header *types.Header) (common.Address, error)

Author retrieves the Ethereum address of the account that minted the given block, which may be different from the header's coinbase if a consensus engine is based on signatures.

func (*Backend) Broadcast

func (sb *Backend) Broadcast(valSet istanbul.ValidatorSet, code uint64, payload []byte) error

Broadcast implements istanbul.Backend.Broadcast

func (*Backend) CalcDifficulty

func (sb *Backend) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int

zekun: HACK

func (*Backend) CheckSignature

func (sb *Backend) CheckSignature(data []byte, address common.Address, sig []byte) error

CheckSignature implements istanbul.Backend.CheckSignature

func (*Backend) Close

func (sb *Backend) Close() error

func (*Backend) Commit

func (sb *Backend) Commit(proposal istanbul.Proposal, seals [][]byte, round *big.Int) (err error)

Commit implements istanbul.Backend.Commit

func (*Backend) Engine

func (sb *Backend) Engine() istanbul.Engine

func (*Backend) EngineForBlockNumber

func (sb *Backend) EngineForBlockNumber(blockNumber *big.Int) istanbul.Engine

func (*Backend) EventMux

func (sb *Backend) EventMux() *event.TypeMux

EventMux implements istanbul.Backend.EventMux

func (*Backend) Finalize

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

Finalize runs any post-transaction state modifications (e.g. block rewards) and assembles the final block.

Note, the block header and state database might be updated to reflect any consensus rules that happen at finalization (e.g. block rewards).

func (*Backend) FinalizeAndAssemble

func (sb *Backend) 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 (*Backend) GetProposer

func (sb *Backend) GetProposer(number uint64) common.Address

GetProposer implements istanbul.Backend.GetProposer

func (*Backend) Gossip

func (sb *Backend) Gossip(valSet istanbul.ValidatorSet, code uint64, payload []byte) error

Gossip implements istanbul.Backend.Gossip

func (*Backend) HandleMsg

func (sb *Backend) HandleMsg(addr common.Address, msg p2p.Msg) (bool, error)

HandleMsg implements consensus.Handler.HandleMsg

func (*Backend) HasBadProposal

func (sb *Backend) HasBadProposal(hash common.Hash) bool

func (*Backend) HasPropsal

func (sb *Backend) HasPropsal(hash common.Hash, number *big.Int) bool

HasPropsal implements istanbul.Backend.HashBlock

func (*Backend) IsQBFTConsensus

func (sb *Backend) IsQBFTConsensus() bool

IsQBFTConsensus returns whether qbft consensus should be used

func (*Backend) IsQBFTConsensusAt

func (sb *Backend) IsQBFTConsensusAt(blockNumber *big.Int) bool

IsQBFTConsensusForHeader checks if qbft consensus is enabled for the block height identified by the given header

func (*Backend) LastProposal

func (sb *Backend) LastProposal() (istanbul.Proposal, common.Address)

func (*Backend) NewChainHead

func (sb *Backend) NewChainHead() error

func (*Backend) ParentValidators

func (sb *Backend) ParentValidators(proposal istanbul.Proposal) istanbul.ValidatorSet

ParentValidators implements istanbul.Backend.GetParentValidators

func (*Backend) Prepare

func (sb *Backend) Prepare(chain consensus.ChainHeaderReader, header *types.Header) error

Prepare initializes the consensus fields of a block header according to the rules of a particular engine. The changes are executed inline.

func (*Backend) Protocol

func (sb *Backend) Protocol() consensus.Protocol

Protocol implements consensus.Engine.Protocol

func (*Backend) Seal

func (sb *Backend) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error

Seal generates a new block for the given input block with the local miner's seal place on top.

func (*Backend) SealHash

func (sb *Backend) SealHash(header *types.Header) common.Hash

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

func (*Backend) SetBroadcaster

func (sb *Backend) SetBroadcaster(broadcaster consensus.Broadcaster)

SetBroadcaster implements consensus.Handler.SetBroadcaster

func (*Backend) Sign

func (sb *Backend) Sign(data []byte) ([]byte, error)

Sign implements istanbul.Backend.Sign

func (*Backend) SignWithoutHashing

func (sb *Backend) SignWithoutHashing(data []byte) ([]byte, error)

SignWithoutHashing implements istanbul.Backend.SignWithoutHashing and signs input data with the backend's private key without hashing the input data

func (*Backend) Signers

func (sb *Backend) Signers(header *types.Header) ([]common.Address, error)

Signers extracts all the addresses who have signed the given header It will extract for each seal who signed it, regardless of if the seal is repeated

func (*Backend) Start

func (sb *Backend) Start(chain consensus.ChainHeaderReader, currentBlock func() *types.Block, hasBadBlock func(db ethdb.Reader, hash common.Hash) bool) error

Start implements consensus.Istanbul.Start

func (*Backend) StartQBFTConsensus

func (sb *Backend) StartQBFTConsensus() error

StartQBFTConsensus stops existing legacy ibft consensus and starts the new qbft consensus

func (*Backend) Stop

func (sb *Backend) Stop() error

Stop implements consensus.Istanbul.Stop

func (*Backend) Validators

func (sb *Backend) Validators(proposal istanbul.Proposal) istanbul.ValidatorSet

Validators implements istanbul.Backend.Validators

func (*Backend) Verify

func (sb *Backend) Verify(proposal istanbul.Proposal) (time.Duration, error)

Verify implements istanbul.Backend.Verify

func (*Backend) VerifyHeader

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

VerifyHeader checks whether a header conforms to the consensus rules of a given engine. Verifying the seal may be done optionally here, or explicitly via the VerifySeal method.

func (*Backend) VerifyHeaders

func (sb *Backend) VerifyHeaders(chain consensus.ChainHeaderReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error)

VerifyHeaders is similar to VerifyHeader, but verifies a batch of headers concurrently. 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 (*Backend) VerifySeal

func (sb *Backend) VerifySeal(chain consensus.ChainHeaderReader, header *types.Header) error

VerifySeal checks whether the crypto seal on a header is valid according to the consensus rules of the given engine.

func (*Backend) VerifyUncles

func (sb *Backend) VerifyUncles(chain consensus.ChainReader, block *types.Block) error

VerifyUncles verifies that the given block's uncles conform to the consensus rules of a given engine.

type BlockSigners

type BlockSigners struct {
	Number     uint64
	Hash       common.Hash
	Author     common.Address
	Committers []common.Address
}

BlockSigners is contains who created and who signed a particular block, denoted by its number and hash

type Snapshot

type Snapshot struct {
	Epoch uint64 // The number of blocks after which to checkpoint and reset the pending votes

	Number uint64                   // Block number where the snapshot was created
	Hash   common.Hash              // Block hash where the snapshot was created
	Votes  []*Vote                  // List of votes cast in chronological order
	Tally  map[common.Address]Tally // Current vote tally to avoid recalculating
	ValSet istanbul.ValidatorSet    // Set of authorized validators at this moment
}

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

func (*Snapshot) MarshalJSON

func (s *Snapshot) MarshalJSON() ([]byte, error)

Marshal to a json byte array

func (*Snapshot) UnmarshalJSON

func (s *Snapshot) UnmarshalJSON(b []byte) error

Unmarshal from a json byte array

type Status

type Status struct {
	SigningStatus map[common.Address]int `json:"sealerActivity"`
	NumBlocks     uint64                 `json:"numBlocks"`
}

type Tally

type Tally struct {
	Authorize bool `json:"authorize"` // Whether the vote it about authorizing or kicking someone
	Votes     int  `json:"votes"`     // Number of votes until now wanting to pass the proposal
}

Tally is a simple vote tally to keep the current score of votes. Votes that go against the proposal aren't counted since it's equivalent to not voting.

type Vote

type Vote struct {
	Validator common.Address `json:"validator"` // Authorized validator that cast this vote
	Block     uint64         `json:"block"`     // Block number the vote was cast in (expire old votes)
	Address   common.Address `json:"address"`   // Account being voted on to change its authorization
	Authorize bool           `json:"authorize"` // Whether to authorize or deauthorize the voted account
}

Vote represents a single vote that an authorized validator made to modify the list of authorizations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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