backend

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2021 License: GPL-3.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TestBackendFactory backendtest.TestBackendFactory = testBackendFactoryImpl{}

TestBackendFactory can be passed to backendtest.InitTestBackendFactory

Functions

func AppendValidatorsToGenesisBlock

func AppendValidatorsToGenesisBlock(genesis *core.Genesis, validators []istanbul.ValidatorData)

func DecryptFn

func DecryptFn(key *ecdsa.PrivateKey) istanbul.DecryptFn

func New

New creates an Ethereum backend for Istanbul core engine.

func SignBLSFn

func SignBLSFn(key *ecdsa.PrivateKey) istanbul.BLSSignerFn

func SignFn

func SignFn(key *ecdsa.PrivateKey) istanbul.SignerFn

func SignHashFn

func SignHashFn(key *ecdsa.PrivateKey) istanbul.HashSignerFn

Types

type API

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

API is a user facing RPC API to dump Istanbul state

func (*API) AddProxy

func (api *API) AddProxy(url, externalUrl string) (bool, error)

AddProxy peers with a remote node that acts as a proxy, even if slots are full

func (*API) ForceRoundChange

func (api *API) ForceRoundChange() (bool, error)

GetCurrentRoundState retrieves the current IBFT RoundState

func (*API) GetCurrentReplicaState

func (api *API) GetCurrentReplicaState() (*replica.ReplicaStateSummary, error)

GetCurrentReplicaState retrieves the current replica state

func (*API) GetCurrentRoundState

func (api *API) GetCurrentRoundState() (*core.RoundStateSummary, error)

GetCurrentRoundState retrieves the current IBFT RoundState

func (*API) GetLookbackWindow

func (api *API) GetLookbackWindow(number *rpc.BlockNumber) (uint64, error)

GetLookbackWindow retrieves the current replica state

func (*API) GetProposer

func (api *API) GetProposer(sequence *rpc.BlockNumber, round *uint64) (common.Address, error)

GetProposer retrieves the proposer for a given block number (i.e. sequence) and round.

func (*API) GetProxiedValidators

func (api *API) GetProxiedValidators() ([]*proxy.ProxiedValidatorInfo, error)

ProxiedValidators retrieves all of the proxies connected proxied validators. Note that we plan to support validators per proxy in the future, so this function is plural and returns an array of proxied validators. This is to prevent future backwards compatibility issues.

func (*API) GetProxiesInfo

func (api *API) GetProxiesInfo() ([]*proxy.ProxyInfo, error)

Proxies retrieves all the proxied validator's proxies' info

func (*API) GetSnapshot

func (api *API) GetSnapshot(number *rpc.BlockNumber) (*Snapshot, error)

GetSnapshot retrieves the state snapshot at a given block.

func (*API) GetValEnodeTable

func (api *API) GetValEnodeTable() (map[string]*vet.ValEnodeEntryInfo, error)

Retrieve the Validator Enode Table

func (*API) GetValidators

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

GetValidators retrieves the list validators that must sign a given block.

func (*API) GetValidatorsBLSPublicKeys

func (api *API) GetValidatorsBLSPublicKeys(number *rpc.BlockNumber) ([]blscrypto.SerializedPublicKey, error)

GetValidatorsBLSPublicKeys retrieves the list of validators BLS public keys that must sign a given block.

func (*API) GetVersionCertificateTableInfo

func (api *API) GetVersionCertificateTableInfo() (map[string]*vet.VersionCertificateEntryInfo, error)

func (*API) IsValidating

func (api *API) IsValidating() bool

IsValidating returns true if this node is participating in the consensus protocol

func (*API) RemoveProxy

func (api *API) RemoveProxy(url string) (bool, error)

RemoveProxy removes a node from acting as a proxy

func (*API) StartValidating

func (api *API) StartValidating() error

StartValidating starts the consensus engine

func (*API) StartValidatingAtBlock

func (api *API) StartValidatingAtBlock(blockNumber int64) error

StartValidatingAtBlock starts the consensus engine on the given block number.

func (*API) StopValidating

func (api *API) StopValidating() error

