dbft

package
v0.0.0-...-ed2c97c Latest Latest
Warning

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

Go to latest
Published: May 18, 2019 License: GPL-3.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MsgPreprepare uint64 = iota
	MsgPrepare
	MsgCommit
)

Variables

This section is empty.

Functions

func CheckValidatorSignature

func CheckValidatorSignature(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 {
	// Verify verifies the proposal.
	Verify(Proposal) error

	// Validators returns the validator set
	Validators(proposal Proposal) Validators

	// 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

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

type DPOS

type DPOS interface {
	// snapshot retrieves the dpos snapshot at a given point in time.
	Snapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) (Snapshot, error)

	// AccumulateRewards credits the coinbase of the given block with the mining reward.
	AccumulateRewards(state *state.StateDB, header *types.Header, snap Snapshot)
}

type Message

type Message struct {
	Code          uint64         // code type contains MsgPreprepare,MsgPrepare,MsgCommit
	Msg           []byte         // content of the Message
	Address       common.Address // address of the proposer
	Signature     []byte         // signed hash of the Msg by proposer
	CommittedSeal []byte         //
}

Message defines message format of the pbft engine

func (*Message) CheckSignature

func (m *Message) CheckSignature() error

func (*Message) Decode

func (m *Message) Decode(val interface{}) error

func (*Message) DecodeRLP

func (m *Message) DecodeRLP(s *rlp.Stream) error

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

func (*Message) EncodeRLP

func (m *Message) EncodeRLP(w io.Writer) error

EncodeRLP serializes m into the Ethereum RLP format.

func (*Message) FromPayload

func (m *Message) FromPayload(b []byte) error

FromPayload decode the payload from the p2p peer and check signature

func (*Message) Payload

func (m *Message) Payload() ([]byte, error)

func (*Message) PayloadNoSig

func (m *Message) PayloadNoSig() ([]byte, error)

func (*Message) String

func (m *Message) String() string

type PBFT

type PBFT interface {
	Start() error
	Stop() error
	StartConsensus(validators Validators, proposal Proposal) error
	PrePrepare(msg *Message) error
	Prepare(msg *Message) error
	Commit(msg *Message) error
	SubscribeNewMsgEvent(chan<- consensus.PbftMsg) event.Subscription
	DispatchMsg(address common.Address, msg p2p.Msg) (bool, 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

	Time() *big.Int

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

	EncodeRLP(w io.Writer) error

	DecodeRLP(s *rlp.Stream) error
}

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

type Snapshot

type Snapshot interface {
	Validators() Validators

	// Inturn returns if a signer at a given block height is in-turn or not.
	Inturn(validator common.Address, headerTime, number *big.Int) bool

	// Intrun returns next timestamp when validator can sign a block
	NextTimeSlot(validator common.Address) *big.Int
}

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 Validators

type Validators []common.Address

func (Validators) Addresses

func (v Validators) Addresses() []common.Address

func (Validators) F

func (v Validators) F() int

Get the maximum number of faulty nodes

func (Validators) IsValidator

func (v Validators) IsValidator(validator common.Address) bool

type View

type View struct {
	Proposer common.Address
	Sequence *big.Int
}

View includes proposer address and a sequence number. Sequence is the block number we'd like to commit.

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