cons

package
v1.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Consensus. Single instance of it.

Used sub-protocols (on the same thread):

  • DSS -- Distributed Schnorr Signature
  • ACS -- Asynchronous Common Subset

Used components (running on other threads):

  • Mempool
  • StateMgr
  • VM

> INPUT: baseAliasOutputID > ON Startup: > Start a DSS. > Ask Mempool for backlog (based on baseAliasOutputID). > Ask StateMgr for a virtual state (based on baseAliasOutputID). > UPON Reception of responses from Mempool, StateMgr and DSS NonceIndexes: > Produce a batch proposal. > Start the ACS. > UPON Reception of ACS output: > IF result is possible THEN > Submit agreed NonceIndexes to DSS. > Send the BLS partial signature. > ELSE > OUTPUT SKIP > UPON Reception of N-2F BLS partial signatures: > Start VM. > UPON Reception of VM Result: > IF result is non-empty THEN > Save the produced block to SM. > Submit the result hash to the DSS. > ELSE > OUTPUT SKIP > UPON Reception of VM Result and a signature from the DSS > IF rotation THEN > OUTPUT Signed Governance TX. > ELSE > Save the block to the StateMgr. > OUTPUT Signed State Transition TX

We move all the synchronization logic to separate objects (upon_...). They are responsible for waiting specific data and then triggering the next state action once. This way we hope to solve a lot of race conditions gracefully. The `upon` predicates and the corresponding done functions should not depend on each other. If some data is needed at several places, it should be passed to several predicates.

TODO: Handle the requests gracefully in the VM before getting the initTX. TODO: Reconsider the termination. Do we need to wait for DSS, RND?

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInputMempoolProposal

func NewInputMempoolProposal(requestRefs []*isc.RequestRef) gpa.Input

func NewInputMempoolRequests

func NewInputMempoolRequests(requests []isc.Request) gpa.Input

func NewInputProposal

func NewInputProposal(baseAliasOutput *isc.AliasOutputWithID) gpa.Input

func NewInputStateMgrBlockSaved

func NewInputStateMgrBlockSaved(block state.Block) gpa.Input

func NewInputStateMgrDecidedVirtualState

func NewInputStateMgrDecidedVirtualState(
	chainState state.State,
) gpa.Input

func NewInputStateMgrProposalConfirmed

func NewInputStateMgrProposalConfirmed() gpa.Input

func NewInputTimeData

func NewInputTimeData(timeData time.Time) gpa.Input

func NewInputVMResult

func NewInputVMResult(task *vm.VMTaskResult) gpa.Input

Types

type Cons

type Cons interface {
	AsGPA() gpa.GPA
}

func New

func New(
	chainID isc.ChainID,
	chainStore state.Store,
	me gpa.NodeID,
	mySK *cryptolib.PrivateKey,
	dkShare tcrypto.DKShare,
	processorCache *processors.Cache,
	instID []byte,
	nodeIDFromPubKey func(pubKey *cryptolib.PublicKey) gpa.NodeID,
	validatorAgentID isc.AgentID,
	log *logger.Logger,
) Cons

type Output

type Output struct {
	Status     OutputStatus
	Terminated bool
	//
	// Requests for other components.
	NeedMempoolProposal       *isc.AliasOutputWithID // Requests for the mempool are needed for this Base Alias Output.
	NeedMempoolRequests       []*isc.RequestRef      // Request payloads are needed from mempool for this IDs/Hash.
	NeedStateMgrStateProposal *isc.AliasOutputWithID // Query for a proposal for Virtual State (it will go to the batch proposal).
	NeedStateMgrDecidedState  *isc.AliasOutputWithID // Query for a decided Virtual State to be used by VM.
	NeedStateMgrSaveBlock     state.StateDraft       // Ask StateMgr to save the produced block.
	NeedVMResult              *vm.VMTask             // VM Result is needed for this (agreed) batch.
	//
	// Following is the final result.
	// All the fields are filled, if State == Completed.
	Result *Result
}

type OutputStatus

type OutputStatus byte
const (
	Running   OutputStatus = iota // Instance is still running.
	Completed                     // Consensus reached, TX is prepared for publication.
	Skipped                       // Consensus reached, no TX should be posted for this LogIndex.
)

func (OutputStatus) String

func (os OutputStatus) String() string

type Result

type Result struct {
	Transaction     *iotago.Transaction    // The TX for committing the block.
	BaseAliasOutput iotago.OutputID        // AO consumed in the TX.
	NextAliasOutput *isc.AliasOutputWithID // AO produced in the TX.
	Block           state.Block            // The state diff produced.
}

func (*Result) String

func (r *Result) String() string

type SyncACS