StopValidating stops the consensus engine from participating in consensus

func (*API) StopValidatingAtBlock

func (api *API) StopValidatingAtBlock(blockNumber int64) error

StopValidatingAtBlock stops the consensus engine from participating in consensus on the given block number.

type Backend

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

func (*Backend) APIs

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

APIs returns the RPC APIs this consensus engine provides.

func (*Backend) AddPeer

func (sb *Backend) AddPeer(node *enode.Node, purpose p2p.PurposeFlag)

func (*Backend) AddProxy

func (sb *Backend) AddProxy(node, externalNode *enode.Node) error

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

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

AuthorForBlock returns the address of the block offer from a given number.

func (*Backend) Authorize

func (sb *Backend) Authorize(ecdsaAddress, blsAddress common.Address, publicKey *ecdsa.PublicKey, decryptFn istanbul.DecryptFn, signFn istanbul.SignerFn, signBLSFn istanbul.BLSSignerFn, signHashFn istanbul.HashSignerFn)

Authorize implements istanbul.Backend.Authorize

func (*Backend) ChainConfig

func (sb *Backend) ChainConfig() *params.ChainConfig

ChainConfig returns the configuration from the embedded blockchain reader.

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

Close the backend

func (*Backend) Commit

func (sb *Backend) Commit(proposal istanbul.Proposal, aggregatedSeal types.IstanbulAggregatedSeal, aggregatedEpochValidatorSetSeal types.IstanbulEpochValidatorSetSeal) error

Commit implements istanbul.Backend.Commit

func (*Backend) EpochSize

func (sb *Backend) EpochSize() uint64

EpochSize returns the size of epochs in blocks.

func (*Backend) EventMux

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

EventMux implements istanbul.Backend.EventMux

func (*Backend) Finalize

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

Finalize runs any post-transaction state modifications (e.g. block rewards) but does not assemble the 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.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, receipts []*types.Receipt, randomness *types.Randomness) (*types.Block, error)

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

func (sb *Backend) GenerateRandomness(parentHash common.Hash) (common.Hash, common.Hash, error)

GenerateRandomness will generate the random beacon randomness

func (*Backend) GetAnnounceVersion

func (sb *Backend) GetAnnounceVersion() uint

GetAnnounceVersion will retrieve the current announce version.

func (*Backend) GetCurrentHeadBlock

func (sb *Backend) GetCurrentHeadBlock() istanbul.Proposal

GetCurrentHeadBlock retrieves the last block

func (*Backend) GetCurrentHeadBlockAndAuthor

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

GetCurrentHeadBlockAndAuthor retrieves the last block alongside the coinbase address for it

func (*Backend) GetProxiedValidatorEngine

func (sb *Backend) GetProxiedValidatorEngine() proxy.ProxiedValidatorEngine

GetProxiedValidatorEngine returns the proxied validator engine object

func (*Backend) GetProxyEngine

func (sb *Backend) GetProxyEngine() proxy.ProxyEngine

GetProxyEngine returns the proxy engine object

func (*Backend) GetValEnodeTableEntries

func (sb *Backend) GetValEnodeTableEntries(valAddresses []common.Address) (map[common.Address]*istanbul.AddressEntry, error)

func (*Backend) GetValidators

func (sb *Backend) GetValidators(blockNumber *big.Int, headerHash common.Hash) []istanbul.Validator

func (*Backend) Gossip

func (sb *Backend) Gossip(payload []byte, ethMsgCode uint64) error

Gossip implements istanbul.Backend.Gossip Gossip will gossip the eth message to all connected peers

func (*Backend) HandleMsg

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

HandleMsg implements consensus.Handler.HandleMsg

func (*Backend) Handshake

func (sb *Backend) Handshake(peer consensus.Peer) (bool, error)

Handshake allows the initiating peer to identify itself as a validator

func (*Backend) HasBlock

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

HasBlock implements istanbul.Backend.HasBlock

func (*Backend) HashForBlock

func (sb *Backend) HashForBlock(number uint64) common.Hash

HashForBlock returns the block hash from the canonical chain for the given number.

