consensus

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 24 Imported by: 0

README

Consensus

This package implements all needed components to run the SBA* consensus algorithm in isolation. This means, that all the "pieces" of the consensus are housed within this package, including communication infrastructure and testing frameworks. However, it still needs to be put together in order to have a fully running consensus. This code is defined in the loop package in this repo.

Values

Message Header
Field Type
pubkeyBLS BLS Signature
round uint64
step uint64
blockhash uint256

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitAcceptedBlockUpdate

func InitAcceptedBlockUpdate(subscriber eventbus.Subscriber) (chan block.Block, uint32)

InitAcceptedBlockUpdate init listener to get updates about lastly accepted block in the chain.

func MockMember added in v0.2.0

func MockMember(keys key.Keys) *user.Member

MockMember mocks a Provisioner.

func MockNewBlockMsg added in v0.4.4

func MockNewBlockMsg(t *testing.T, hdr *header.Header) message.Message

MockNewBlockMsg ...

func MockProvisioners added in v0.2.0

func MockProvisioners(amount int) (*user.Provisioners, []key.Keys)

MockProvisioners mock a Provisioner set.

func WithFields added in v0.4.4

func WithFields(round uint64, step uint8, eventName string, hash,
	blsPubKey []byte, sVotingCommittee *user.VotingCommittee,
	sVotedCommittee *sortedset.Cluster, p *user.Provisioners,
) *log.Entry

WithFields builds a list of common Consensus logging fields. It also adds extra fields for TraceLevel only.

Types

type CandidateVerificationFunc added in v0.4.0

type CandidateVerificationFunc func(context.Context, block.Block) error

CandidateVerificationFunc is a callback used to verify candidate blocks after the conclusion of the first reduction step.

type ControlFn added in v0.4.0

type ControlFn func(context.Context, *Queue, <-chan message.Message, <-chan message.Message, RoundUpdate) Results

ControlFn represents the asynchronous loop controlling the commencement of the Phase transition.

type Controller added in v0.4.0

type Controller interface {
	// GetControlFn returns a ControlFn.
	GetControlFn() ControlFn
}

Controller is a factory for the ControlFn. It basically relates to the Agreement, which needs a different execution each round.

type Emitter added in v0.4.0

type Emitter struct {
	EventBus    *eventbus.EventBus
	RPCBus      *rpcbus.RPCBus
	Keys        key.Keys
	TimerLength time.Duration
}

Emitter is a simple struct to pass the communication channels that the steps should be able to emit onto.

func MockEmitter added in v0.4.0

func MockEmitter(consTimeout time.Duration) *Emitter

MockEmitter is a utility to quickly wire up an emitter in tests.

func StupidEmitter added in v0.4.0

func StupidEmitter() (*Emitter, *user.Provisioners)

StupidEmitter ...

func (*Emitter) Gossip added in v0.4.0

func (e *Emitter) Gossip(msg message.Message) error

Gossip concatenates the topic, the header and the payload, and gossips it to the rest of the network.

func (*Emitter) Kadcast added in v0.4.3

func (e *Emitter) Kadcast(msg message.Message) error

Kadcast propagates a message in Kadcast network.

func (*Emitter) Republish added in v0.4.3

func (e *Emitter) Republish(msg message.Message) error

Republish reroutes message propagation to either Gossip or Kadcast network.

func (*Emitter) Sign added in v0.4.0

func (e *Emitter) Sign(h header.Header) ([]byte, error)

Sign a header.

type ExecuteTxsFunc added in v0.4.4

type ExecuteTxsFunc func(ctx context.Context, txs []transactions.ContractCall, blockHeight uint64, gasLimit uint64, generator []byte) ([]transactions.ContractCall, []byte, error)

ExecuteTxsFunc is a callback used to retrieve a valid set of txs.

type InternalPacket added in v0.3.0

type InternalPacket interface {
	payload.Safe
	State() header.Header
}

InternalPacket is a specialization of the Payload of message.Message. It is used to unify messages used by the consensus, which need to carry the header.Header for consensus specific operations.

type Phase added in v0.4.0

type Phase interface {
	// Initialize accepts as an
	// argument an interface, usually a message or the result  of the state
	// function execution. It provides the capability to create a closure of sort.
	Initialize(InternalPacket) PhaseFn
}

