pbft

package
v0.0.0-...-8ad0a2a Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnauthorizedAddress is returned when given address cannot be found in
	// current validator set.
	ErrUnauthorizedAddress = errors.New("unauthorized address")
	// ErrStoppedEngine is returned if the engine is stopped
	ErrStoppedEngine = errors.New("stopped engine")
	// ErrStartedEngine is returned if the engine is already started
	ErrStartedEngine = errors.New("started engine")
)
View Source
var DefaultConfig = &Config{
	RequestTimeout: 3000,
	BlockPeriod:    1,
	ProposerPolicy: RoundRobin,
	Epoch:          30000,
	LightMode:      false,
}
View Source
var MaxBlockTxs uint64 = 1000

Functions

func CheckValidatorSignature

func CheckValidatorSignature(valSet ValidatorSet, data []byte, sig []byte) (common.Address, error)

func GetSignatureAddress

func GetSignatureAddress(data []byte, sig []byte) (common.Address, error)

GetSignatureAddress gets the signer address from the signature

func RLPHash

func RLPHash(v interface{}) (h common.Hash)

Types

type Backend

type Backend interface {
	// Address returns the owner's address
	Address() common.Address

	// Validators returns the validator set
	Validators(conclusion Conclusion) ValidatorSet

	// EventMux returns the event mux in backend
	EventMux() *event.TypeMux

	// Post post a message
	Post(payload []byte)

	// Broadcast sends a message to other validators by router
	Broadcast(valSet ValidatorSet, sender common.Address, payload []byte) error

	// BroadcastMsg sends a message to specific validators
	BroadcastMsg(ps map[common.Address]consensus.Peer, hash common.Hash, payload []byte) error

	// Send a message to the specific validators
	SendMsg(val Validators, payload []byte) error

	// Guidance sends a message to other validators by router
	Guidance(valSet ValidatorSet, sender common.Address, payload []byte)

	// Gossip sends a message to all validators (exclude self)
	Gossip(valSet ValidatorSet, payload []byte)

	// GetForwardNodes returns peers of validators, and forward node addresses
	GetForwardNodes(Validators) (map[common.Address]consensus.Peer, []common.Address)

	// Commit delivers an approved proposal to backend.
	// The delivered proposal will be put into blockchain.
	Commit(proposal Conclusion, commitSeals [][]byte) error

	// Verify verifies the proposal. If a consensus.ErrFutureBlock error is returned,
	// the time difference of the proposal and current time is also returned.
	Verify(proposal Proposal, checkHeader, checkBody bool) (time.Duration, error)

	// Execute a proposal by sealer
	Execute(Proposal) (Conclusion, error)

	// OnTimeout notify the sealer pbft on timeout event
	OnTimeout()

	// Fill a light proposal, return whether it is filled and missed transactions
	FillLightProposal(proposal LightProposal) (bool, []types.MissedTx, error)

	// MarkTransactionKnownBy mark transactions are known by validators, do not broadcast again
	MarkTransactionKnownBy(val Validator, txs types.Transactions)

	// Sign signs input data with the backend's private key
	Sign([]byte) ([]byte, error)

	// CheckSignature verifies the signature by checking if it's signed by
	// the given validator
	CheckSignature(data []byte, addr common.Address, sig []byte) error

	// LastProposal retrieves latest committed proposal and the address of proposer
	LastProposal() (Proposal, Conclusion, common.Address)

	// HasProposal checks if the combination of the given hash and height matches any existing blocks
	HasProposal(hash common.Hash, number *big.Int) (common.Hash, bool)

	AnnounceCommittedProposal(hash common.Hash, number *big.Int, to Validator)

	// GetProposer returns the proposer of the given block height
	GetProposer(number uint64) common.Address

	// ParentValidators returns the validator set of the given proposal's parent block
	ParentValidators(proposal Proposal) ValidatorSet

	// HasBadBlock returns whether the block with the hash is a bad block
	HasBadProposal(hash common.Hash) bool

	Close() error
}

Backend provides application specific functions for Istanbul core

type Conclusion

type Conclusion interface {
	Proposal
	// Hash retrieves the hash of this proposal.
	Hash() common.Hash
}

Conclusion means executed Proposal

type Config

type Config struct {
	RequestTimeout uint64         `toml:",omitempty"` // The timeout for each bft round in milliseconds.
	BlockPeriod    uint64         `toml:",omitempty"` // Default minimum difference between two consecutive block's timestamps in second
	ProposerPolicy ProposerPolicy `toml:",omitempty"` // The policy for proposer selection
	Epoch          uint64         `toml:",omitempty"` // The number of blocks after which to checkpoint and reset the pending votes
	LightMode      bool           `toml:",omitempty"` // Enable receive light block with tx digests only
	GasLimit       uint64
}

type FinalCommittedEvent

type FinalCommittedEvent struct {
	Committed Conclusion
}

FinalCommittedEvent is posted when a proposal is committed

type LightPreprepare

type LightPreprepare Preprepare

func (*LightPreprepare) DecodeRLP

func (b *LightPreprepare) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream. Overwrite Decode method for light block

func (*LightPreprepare) FullPreprepare