func (*Backend) IsLastBlockOfEpoch

func (sb *Backend) IsLastBlockOfEpoch(header *types.Header) bool

IsLastBlockOfEpoch returns whether or not a particular header represents the last block in the epoch.

func (*Backend) IsPrimary

func (sb *Backend) IsPrimary() bool

func (*Backend) IsPrimaryForSeq

func (sb *Backend) IsPrimaryForSeq(seq *big.Int) bool

func (*Backend) IsProxiedValidator

func (sb *Backend) IsProxiedValidator() bool

IsProxiedValidator returns true if instance has proxied validator flag

func (*Backend) IsProxy

func (sb *Backend) IsProxy() bool

IsProxy returns true if instance has proxy flag

func (*Backend) IsValidating

func (sb *Backend) IsValidating() bool

IsValidating return true if instance is validating

func (*Backend) IsValidator

func (sb *Backend) IsValidator() bool

IsValidator return if instance is a validator (either proxied or standalone)

func (*Backend) LastSubject

func (sb *Backend) LastSubject() (istanbul.Subject, error)

func (*Backend) LookbackWindow

func (sb *Backend) LookbackWindow(header *types.Header, state *state.StateDB) uint64

LookbackWindow returns the size of the lookback window for calculating uptime (in blocks) Value is constant during an epoch

func (*Backend) MakePrimary

func (sb *Backend) MakePrimary() error

MakePrimary clears the start/stop state & makes this node participate in consensus

func (*Backend) MakeReplica

func (sb *Backend) MakeReplica() error

MakeReplica clears the start/stop state & stops this node from participating in consensus

func (*Backend) Multicast

func (sb *Backend) Multicast(destAddresses []common.Address, payload []byte, ethMsgCode uint64, sendToSelf bool) error

Multicast implements istanbul.Backend.Multicast Multicast will send the eth message (with the message's payload and msgCode field set to the params payload and ethMsgCode respectively) to the nodes with the signing address in the destAddresses param. If this node is proxied and destAddresses is not nil, the message will be wrapped in an istanbul.ForwardMessage to ensure the proxy sends it to the correct destAddresses.

func (*Backend) NewWork

func (sb *Backend) NewWork() error

This function is called by miner/worker.go whenever it's mainLoop gets a newWork event.

func (*Backend) NextBlockValidators

func (sb *Backend) NextBlockValidators(proposal istanbul.Proposal) (istanbul.ValidatorSet, error)

func (*Backend) ParentBlockValidators

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

ParentBlockValidators implements istanbul.Backend.ParentBlockValidators

func (*Backend) Prepare

func (sb *Backend) Prepare(chain consensus.ChainReader, 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) RefreshValPeers

func (sb *Backend) RefreshValPeers() error

RefreshValPeers will create 'validator' type peers to all the valset validators, and disconnect from the peers that are not part of the valset. It will also disconnect all validator connections if this node is not a validator. Note that adding and removing validators are idempotent operations. If the validator being added or removed is already added or removed, then a no-op will be done.

func (*Backend) RegisterPeer

func (sb *Backend) RegisterPeer(peer consensus.Peer, isProxiedPeer bool) error

func (*Backend) RemovePeer

func (sb *Backend) RemovePeer(node *enode.Node, purpose p2p.PurposeFlag)

func (*Backend) RemoveProxy

func (sb *Backend) RemoveProxy(node *enode.Node) error

func (*Backend) RetrieveEnodeCertificateMsgMap

func (sb *Backend) RetrieveEnodeCertificateMsgMap() map[enode.ID]*istanbul.EnodeCertMsg

RetrieveEnodeCertificateMsgMap gets the most recent enode certificate messages. May be nil if no message was generated as a result of the core not being started, or if a proxy has not received a message from its proxied validator

func (*Backend) RetrieveValidatorConnSet

func (sb *Backend) RetrieveValidatorConnSet() (map[common.Address]bool, error)

RetrieveValidatorConnSet returns the cached validator conn set if the cache is younger than 20 blocks, younger than 1 minute, or if an epoch transition didn't occur since the last cached entry. In the event of a cache miss, this may block for a couple seconds while retrieving the uncached set.

func (*Backend) RewriteValEnodeTableEntries

func (sb *Backend) RewriteValEnodeTableEntries(entries map[common.Address]*istanbul.AddressEntry) error

func (*Backend) Seal

func (sb *Backend) Seal(chain consensus.ChainReader, 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) SelfNode

func (sb *Backend) SelfNode() *enode.Node

SelfNode returns the owner's node (if this is a proxy, it will return the external node)

func (*Backend) SendDelegateSignMsgToProxiedValidator

func (sb *Backend) SendDelegateSignMsgToProxiedValidator(msg []byte) error

SendDelegateSignMsgToProxiedValidator sends an istanbulDelegateSign message to a proxied validator if one exists

func (*Backend) SendDelegateSignMsgToProxy

func (sb *Backend) SendDelegateSignMsgToProxy(msg []byte, peerID enode.ID) error

SendDelegateSignMsgToProxy sends an istanbulDelegateSign message to a proxy if one exists

func (*Backend) SetBlockProcessors

func (sb *Backend) SetBlockProcessors(hasBadBlock func(common.Hash) bool,
	processBlock func(*types.Block, *state.StateDB) (types.Receipts, []*types.Log, uint64, error),
	validateState func(*types.Block, *state.StateDB, types.Receipts, uint64) error) error

SetBlockProcessors implements consensus.Istanbul.SetBlockProcessors

func (*Backend) SetBroadcaster

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

SetBroadcaster implements consensus.Handler.SetBroadcaster

func (*Backend) SetChain

func (sb *Backend) SetChain(chain consensus.ChainReader, currentBlock func() *types.Block, stateAt func(common.Hash) (*state.StateDB, error))

func (*Backend) SetEnodeCertificateMsgMap

func (sb *Backend) SetEnodeCertificateMsgMap(enodeCertMsgMap map[enode.ID]*istanbul.EnodeCertMsg) error

SetEnodeCertificateMsgMap will verify the given enode certificate message map, then update it on this struct.

func (*Backend) SetP2PServer

func (sb *Backend) SetP2PServer(p2pserver consensus.P2PServer)

SetP2PServer implements consensus.Handler.SetP2PServer

func (*Backend) SetStartValidatingBlock

func (sb *Backend) SetStartValidatingBlock(blockNumber *big.Int) error

SetStartValidatingBlock sets block that the validator will start validating on (inclusive)

func (*Backend) SetStopValidatingBlock

func (sb *Backend) SetStopValidatingBlock(blockNumber *big.Int) error

SetStopValidatingBlock sets the block that the validator will stop just before (exclusive range)

func (*Backend) Sign

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

Sign implements istanbul.Backend.Sign

func (*Backend) SignBLS

func (sb *Backend) SignBLS(data []byte, extra []byte, useComposite, cip22 bool) (blscrypto.SerializedSignature, error)

Sign implements istanbul.Backend.SignBLS

func (*Backend) StartAnnouncing

func (sb *Backend) StartAnnouncing() error

StartAnnouncing implements consensus.Istanbul.StartAnnouncing

func (*Backend) StartProxiedValidatorEngine

func (sb *Backend) StartProxiedValidatorEngine() error

StartProxiedValidatorEngine implements consensus.Istanbul.StartProxiedValidatorEngine

func (*Backend) StartValidating

func (sb *Backend) StartValidating() error

StartValidating implements consensus.Istanbul.StartValidating

func (*Backend) StopAnnouncing

func (sb *Backend) StopAnnouncing() error

StopAnnouncing implements consensus.Istanbul.StopAnnouncing

func (*Backend) StopProxiedValidatorEngine

func (sb *Backend) StopProxiedValidatorEngine() error

StopProxiedValidatorEngine implements consensus.Istanbul.StopProxiedValidatorEngine

func (*Backend) StopValidating

func (sb *Backend) StopValidating() error

StopValidating implements consensus.Istanbul.StopValidating

func (*Backend) SubscribeNewDelegateSignEvent

func (sb *Backend) SubscribeNewDelegateSignEvent(ch chan<- istanbul.MessageWithPeerIDEvent) event.Subscription

SubscribeNewDelegateSignEvent subscribes a channel to any new delegate sign messages

func (*Backend) Unicast

func (sb *Backend) Unicast(peer consensus.Peer, payload []byte, ethMsgCode uint64)

Unicast asynchronously sends a message to a single peer.

func (*Backend) UnregisterPeer

func (sb *Backend) UnregisterPeer(peer consensus.Peer, isProxiedPeer bool)

func (*Backend) UpdateAnnounceVersion

func (sb *Backend) UpdateAnnounceVersion()

UpdateAnnounceVersion will asynchronously update the announce version.

func (*Backend) UpdateMetricsForParentOfBlock

func (sb *Backend) UpdateMetricsForParentOfBlock(child *types.Block)

UpdateMetricsForParentOfBlock maintains metrics around the *parent* of the supplied block. To figure out if this validator signed the parent block: * First check the grandparent's validator set. If not elected, it didn't. * Then, check the parent seal on the supplied (child) block. We cannot determine any specific info from the validators in the seal of the parent block, because different nodes circulate different versions. The bitmap of signed validators only becomes canonical when the child block is proposed.

func (*Backend) UpdateReplicaState

func (sb *Backend) UpdateReplicaState(seq *big.Int)

UpdateReplicaState updates the replica state with the latest seq.

func (*Backend) UpdateValSetDiff

func (sb *Backend) UpdateValSetDiff(chain consensus.ChainReader, header *types.Header, state *state.StateDB) error

UpdateValSetDiff will update the validator set diff in the header, if the mined header is the last block of the epoch

func (*Backend) ValidatorAddress

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

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.ChainReader, header *types.Header, seal bool) error

