Documentation
¶
Index ¶
- Variables
- func InitializeNodes(t *protocol.Tree, f, g NodeHook)
- func JobTopic(roundID identity.ID, workerID identity.ID) string
- func ProposalTopic(roundID identity.ID) string
- func ResultTopic(roundID identity.ID, label int) string
- type BatchPubSub
- type Job
- type JobPool
- type Leader
- type MarshalledJob
- type MarshalledProposal
- type MarshalledResult
- type MockBatchPS
- type MockBlockchain
- type Node
- type NodeHook
- type Participant
- type Proposal
- type Result
- type Round
- type Task
- type TopicProvider
- func (t *TopicProvider) JobTopic(ctx context.Context, ID identity.ID) network.Topic
- func (t *TopicProvider) ProposalTopic(ctx context.Context) network.Topic
- func (t *TopicProvider) PublishJob(j *Job, ID identity.ID) error
- func (t *TopicProvider) PublishProposal(p *Proposal) error
- func (t *TopicProvider) PublishResult(r *Result) error
- func (t *TopicProvider) ResultTopic(ctx context.Context, label int) network.Topic
- type Worker
Constants ¶
This section is empty.
Variables ¶
var ( // TopicPath is the basis of every topic used by this protocol TopicPath = "boojum.protocol.election" // ProposalTopicPath is the base string used for the proposals ProposalTopicPath string // ResultTopicPath is the base string used for the aggregation results ResultTopicPath string // JobTopicPath is the base string used for the aggregation requests JobTopicPath string )
Functions ¶
func InitializeNodes ¶
InitializeNodes performs all the election specific initialization
func ProposalTopic ¶
ProposalTopic format a topic name for a new proposal
Types ¶
type BatchPubSub ¶
type BatchPubSub interface {
// PublishAggregated publish the proof aggregate on the blockchain
// It should be no fail
PublishAggregated(context.Context, []byte) error
// NextNewBatch waits and returns the next new batch.
NextNewBatch(context.Context) ([][]byte, error)
// NextBatchDone block and waits untils the current aggregation step is over.
NextBatchDone(context.Context) error
}
BatchPubSub is the blockchain interface of participant
type JobPool ¶
type JobPool struct {
// contains filtered or unexported fields
}
JobPool schedules the jobs
func NewJobPool ¶
NewJobPool returns a job pool object
func (*JobPool) AddJob ¶
AddJob adds the job to the pool until it is completed. It assumes the job is well-formed.
func (*JobPool) DequeueProposal ¶
DequeueProposal returns a proposal waits for a proposal to be dequeued
type Leader ¶
type Leader struct {
JobPool *JobPool
Tree *protocol.Tree // Root of the aggregation tree
Round *Round
// contains filtered or unexported fields
}
Leader is a control struct that schedule the aggregation process
func (*Leader) ListenForProposal ¶
ListenForProposal start an async loop fetching new proposal and enqueuing them
func (*Leader) MakeJobHandler ¶
MakeJobHandler returns a jobpool tasks that handle an aggregation job
func (*Leader) OnReadinessUpdateHook ¶
OnReadinessUpdateHook returns a HookOnReadinessUpdate that sends a new job to the pool if ready It is automaticallt triggered by Node when all its children are completed
func (*Leader) OnRootProofUpdateHook ¶
OnRootProofUpdateHook returns a hook that is triggered when setting a value to the root node's aggregated proof Taking action to publish it on-chain
func (*Leader) PublishOnChain ¶
PublishOnChain sends the aggregated proof on-chain
type MarshalledJob ¶
type MarshalledJob []byte
MarshalledJob is an alias for encoded proposal
func (MarshalledJob) Decode ¶
func (m MarshalledJob) Decode() (*Job, error)
Decode returns an unmarshalled Job
type MarshalledProposal ¶
type MarshalledProposal []byte
MarshalledProposal is an alias for encoded proposal
func (MarshalledProposal) Decode ¶
func (m MarshalledProposal) Decode() (*Proposal, error)
Decode attemps at returning an unmarshalled proposal
type MarshalledResult ¶
type MarshalledResult []byte
MarshalledResult is an alias for encoded proposal
func (MarshalledResult) Decode ¶
func (m MarshalledResult) Decode() (*Result, error)
Decode returns an unmarshalled Result
type MockBatchPS ¶
type MockBatchPS struct {
// contains filtered or unexported fields
}
MockBatchPS is a mock for blockchain agent
func (*MockBatchPS) NextBatchDone ¶
func (b *MockBatchPS) NextBatchDone(ctx context.Context) error
NextBatchDone blocks until any agent triggers publish aggregated
func (*MockBatchPS) NextNewBatch ¶
func (b *MockBatchPS) NextNewBatch(ctx context.Context) ([][]byte, error)
NextNewBatch blocks until a new batch is available
func (*MockBatchPS) PublishAggregated ¶
func (b *MockBatchPS) PublishAggregated(ctx context.Context, aggregated []byte) error
PublishAggregated publish that a new batch have been aggregated
type MockBlockchain ¶
type MockBlockchain struct {
// contains filtered or unexported fields
}
MockBlockchain simulate a blockchain for tests
func NewMockBlockchain ¶
func NewMockBlockchain(batch [][]byte) *MockBlockchain
NewMockBlockchain returns a mock of a blockchain
func (*MockBlockchain) CreateAgent ¶
func (m *MockBlockchain) CreateAgent() *MockBatchPS
CreateAgent builds a new agent and link it to the others
func (*MockBlockchain) NewBatch ¶
func (m *MockBlockchain) NewBatch()
NewBatch builds a new agent and link it to the others
func (*MockBlockchain) PublishAggregated ¶
func (m *MockBlockchain) PublishAggregated() error
PublishAggregated builds a new agent and link it to the others
type Node ¶
type Node struct {
Tree *protocol.Tree
Label int
AggregateProof []byte
Topic network.Topic
// contains filtered or unexported fields
}
Node contains data for each node of the aggregation tree
func (*Node) IncrementReadiness ¶
func (n *Node) IncrementReadiness()
IncrementReadiness update the readiness of the node
func (*Node) SetAggregateProof ¶
SetAggregateProof set the aggregation field and update the readiness of its parent
type NodeHook ¶
type NodeHook func(n *Node)
NodeHook is function that is trigerred by the tree when we update its readiness We choose to apply a hook injection pattern because we don't implement control logic here The NodeHook SHOULD NOT have access to the mutex
type Participant ¶
type Participant struct {
ID identity.ID
MemberProvider protocol.MemberProvider
Network net.PubSub
BatchPubSub BatchPubSub
Aggregator aggregator.Aggregator
// contains filtered or unexported fields
}
Participant is the higher level protocol struct
func NewParticipant ¶
func NewParticipant( ctx context.Context, id identity.ID, aggregator aggregator.Aggregator, memberProvider protocol.MemberProvider, batchPubSub BatchPubSub, network net.PubSub, ) *Participant
NewParticipant ..
func (*Participant) Start ¶
func (par *Participant) Start()
Start the main routine of the participant
type Round ¶
type Round struct {
ID identity.ID
Batch [][]byte
Participant *Participant
Members protocol.IDList
TopicProvider *TopicProvider
// contains filtered or unexported fields
}
Round encompasses the computation made in a single
func NewRound ¶
func NewRound(ctx context.Context, par *Participant, batch [][]byte) *Round
NewRound construct a new round
func (*Round) GetLeaderID ¶
GetLeaderID returns the ID and position of the leader
func (*Round) WaitForResult ¶
func (r *Round) WaitForResult()
WaitForResult waits for the round aggregation result to be published on-chain
func (*Round) WithTopicProvider ¶
WithTopicProvider add a topic provider in the Round object
type TopicProvider ¶
TopicProvider is a helper to interact with topics in a friendly way
func (*TopicProvider) ProposalTopic ¶
func (t *TopicProvider) ProposalTopic(ctx context.Context) network.Topic
ProposalTopic returns the appropriate result topic
func (*TopicProvider) PublishJob ¶
func (t *TopicProvider) PublishJob(j *Job, ID identity.ID) error
PublishJob to make a worker do it
func (*TopicProvider) PublishProposal ¶
func (t *TopicProvider) PublishProposal(p *Proposal) error
PublishProposal to alert the leader, we are ready
func (*TopicProvider) PublishResult ¶
func (t *TopicProvider) PublishResult(r *Result) error
PublishResult to alert a leader that we are done
func (*TopicProvider) ResultTopic ¶
ResultTopic in the appropriate result topic
type Worker ¶
type Worker struct {
Round *Round
Timeout time.Duration // Timeout in second for a proposal
// contains filtered or unexported fields
}
Worker contains all the logic required to aggregate the proofs
func (*Worker) PublishProposal ¶
PublishProposal to alert the leader, we are ready