func (b *LightPreprepare) FullPreprepare() *Preprepare

type LightProposal

type LightProposal interface {
	Proposal

	TxDigests() []common.Hash

	Completed() bool // return whether the proposal is completed (no missed txs)

	FillMissedTxs(txs types.Transactions) error
}

LightProposal is a Proposal without tx body

func Proposal2Light

func Proposal2Light(proposal Proposal, init bool) LightProposal

Proposal2Light change the common proposal to the light proposal return nil if proposal to block failed

type MessageEvent

type MessageEvent struct {
	Payload []byte
}

MessageEvent is posted for pbft engine communication

type MissedReq

type MissedReq struct {
	View      *View
	MissedTxs []types.MissedTx
}

func (*MissedReq) DecodeRLP

func (b *MissedReq) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*MissedReq) EncodeRLP

func (b *MissedReq) EncodeRLP(w io.Writer) error

func (*MissedReq) String

func (b *MissedReq) String() string

type MissedResp

type MissedResp struct {
	View   *View
	ReqTxs types.Transactions
}

func (*MissedResp) DecodeOffset

func (b *MissedResp) DecodeOffset(buf []byte) error

func (*MissedResp) DecodeRLP

func (b *MissedResp) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*MissedResp) EncodeOffset

func (b *MissedResp) EncodeOffset() ([]byte, error)

func (*MissedResp) EncodeRLP

func (b *MissedResp) EncodeRLP(w io.Writer) error

type Preprepare

type Preprepare struct {
	View     *View
	Proposal Proposal
}

func (*Preprepare) DecodeRLP

func (b *Preprepare) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Preprepare) EncodeRLP

func (b *Preprepare) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

type Proposal

type Proposal interface {
	// Number retrieves the sequence number of this proposal.
	Number() *big.Int

	PendingHash() common.Hash // unexecuted block hash

	EncodeRLP(w io.Writer) error

	DecodeRLP(s *rlp.Stream) error

	String() string

	FetchMissedTxs(misses []types.MissedTx) (types.Transactions, error)

	IsEmpty() bool
}

Proposal supports retrieving height and serialized block to be used during Istanbul consensus.

func Light2Proposal

func Light2Proposal(proposal Proposal) Proposal

Light2Proposal trans a light proposal to the common proposal warning: will panic if proposal is not light

type ProposalSelector

type ProposalSelector func(ValidatorSet, common.Address, uint64) Validator

type ProposerPolicy

type ProposerPolicy uint64
const (
	RoundRobin ProposerPolicy = iota
	Sticky
)

type Request

type Request struct {
	Proposal Proposal // always common proposal (block with all txs)
}

func (*Request) TerminalString

func (r *Request) TerminalString() string

type RequestEvent

type RequestEvent struct {
	Proposal Proposal
}

RequestEvent is posted to propose a proposal

type SealContext

type SealContext struct {
	MaxBlockTxs    uint64
	LastTimeoutTx  int
	MaxNoTimeoutTx int
	LastSealTime   int64
}

func CreateSealContext

func CreateSealContext() *SealContext

type Subject

type Subject struct {
	View    *View
	Pending common.Hash
	Digest  common.Hash
}

func (*Subject) DecodeRLP

func (b *Subject) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*Subject) EncodeRLP

func (b *Subject) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*Subject) String

func (b *Subject) String() string

type Validator

type Validator interface {
	// Address returns address
	Address() common.Address

	// String representation of Validator
	String() string
}

type ValidatorSet

type ValidatorSet interface {
	// Calculate the proposer
	CalcProposer(lastProposer common.Address, round uint64)
	// Return the validator size
	Size() int
	// Return the validator array
	List() []Validator
	// Get validator by index
	GetByIndex(i uint64) Validator
	// Get validator by given address
	GetByAddress(addr common.Address) (int, Validator)
	// Get current proposer
	GetProposer() Validator
	// Check whether the validator with given address is a proposer
	IsProposer(address common.Address) bool
	// Add validator
	AddValidator(address common.Address) bool
	// Remove validator
	RemoveValidator(address common.Address) bool
	// Copy validator set
	Copy() ValidatorSet
	// Get the maximum number of faulty nodes
	F() int
	// Get proposer policy
	Policy() ProposerPolicy
}

type Validators

type Validators []Validator

func (Validators) Len

func (slice Validators) Len() int

func (Validators) Less

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

func (Validators) Swap

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

type View

type View struct {
	Round    *big.Int
	Sequence *big.Int
}

View includes a round number and a sequence number. Sequence is the block number we'd like to commit. Each round has a number and is composed by 3 steps: preprepare, prepare and commit.

If the given block is not accepted by validators, a round change will occur and the validators start a new round with round+1.

func (*View) Cmp

func (v *View) Cmp(y *View) int

Cmp compares v and y and returns:

-1 if v <  y
 0 if v == y
+1 if v >  y

func (*View) DecodeRLP

func (v *View) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder, and load the consensus fields from a RLP stream.

func (*View) EncodeRLP

func (v *View) EncodeRLP(w io.Writer) error

EncodeRLP serializes b into the Ethereum RLP format.

func (*View) String

func (v *View) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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