VerifyHeader checks whether a header conforms to the consensus rules of a given engine. Verifies the seal regardless of given "seal" argument.

func (*Backend) VerifyHeaders

func (sb *Backend) VerifyHeaders(chain consensus.ChainReader, 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) VerifyPendingBlockValidatorSignature

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

VerifyPendingBlockValidatorSignature will verify that the message sender is a validator that is responsible for the current pending block (the next block right after the head block).

func (*Backend) VerifySeal

func (sb *Backend) VerifySeal(chain consensus.ChainReader, 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) VerifyValidatorConnectionSetSignature

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

VerifyValidatorConnectionSetSignature will verify that the message sender is a validator that is responsible for the current pending block (the next block right after the head block).

type Keys

type Keys []*ecdsa.PrivateKey

func (Keys) Len

func (slice Keys) Len() int

func (Keys) Less

func (slice Keys) Less(i, j int) bool

func (Keys) Swap

func (slice Keys) Swap(i, j int)

type QueryEnodeGossipFrequencyState

type QueryEnodeGossipFrequencyState int

QueryEnodeGossipFrequencyState specifies how frequently to gossip query enode messages

const (
	// HighFreqBeforeFirstPeerState will send out a query enode message every 1 minute until the first peer is established
	HighFreqBeforeFirstPeerState QueryEnodeGossipFrequencyState = iota

	// HighFreqAfterFirstPeerState will send out an query enode message every 1 minute for the first 10 query enode messages after the first peer is established.
	// This is on the assumption that when this node first establishes a peer, the p2p network that this node is in may
	// be partitioned with the broader p2p network. We want to give that p2p network some time to connect to the broader p2p network.
	HighFreqAfterFirstPeerState

	// LowFreqState will send out an query every config.AnnounceQueryEnodeGossipPeriod seconds
	LowFreqState
)

type Snapshot

type Snapshot struct {
	Epoch uint64 // The number of blocks for each epoch

	Number uint64                // Block number where the snapshot was created
	Hash   common.Hash           // Block hash where the snapshot was created
	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)

MarshalJSON to a json byte array

func (*Snapshot) UnmarshalJSON

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

UnmarshalJSON from a json byte array

Directories

Path Synopsis
internal
db

Jump to

Keyboard shortcuts

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