consensus

package
v0.0.0-...-a5ce5ae Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregatePublicKeys

func AggregatePublicKeys(pk ...*cryptography.Bls12381PublicKey) kyber.Point

func AggregateSignatures

func AggregateSignatures(sigs ...[]byte) ([]byte, error)

Types

type BlockMsg

type BlockMsg struct {
	Block *storage.Block `msgpack:"b"`
}

type Consensus

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

func NewConsensus

func NewConsensus(h host.Host, p *pubsub.PubSub, opts ...Option) (*Consensus, error)

NewConsensus initiates a new consensus engine by checking if the genesis has been fully applied to the metadata store, setting up the round timeouts and restores the current consensus state from the metadata store

func (*Consensus) ChainID

func (c *Consensus) ChainID() string

func (*Consensus) SetTracer

func (c *Consensus) SetTracer(t Tracer)

func (*Consensus) Start

func (c *Consensus) Start() error

Start initiates watching for new proposers and timeouts as well as subscribing to new messages from other nodes

func (*Consensus) State

func (c *Consensus) State() *State

func (*Consensus) Validator

func (c *Consensus) Validator() storage.Validator

type ConsensusMsg

type ConsensusMsg struct {
	Type     ConsensusMsgType      `msgpack:"t"`
	NewRound *ConsensusMsgNewRound `msgpack:"n,omitempty"`
	Proposal *ConsensusMsgProposal `msgpack:"p,omitempty"`
	Vote     *ConsensusMsgVote     `msgpack:"v,omitempty"`
	Block    *ConsensusMsgBlock    `msgpack:"b,omitempty"`
	Evidence *ConsensusMsgEvidence `msgpack:"e,omitempty"`
}

type ConsensusMsgBlock

type ConsensusMsgBlock struct {
	Height     uint64 `msgpack:"h"`
	Round      uint32 `msgpack:"r"`
	CID        string `msgpack:"c"`
	Validators []byte `msgpack:"v"`
	Signature  []byte `msgpack:"s"`
}

type ConsensusMsgEvidence

type ConsensusMsgEvidence struct {
	ConsensusMsgVote
	Accepted bool `msgpack:"a"`
}

type ConsensusMsgNewRound

type ConsensusMsgNewRound struct {
	Height          uint64    `msgpack:"h"`
	Round           uint32    `msgpack:"r"`
	LastCommitRound uint32    `msgpack:"l"`
	Timestamp       time.Time `msgpack:"ts"`
}

type ConsensusMsgProposal

type ConsensusMsgProposal struct {
	Height    uint64    `msgpack:"h,string"`
	Round     uint32    `msgpack:"r"`
	BlockID   string    `msgpack:"id"`
	Timestamp time.Time `msgpack:"ts"`
}

type ConsensusMsgType

type ConsensusMsgType uint8
const (
	ConsensusMsgTypeNewRound ConsensusMsgType = iota + 1
	ConsensusMsgTypeProposal
	ConsensusMsgTypeVote
	ConsensusMsgTypeBlock
	ConsensusMsgTypeEvidence
)

type ConsensusMsgVote

type ConsensusMsgVote struct {
	Type      VoteType  `msgpack:"t"`
	Height    uint64    `msgpack:"h"`
	Round     uint32    `msgpack:"r"`
	BlockID   string    `msgpack:"id"`
	Timestamp time.Time `msgpack:"ts"`
	Validator string    `msgpack:"v"`
}

type MemPool

type MemPool interface {
	AddTx(*tx.Tx, int) error
	GetTx() *tx.Tx
	Len() int
}

MemPool provides a means of storing new TXs that are NOT in the current block chain. The MemPool is to provide TXs in sequental time as stated by the TX, not but the time received

type Msg

type Msg struct {
	Type      MsgType       `msgpack:"t"`
	From      peer.ID       `msgpack:"p"`
	Chain     []byte        `msgpack:"c"`
	Tx        *TxMsg        `msgpack:"tx,omitempty"`
	Block     *BlockMsg     `msgpack:"bl,omitempty"`
	Consensus *ConsensusMsg `msgpack:"cn,omitempty"`
	Timestamp time.Time     `msgpack:"ts"`
	Signature []byte        `msgpack:"s"`
	Key       []byte        `msgpack:"k,omptempty"`
}

func (*Msg) Marshal

func (m *Msg) Marshal() ([]byte, error)

type MsgType

type MsgType uint16
const (
	MsgTypeTx MsgType = iota + 1
	MsgTypeBlock
	MsgTypeConsensus
)

type Option

type Option func(*Consensus) error

func WithBeaconSource

func WithBeaconSource(s <-chan uint64) Option

func WithBlockStore

func WithBlockStore(s storage.Store) Option

func WithGenesis

func WithGenesis(g *storage.GenesisInfo) Option

func WithSigningKey

func WithSigningKey(priv *cryptography.Bls12381PrivateKey) Option

func WithValidator

func WithValidator(v storage.Validator) Option

type State

type State struct {
	AmProposer  bool
	Proposer    string
	Height      uint64
	Round       uint32
	Step        Step
	Block       cid.Cid
	ParentBlock cid.Cid

	PreVotes   map[peer.ID]*Msg
	PreCommits map[peer.ID]*Msg

	PreVotesEvidence   map[string]*ConsensusMsgEvidence
	PreCommitsEvidence map[string]*ConsensusMsgEvidence
	// contains filtered or unexported fields
}

type Step

type Step uint8

type Tracer

type Tracer interface {
	OnMsg(*Msg)
	OnSendMsg(*Msg)
}

type TxList

type TxList []*tx.Tx

type TxMemPool

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

func NewTxMemPool

func NewTxMemPool() *TxMemPool

NewTxMemPool creates a new empty MemPool

func (*TxMemPool) AddTx

func (m *TxMemPool) AddTx(tx *tx.Tx, expires int) error

AddTx pushes a new TX into the MemPool and updates the priorities of any existing TX in the pool

func (*TxMemPool) GetTx

func (m *TxMemPool) GetTx() *tx.Tx

GetTx gets the next, most recent TX in the pool

func (*TxMemPool) Len

func (m *TxMemPool) Len() int

func (*TxMemPool) Less

func (m *TxMemPool) Less(i, j int) bool

func (*TxMemPool) Pop

func (m *TxMemPool) Pop() interface{}

func (*TxMemPool) Push

func (m *TxMemPool) Push(x interface{})

func (*TxMemPool) Swap

func (m *TxMemPool) Swap(i, j int)

type TxMsg

type TxMsg struct {
	Tx  *tx.Tx `msgpack:"t"`
	TTL int    `msgpack:"ttl"`
}

type VoteType

type VoteType uint8
const (
	VoteTypePreVote VoteType = iota + 1
	VoteTypePreCommit
	VoteTypeProposal
)

Jump to

Keyboard shortcuts

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