ibft

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyType      = "type"
	KeyEpochSize = "epochSize"
)
View Source
const (
	DefaultEpochSize = 100000

	WriteBlockSource = "ibft"
)
View Source
const IbftKeyName = "validator.key"

Variables

View Source
var (
	// IstanbulDigest represents a hash of "Istanbul practical byzantine fault tolerance"
	// to identify whether the block is from Istanbul consensus engine
	IstanbulDigest = types.StringToHash("0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365")

	// IstanbulExtraVanity represents a fixed number of extra-data bytes reserved for proposer vanity
	IstanbulExtraVanity = 32

	// IstanbulExtraSeal represents the fixed number of extra-data bytes reserved for proposer seal
	IstanbulExtraSeal = 65
)
View Source
var (
	ErrInvalidHookParam      = errors.New("invalid IBFT hook param passed in")
	ErrInvalidMechanismType  = errors.New("invalid consensus mechanism type in params")
	ErrMissingMechanismType  = errors.New("missing consensus mechanism type in params")
	ErrEmptyValidatorExtract = errors.New("empty extract validatorset")
	ErrInvalidMixHash        = errors.New("invalid mixhash")
	ErrInvalidUncleHash      = errors.New("invalid uncle hash")
	ErrWrongDifficulty       = errors.New("wrong difficulty")
	ErrInvalidBlockTimestamp = errors.New("invalid block timestamp")
	ErrInvalidCommittedSeal  = errors.New("invalid committed seal")
)
View Source
var (
	ErrInvalidNonce = errors.New("invalid nonce specified")
)

Functions

func Factory

func Factory(
	params *consensus.ConsensusParams,
) (consensus.Consensus, error)

Factory implements the base consensus Factory method

func PutIbftExtra

func PutIbftExtra(h *types.Header, istanbulExtra *IstanbulExtra) error

PutIbftExtra sets the extra data field in the header to the passed in istanbul extra data

Types

type BaseConsensusMechanism

type BaseConsensusMechanism struct {

	// Available periods
	From uint64
	To   *uint64
	// contains filtered or unexported fields
}

func (*BaseConsensusMechanism) GetHookMap

func (base *BaseConsensusMechanism) GetHookMap() map[HookType]func(interface{}) error

GetHookMap implements the ConsensusMechanism interface method

func (*BaseConsensusMechanism) GetType

func (base *BaseConsensusMechanism) GetType() MechanismType

GetType implements the ConsensusMechanism interface method

func (*BaseConsensusMechanism) IsInRange

func (base *BaseConsensusMechanism) IsInRange(blockNumber uint64) bool

IsInRange returns indicates if the given blockNumber is between from and to

type ConsensusMechanism

type ConsensusMechanism interface {
	// GetType returns the type of IBFT consensus mechanism (PoA / PoS)
	GetType() MechanismType

	// GetHookMap returns the hooks registered with the specific consensus mechanism
	GetHookMap() map[HookType]func(interface{}) error

	// IsAvailable returns whether the corresponding hook is available
	IsAvailable(hook HookType, height uint64) bool

	// ShouldWriteTransactions returns whether transactions should be written to a block
	// from the TxPool
	ShouldWriteTransactions(blockNumber uint64) bool
	// contains filtered or unexported methods
}

func PoAFactory

func PoAFactory(ibft *Ibft, params *IBFTFork) (ConsensusMechanism, error)

PoAFactory initializes the required data for the Proof of Authority mechanism

func PoSFactory

func PoSFactory(ibft *Ibft, params *IBFTFork) (ConsensusMechanism, error)

PoSFactory initializes the required data for the Proof of Stake mechanism

type ConsensusMechanismFactory

type ConsensusMechanismFactory func(ibft *Ibft, params *IBFTFork) (ConsensusMechanism, error)

ConsensusMechanismFactory is the factory function to create a consensus mechanism

type HookType