Phase is used whenever an instantiation is needed.

func MockPhase added in v0.4.0

func MockPhase(cb func(ctx context.Context) bool) Phase

MockPhase mocks up a consensus phase. It accepts a (recursive) function which returns a boolean indicating whether the consensus loop needs to return, or an error. If function returns true, it halts the consensus loop. An error indicates unrecoverable situation.

type PhaseFn added in v0.4.0

type PhaseFn interface {
	// Run the phase function.
	Run(context.Context, *Queue, chan message.Message, chan message.Message, RoundUpdate, uint8) PhaseFn

	// String returns the description of this phase function.
	String() string
}

PhaseFn represents the recursive consensus state function.

type Publisher added in v0.4.0

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

Publisher is used to direct consensus messages from the peer.MessageProcessor to the consensus components.

func NewPublisher added in v0.4.0

func NewPublisher(publisher eventbus.Publisher) *Publisher

NewPublisher returns an initialized Publisher.

func (*Publisher) Process added in v0.4.0

func (p *Publisher) Process(srcPeerID string, msg message.Message) ([]bytes.Buffer, error)

Process incoming consensus messages. Satisfies the peer.ProcessorFunc interface.

type Queue added in v0.2.0

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

Queue is a Queue of Events grouped by rounds and steps. It is thread-safe through a sync.RWMutex. TODO: entries should become buntdb instead.

func NewQueue added in v0.2.0

func NewQueue() *Queue

NewQueue creates a new Queue. It is primarily used by Collectors to temporarily store messages not yet relevant to the collection process.

func (*Queue) Clear added in v0.2.0

func (eq *Queue) Clear(round uint64)

Clear the queue. This method swaps the internal `entries` map, to avoid a situation where memory is continuously allocated and never freed.

func (*Queue) Flush added in v0.2.0

func (eq *Queue) Flush(round uint64) []message.Message

Flush all events stored for a specific round from the queue, and return them Messages are sorted giving priority to AggrAgreement and then to their step.

func (*Queue) GetEvents added in v0.2.0

func (eq *Queue) GetEvents(round uint64, step uint8) []message.Message

GetEvents returns the events for a round and step.

func (*Queue) PutEvent added in v0.2.0

func (eq *Queue) PutEvent(round uint64, step uint8, m message.Message)

PutEvent stores an Event at a given round and step.

type Results added in v0.4.0

type Results struct {
	Blk block.Block
	Err error
}

Results carries the eventual consensus results.

type RoundUpdate added in v0.2.0

type RoundUpdate struct {
	Round           uint64
	P               user.Provisioners
	Seed            []byte
	Hash            []byte
	LastCertificate *block.Certificate
	Timestamp       int64
}

RoundUpdate carries the data about the new Round, such as the active Provisioners, the BidList, the Seed and the Hash. TODO: consider replacing most of the fields with a full copy of most recent block.

func MockRoundUpdate added in v0.2.0

func MockRoundUpdate(round uint64, p *user.Provisioners) RoundUpdate

MockRoundUpdate mocks a round update.

func (RoundUpdate) Copy added in v0.4.0

func (r RoundUpdate) Copy() payload.Safe

Copy complies with message.Safe interface. It returns a deep copy of the message safe to publish to multiple subscribers.

type TestCallback added in v0.4.0

TestCallback is a callback to allow for table testing based on step results.

type TestPhase added in v0.4.0

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

TestPhase is the phase to inject in the step under test to allow for table testing. It treats the packet injected through the Fn method as the result to test.

func NewTestPhase added in v0.4.0

func NewTestPhase(t *testing.T, callback TestCallback, streamer *eventbus.GossipStreamer, aChan chan message.Message) *TestPhase

NewTestPhase returns a Phase implementation suitable for testing steps.

func (*TestPhase) Initialize added in v0.4.0

func (t *TestPhase) Initialize(sv InternalPacket) PhaseFn

Initialize is used by the step under test to provide its result.

func (*TestPhase) Run added in v0.4.0

func (t *TestPhase) Run(_ context.Context, queue *Queue, _, _ chan message.Message, _ RoundUpdate, step uint8) PhaseFn

Run does nothing else than delegating to the specified callback.

func (*TestPhase) String added in v0.4.0

func (t *TestPhase) String() string

Jump to

Keyboard shortcuts

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