ibft

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: LGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (

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

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

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

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

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

	// SyncStateHook defines the additional snapshot update logic
	// for PoS systems
	SyncStateHook = "SyncStateHook"

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

Define constant hook names

View Source
const (
	DefaultEpochSize = 100000
)
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")
	ErrMissingHook      = errors.New("missing IBFT hook from mechanism")
)
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 ConsensusMechanism added in v0.1.0

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[string]func(interface{}) error

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

func PoAFactory added in v0.1.0

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

PoAFactory initializes the required data for the Proof of Authority mechanism

func PoSFactory added in v0.1.0

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

PoSFactory initializes the required data for the Proof of Stake mechanism

type ConsensusMechanismFactory added in v0.1.0

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

ConsensusMechanismFactory is the factory function to create a consensus mechanism

type Ibft

type Ibft struct {
	// 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 added in v0.1.0

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

GetEpoch returns the current epoch

func (*Ibft) GetSyncProgression added in v0.1.0

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

GetSyncProgression gets the latest sync progression, if any

func (*Ibft) IsLastOfEpoch added in v0.1.0

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

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

func (*Ibft) Start

func (i *Ibft) Start() error

Start starts the IBFT consensus

func (*Ibft) VerifyHeader

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

VerifyHeader wrapper for verifying headers

type IbftState

type IbftState uint32
const (
	AcceptState IbftState = iota
	RoundChangeState
	ValidateState
	CommitState
	SyncState
)

Define the states in IBFT

func (IbftState) String

func (i IbftState) String() string

String returns the string representation of the passed in state

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 added in v0.1.0

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 on the Staking SC
	PoS MechanismType = "PoS"
)

func (MechanismType) String added in v0.1.0

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 added in v0.1.0

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

PoAMechanism defines specific hooks for the Proof of Authority IBFT mechanism

func (*PoAMechanism) GetHookMap added in v0.1.0

func (poa *PoAMechanism) GetHookMap() map[string]func(interface{}) error

GetHookMap implements the ConsensusMechanism interface method

func (*PoAMechanism) GetType added in v0.1.0

func (poa *PoAMechanism) GetType() MechanismType

GetType implements the ConsensusMechanism interface method

func (*PoAMechanism) ShouldWriteTransactions added in v0.1.0

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

ShouldWriteTransactions indicates if transactions should be written to a block

type PoSMechanism added in v0.1.0

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

PoSMechanism defines specific hooks for the Proof of Stake IBFT mechanism

func (*PoSMechanism) GetHookMap added in v0.1.0

func (pos *PoSMechanism) GetHookMap() map[string]func(interface{}) error

GetHookMap implements the ConsensusMechanism interface method

func (*PoSMechanism) GetType added in v0.1.0

func (pos *PoSMechanism) GetType() MechanismType

GetType implements the ConsensusMechanism interface method

func (*PoSMechanism) ShouldWriteTransactions added in v0.1.0

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 ValidatorSet
}

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 ValidatorSet

type ValidatorSet []types.Address

func (*ValidatorSet) Add

func (v *ValidatorSet) Add(addr types.Address)

Add adds a new address to the validator set

func (*ValidatorSet) CalcProposer

func (v *ValidatorSet) CalcProposer(round uint64, lastProposer types.Address) types.Address

CalcProposer calculates the address of the next proposer, from the validator set

func (*ValidatorSet) Del

func (v *ValidatorSet) Del(addr types.Address)

Del removes an address from the validator set

func (*ValidatorSet) Equal

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

Equal checks if 2 validator sets are equal

func (*ValidatorSet) Includes

func (v *ValidatorSet) Includes(addr types.Address) bool

Includes checks if the address is in the validator set

func (*ValidatorSet) Index

func (v *ValidatorSet) Index(addr types.Address) int

Index returns the index of the passed in address in the validator set. Returns -1 if not found

func (*ValidatorSet) Len

func (v *ValidatorSet) Len() int

Len returns the size of the validator set

func (*ValidatorSet) MaxFaultyNodes

func (v *ValidatorSet) MaxFaultyNodes() int

MaxFaultyNodes returns the maximum number of allowed faulty nodes (F), based on the current validator set

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