type HookType string
const (

	// VerifyHeadersHook defines additional checks that need to happen
	// when verifying the headers
	VerifyHeadersHook HookType = "VerifyHeadersHook"

	// ProcessHeadersHook defines additional steps that need to happen
	// when processing the headers
	ProcessHeadersHook HookType = "ProcessHeadersHook"

	// InsertBlockHook defines additional steps that need to happen
	// when inserting a block into the chain
	InsertBlockHook HookType = "InsertBlockHook"

	// CandidateVoteHook defines additional steps that need to happen
	// when building a block (candidate voting)
	CandidateVoteHook HookType = "CandidateVoteHook"

	// AcceptStateLogHook defines what should be logged out as the status
	// from AcceptState
	AcceptStateLogHook HookType = "AcceptStateLogHook"

	// VerifyBlockHook defines the additional verification steps for the PoS mechanism
	VerifyBlockHook HookType = "VerifyBlockHook"

	// PreStateCommitHook defines the additional state transition injection
	PreStateCommitHook HookType = "PreStateCommitHook"

	// CalculateProposerHook defines what is the next proposer
	// based on the previous
	CalculateProposerHook = "CalculateProposerHook"
)

type IBFTFork

type IBFTFork struct {
	Type       MechanismType      `json:"type"`
	Deployment *common.JSONNumber `json:"deployment,omitempty"`
	From       common.JSONNumber  `json:"from"`
	To         *common.JSONNumber `json:"to,omitempty"`
}

IBFT Fork represents setting in params.engine.ibft of genesis.json

func GetIBFTForks

func GetIBFTForks(ibftConfig map[string]interface{}) ([]IBFTFork, error)

GetIBFTForks returns IBFT fork configurations from chain config

type Ibft

type Ibft struct {
	Grpc *grpc.Server // gRPC configuration
	// contains filtered or unexported fields
}

Ibft represents the IBFT consensus mechanism object

func (*Ibft) Close

func (i *Ibft) Close() error

Close closes the IBFT consensus mechanism, and does write back to disk

func (*Ibft) GetBlockCreator

func (i *Ibft) GetBlockCreator(header *types.Header) (types.Address, error)

GetBlockCreator retrieves the block signer from the extra data field

func (*Ibft) GetEpoch

func (i *Ibft) GetEpoch(number uint64) uint64

GetEpoch returns the current epoch

func (*Ibft) GetSyncProgression

func (i *Ibft) GetSyncProgression() *progress.Progression

GetSyncProgression gets the latest sync progression, if any

func (*Ibft) Initialize

func (i *Ibft) Initialize() error

Start starts the IBFT consensus

func (*Ibft) IsLastOfEpoch

func (i *Ibft) IsLastOfEpoch(number uint64) bool

IsLastOfEpoch checks if the block number is the last of the epoch

func (*Ibft) IsSystemTransaction added in v1.2.0

func (i *Ibft) IsSystemTransaction(height uint64, coinbase types.Address, tx *types.Transaction) bool

func (*Ibft) PreStateCommit

func (i *Ibft) PreStateCommit(header *types.Header, txn *state.Transition) error

PreStateCommit a hook to be called before finalizing state transition on inserting block

func (*Ibft) ProcessHeaders

func (i *Ibft) ProcessHeaders(headers []*types.Header) error

func (*Ibft) Start

func (i *Ibft) Start() error

Start starts the IBFT consensus

func (*Ibft) VerifyHeader

func (i *Ibft) VerifyHeader(header *types.Header) error

VerifyHeader wrapper for verifying headers

type IstanbulExtra

type IstanbulExtra struct {
	Validators    []types.Address
	Seal          []byte
	CommittedSeal [][]byte
}

IstanbulExtra defines the structure of the extra field for Istanbul

func (*IstanbulExtra) MarshalRLPTo

func (i *IstanbulExtra) MarshalRLPTo(dst []byte) []byte

MarshalRLPTo defines the marshal function wrapper for IstanbulExtra

func (*IstanbulExtra) MarshalRLPWith