type SyncACS interface {
	StateProposalReceived(proposedBaseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages
	MempoolRequestsReceived(requestRefs []*isc.RequestRef) gpa.OutMessages
	DSSIndexProposalReceived(dssIndexProposal []int) gpa.OutMessages
	TimeDataReceived(timeData time.Time) gpa.OutMessages
	ACSOutputReceived(output gpa.Output) gpa.OutMessages
	String() string
}

func NewSyncACS

func NewSyncACS(
	inputsReadyCB func(baseAliasOutput *isc.AliasOutputWithID, requestRefs []*isc.RequestRef, dssIndexProposal []int, timeData time.Time) gpa.OutMessages,
	outputReadyCB func(output map[gpa.NodeID][]byte) gpa.OutMessages,
	terminatedCB func(),
) SyncACS

type SyncDSS

type SyncDSS interface {
	InitialInputReceived() gpa.OutMessages
	DSSOutputReceived(output gpa.Output) gpa.OutMessages
	DecidedIndexProposalsReceived(decidedIndexProposals map[gpa.NodeID][]int) gpa.OutMessages
	MessageToSignReceived(messageToSign []byte) gpa.OutMessages
	String() string
}

func NewSyncDSS

func NewSyncDSS(
	initialInputsReadyCB func() gpa.OutMessages,
	indexProposalReadyCB func(indexProposals []int) gpa.OutMessages,
	signingInputsReadyCB func(decidedIndexProposals map[gpa.NodeID][]int, messageToSign []byte) gpa.OutMessages,
	outputReadyCB func(signature []byte) gpa.OutMessages,
) SyncDSS

type SyncMP

type SyncMP interface {
	BaseAliasOutputReceived(baseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages
	ProposalReceived(requestRefs []*isc.RequestRef) gpa.OutMessages
	RequestsNeeded(requestRefs []*isc.RequestRef) gpa.OutMessages
	RequestsReceived(requests []isc.Request) gpa.OutMessages
	String() string
}

func NewSyncMP

func NewSyncMP(
	proposalInputsReadyCB func(baseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages,
	proposalReceivedCB func(requestRefs []*isc.RequestRef) gpa.OutMessages,
	requestsNeededCB func(requestIDs []*isc.RequestRef) gpa.OutMessages,
	requestsReceivedCB func(requests []isc.Request) gpa.OutMessages,
) SyncMP

type SyncRND

type SyncRND interface {
	CanProceed(dataToSign []byte) gpa.OutMessages
	BLSPartialSigReceived(sender gpa.NodeID, partialSig []byte) gpa.OutMessages
}

func NewSyncRND

func NewSyncRND(
	blsThreshold int,
	inputsReadyCB func(dataToSign []byte) gpa.OutMessages,
	sigSharesReadyCB func(dataToSign []byte, sigShares map[gpa.NodeID][]byte) (bool, gpa.OutMessages),
) SyncRND

type SyncSM

type SyncSM interface {
	//
	// State proposal.
	ProposedBaseAliasOutputReceived(baseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages
	StateProposalConfirmedByStateMgr() gpa.OutMessages
	//
	// Decided state.
	DecidedVirtualStateNeeded(decidedBaseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages
	DecidedVirtualStateReceived(chainState state.State) gpa.OutMessages
	//
	// Save the block.
	BlockProduced(producedBlock state.StateDraft) gpa.OutMessages
	BlockSaved(savedBlock state.Block) gpa.OutMessages
	//
	// Supporting stuff.
	String() string
}

func NewSyncSM

func NewSyncSM(
	stateProposalQueryInputsReadyCB func(baseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages,
	stateProposalReceivedCB func(proposedAliasOutput *isc.AliasOutputWithID) gpa.OutMessages,
	decidedStateQueryInputsReadyCB func(decidedBaseAliasOutput *isc.AliasOutputWithID) gpa.OutMessages,
	decidedStateReceivedCB func(chainState state.State) gpa.OutMessages,
	saveProducedBlockInputsReadyCB func(producedBlock state.StateDraft) gpa.OutMessages,
	saveProducedBlockDoneCB func(savedBlock state.Block) gpa.OutMessages,
) SyncSM

type SyncTX

type SyncTX interface {
	VMResultReceived(vmResult *vm.VMTaskResult) gpa.OutMessages
	SignatureReceived(signature []byte) gpa.OutMessages
	BlockSaved(block state.Block) gpa.OutMessages
	String() string
}

func NewSyncTX

func NewSyncTX(inputsReadyCB func(vmResult *vm.VMTaskResult, block state.Block, signature []byte) gpa.OutMessages) SyncTX

type SyncVM

type SyncVM interface {
	DecidedBatchProposalsReceived(aggregatedProposals *bp.AggregatedBatchProposals) gpa.OutMessages
	DecidedStateReceived(chainState state.State) gpa.OutMessages
	RandomnessReceived(randomness hashing.HashValue) gpa.OutMessages
	RequestsReceived(requests []isc.Request) gpa.OutMessages
	VMResultReceived(vmResult *vm.VMTaskResult) gpa.OutMessages
	String() string
}

func NewSyncVM

func NewSyncVM(
	inputsReadyCB func(aggregatedProposals *bp.AggregatedBatchProposals, chainState state.State, randomness *hashing.HashValue, requests []isc.Request) gpa.OutMessages,
	outputReadyCB func(output *vm.VMTaskResult) gpa.OutMessages,
) SyncVM

Directories

Path Synopsis
The purpose of this package is to run the consensus protocol as a goroutine and communicate with all the related components.
The purpose of this package is to run the consensus protocol as a goroutine and communicate with all the related components.

Jump to

Keyboard shortcuts

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