bft

package
v0.0.0-...-d2cd647 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const WitnessSize = 8

Variables

View Source
var (
	// ErrAddressUnauthorized is returned when given address cannot be found in
	// current validator set.
	ErrAddressUnauthorized = errors.New("unauthorized address")
	// ErrEngineStopped is returned if the engine is stopped
	ErrEngineStopped = errors.New("stopped engine")
	// ErrEngineStarted is returned if the engine is already started
	ErrEngineStarted = errors.New("started engine")
)
View Source
var DefaultConfig = &BFTConfig{
	RequestTimeout: 10000,
	BlockPeriod:    common.BFTBlockInterval,
	ProposerPolicy: RoundRobin,
	Epoch:          common.CheckInterval,
}

Functions

func CheckVerifierSignature

func CheckVerifierSignature(verSet VerifierSet, data []byte, sig []byte) (common.Address, error)

CheckVerifierSignature check the validator in or not in the verset by signature

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{}) (hash common.Hash)

Types

type BFTConfig

type BFTConfig 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
}

type FinalCommittedEvent

type FinalCommittedEvent struct {
}

type MessageEvent

type MessageEvent struct {
	Payload []byte
}

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 {
	// Height retrieves the sequence number of this proposal.
	Height() uint64

	// Hash retrieves the hash of this proposal.
	Hash() common.Hash
}

type ProposalSelector

type ProposalSelector func(VerifierSet, common.Address, uint64) Verifier

type ProposerPolicy

type ProposerPolicy uint64
const (
	RoundRobin ProposerPolicy = iota // in a round robin setting, proposer will change in very block and round change.
	Sticky                           // with sticky property, propose will change only when a round change happens.
)

type Request

type Request struct {
	Proposal Proposal
}

type RequestEvent

type RequestEvent struct {
	Proposal Proposal
}

type Server

type Server interface {
	Address() common.Address

	// Verifiers returns the Verifier set
	Verifiers(proposal Proposal) VerifierSet

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

	// Broadcast sends a message to all Verifiers (include self)
	Broadcast(valSet VerifierSet, payload []byte) error

	// Gossip sends a message to all Verifiers (exclude self)
	Gossip(valSet VerifierSet, payload []byte) error

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

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

	// 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 Verifier
	CheckSignature(data []byte, addr common.Address, sig []byte) error

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

	// HasPropsal checks if the combination of the given hash and height matches any existing blocks
	HasPropsal(hash common.Hash) bool

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

	// ParentVerifiers returns the Verifier set of the given proposal's parent block
	ParentVerifiers(proposal Proposal) VerifierSet

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

type Subject

type Subject struct {
	View   *View
	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 Verifier

type Verifier interface {
	Address() common.Address
	String() string // representation of verifier
}

type VerifierSet

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

type Verifiers

type Verifiers []Verifier

func (Verifiers) Len

func (verifiers Verifiers) Len() int

func (Verifiers) Less

func (verifiers Verifiers) Less(i, j int) bool

Less return whether one verifier is smaller than another (by verifier.String())

func (Verifiers) Swap

func (verifiers Verifiers) 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

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