func (i *IstanbulExtra) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith defines the marshal function implementation for IstanbulExtra

func (*IstanbulExtra) UnmarshalRLP

func (i *IstanbulExtra) UnmarshalRLP(input []byte) error

UnmarshalRLP defines the unmarshal function wrapper for IstanbulExtra

func (*IstanbulExtra) UnmarshalRLPFrom

func (i *IstanbulExtra) UnmarshalRLPFrom(p *fastrlp.Parser, v *fastrlp.Value) error

UnmarshalRLPFrom defines the unmarshal implementation for IstanbulExtra

type MechanismType

type MechanismType string
const (
	// PoA defines the Proof of Authority IBFT type,
	// where the validator set is changed through voting / pre-set in genesis
	PoA MechanismType = "PoA"

	// PoS defines the Proof of Stake IBFT type,
	// where the validator set it changed through staking and authorization
	// on the ValidatorSet SC
	PoS MechanismType = "PoS"
)

func ParseType

func ParseType(mechanism string) (MechanismType, error)

ParseType converts a mechanism string representation to a MechanismType

func (MechanismType) String

func (t MechanismType) String() string

String is a helper method for casting a MechanismType to a string representation

type MsgType

type MsgType uint64

func (MsgType) String

func (m MsgType) String() string

String returns the string representation of the message type

type PoAMechanism

type PoAMechanism struct {
	BaseConsensusMechanism
}

PoAMechanism defines specific hooks for the Proof of Authority IBFT mechanism

func (*PoAMechanism) IsAvailable

func (poa *PoAMechanism) IsAvailable(hookType HookType, height uint64) bool

IsAvailable returns indicates if mechanism should be called at given height

func (*PoAMechanism) ShouldWriteTransactions

func (poa *PoAMechanism) ShouldWriteTransactions(blockNumber uint64) bool

ShouldWriteTransactions indicates if transactions should be written to a block

type PoSMechanism

type PoSMechanism struct {
	BaseConsensusMechanism
	// Params
	ContractDeployment uint64 // The height when deploying ValidatorSet contract
}

PoSMechanism defines specific hooks for the Proof of Stake IBFT mechanism

func (*PoSMechanism) IsAvailable

func (pos *PoSMechanism) IsAvailable(hookType HookType, height uint64) bool

IsAvailable returns indicates if mechanism should be called at given height

func (*PoSMechanism) ShouldWriteTransactions

func (pos *PoSMechanism) ShouldWriteTransactions(blockNumber uint64) bool

ShouldWriteTransactions indicates if transactions should be written to a block

type Snapshot

type Snapshot struct {
	// block number when the snapshot was created
	Number uint64

	// block hash when the snapshot was created
	Hash string

	// votes casted in chronological order
	Votes []*Vote

	// current set of validators
	Set validator.Validators
}

Snapshot is the current state at a given point in time for validators and votes

func (*Snapshot) Copy

func (s *Snapshot) Copy() *Snapshot

Copy makes a copy of the snapshot

func (*Snapshot) Count

func (s *Snapshot) Count(h func(v *Vote) bool) (count int)

Count returns the vote tally. The count increases if the callback function returns true

func (*Snapshot) Equal

func (s *Snapshot) Equal(ss *Snapshot) bool

Equal checks if two snapshots are equal

func (*Snapshot) RemoveVotes

func (s *Snapshot) RemoveVotes(h func(v *Vote) bool)

RemoveVotes removes votes from the snapshot, based on the passed in callback

func (*Snapshot) ToProto

func (s *Snapshot) ToProto() *proto.Snapshot

ToProto converts the snapshot to a Proto snapshot

type Vote

type Vote struct {
	Validator types.Address
	Address   types.Address
	Authorize bool
}

Vote defines the vote structure

func (*Vote) Copy

func (v *Vote) Copy() *Vote

Copy makes a copy of the vote, and returns it

func (*Vote) Equal

func (v *Vote) Equal(vv *Vote) bool

Equal checks if two votes are equal

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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