Skip to content

Instantly share code, notes, and snippets.

@Wondertan
Last active May 6, 2023 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wondertan/02ac82f73cd6f17d43a0e8de072f1dc4 to your computer and use it in GitHub Desktop.
Save Wondertan/02ac82f73cd6f17d43a0e8de072f1dc4 to your computer and use it in GitHub Desktop.
Interfaces for heterogenous consensus algorigthms over p2p network.
// ProposalData is arbitrary data that Proposers agree on.
//
// Alternative names: consensus.Data, Contract, or can remove alias altogether.
type ProposalData = []byte
// ValidatorFunc validates the ProposalData and reports back to the Concord
// Q: Verify vs Validate? Quick googling suggests that Validate suits better, but might be wrong.
type ValidatorFunc func(context.Context, ProposalData) (bool, error)
// ProposeFunc builds ProposalData.
// Concord invokes it when selected to propose within Group.
//
// Alternative names: BuildFunc.
type ProposeFunc func(context.Context) (ProposalData, error)
// Conciliator manages and allows joining multiple Concords or in other words
// participate in multiple consensuses.
//
// Alternative names: consensus.Orchestrator, consensus.Ensemble, consensus.Swarm
type Conciliator interface {
// JoinConcord joins Concord by the ConcordID.
//
// Finds other peers partipating in the Concord by the ID.
// Does not require to be in the active validator set to join.
//
// Alternative names: Participate
JoinConcord(ConcordID, BuilderFunc, ...ValidatorFunc) (Concord, error)
}
// ConcordID identifies a Concord.
type ConcordID string
// AgreeOptions defines a set of *optional* actions for Concord
// to perform during an AgreeWith round.
// Might become functional options.
type AgreeOptions struct {
// ExtensionData enables *each* Member to inject application data to Commitment
// In constrast, ProposalData is uniqly produced only by one Member within AgreeWith round,
// while each Member can add ExtensionData within AgreeWith round.
ExtensionData []byte
// ExtensionValidatorFunc validates ExtensionData of each Member within AgreeWith round.
ExtensionValidatorFunc func(Member, []data) (bool, error)
// Experimantal Ideas:
// Allows overriding global ValidatorFunc for an AgreeWith round.
ValidatorFunc
// Allows overriding global ProposeFunc for an AgreeWith round.
ProposeFunc
}
// Concord defines consensus process.
// It actively listens for network message and passively participates in consensus in the backgound,
// unless AgreeWith is called.
//
// Alternative names: Consensus,
type Concord interface {
// ID reports ConcordID of the Concord instance.
ID() ConcordID
// AgreeWith reaches the consensus with the Group
// and as a result produces ProposalData wrapped with a group Commitment over it.
//
// Alternative names: CommitWith, Commit.
//
// IDEA: Design AgreeWith(Group, data) (Commitment, error) around vote extension
// so that every validator is expected to submit data each round.
AgreeWith(context.Context, Group, AgreeOptions) (Commitment, error)
// Potential other methods:
// * VerifyCommitment
}
// Group defines a group of consensus/concord Members eligible to produce ProposalData
// and committed to its tegridy.
// Alternative names: Proposers
// TODO: Needs revision for compatibility with Secret Leader Election.
type Group interface {
// Next requests next Member selected for PropodalData.
Next() Member
// List all the eligible Group members.
List() []Member
}
// Member is eligible member of the Group committed to produce and verify ProposalData.
// NOTE: Taken from Callum's proposal
type Member interface {
// ID reports Member idnetifier.
ID() string
// Weight reports weight/voting power of the member.
Weight() float64
// TODO: Define types for Signatures.
// Verify checks if the Member signed given message.
Verify(msg, sig []byte) bool
}
// Commitment is a Grop commitment to the ProposalData.
type Commitment interface {
// ProposalData reports the ProposalData Grouped commited to.
ProposalData() ProposalData
// ExtensionData provides a map for data each or some of Members submitted within AgreeWith round.
ExtensionData() map[Member][]byte
// TODO: Define types for Signatures.
Signatures() []byte
}
// NOTES:
// * No internal height tracking needed in this proposal, keeping it completely blochain application user concern.
// * Enables clear PBS(Proposal Builder Separation) via ProposeFunc
// * p2p is a concern of lower layer.
// * Keeeps Voting and Lock-and-Commit as implementation details.
// * We may define a lower layer interface for Lock-and-Commit paradigm consensus.
// * Enables immediate/deferred and optimistic executions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment