election

package
v0.0.0-...-967d326 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func InitializeNodes(t *protocol.Tree, f, g NodeHook)

InitializeNodes performs all the election specific initialization

func JobTopic

func JobTopic(roundID identity.ID, workerID identity.ID) string

JobTopic format a topic name for a given job and round

func ProposalTopic

func ProposalTopic(roundID identity.ID) string

ProposalTopic format a topic name for a new proposal

func ResultTopic

func ResultTopic(roundID identity.ID, label int) string

ResultTopic format a topic name for a given result

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 Job

type Job struct {
	InputProofs [][]byte
	Label       int
}

Job contains the

func (*Job) Encode

func (j *Job) Encode() []byte

Encode returns a marshalled job

type JobPool

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

JobPool schedules the jobs

func NewJobPool

func NewJobPool(ctx context.Context) *JobPool

NewJobPool returns a job pool object

func (*JobPool) AddJob

func (j *JobPool) AddJob(jobctx context.Context, task Task)

AddJob adds the job to the pool until it is completed. It assumes the job is well-formed.

func (*JobPool) DequeueProposal

func (j *JobPool) DequeueProposal(ctx context.Context) (*Proposal, error)

DequeueProposal returns a proposal waits for a proposal to be dequeued

func (*JobPool) EnqueueProposal

func (j *JobPool) EnqueueProposal(ctx context.Context, p *Proposal) error

EnqueueProposal enqueue a proposal in the channel

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 NewLeader

func NewLeader(r *Round) *Leader

NewLeader constructs a new leader

func (*Leader) ListenForProposal

func (l *Leader) ListenForProposal() error

ListenForProposal start an async loop fetching new proposal and enqueuing them

func (*Leader) MakeJobHandler

func (l *Leader) MakeJobHandler(n *Node) (Task, error)

MakeJobHandler returns a jobpool tasks that handle an aggregation job

func (*Leader) OnReadinessUpdateHook

func (l *Leader) OnReadinessUpdateHook() NodeHook

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

func (l *Leader) OnRootProofUpdateHook() NodeHook

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

func (l *Leader) PublishOnChain(aggregatedProof []byte)

PublishOnChain sends the aggregated proof on-chain

func (*Leader) Start

func (l *Leader) Start()

Start the leader routine

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) IsReady

func (n *Node) IsReady() bool

IsReady returns true if the node can start being aggregated

func (*Node) Job

func (n *Node) Job() *Job

Job provide a list of proofs to be aggregated

func (*Node) SetAggregateProof

func (n *Node) SetAggregateProof(aggregateProof []byte)

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 Proposal

type Proposal struct {
	ID       identity.ID
	Deadline time.Time
}

Proposal contains an data relative to an aggregation proposal

func (*Proposal) Encode

func (p *Proposal) Encode() []byte

Encode return a marshalled proposal

type Result

type Result struct {
	Result []byte
	Label  int
	ID     identity.ID
}

Result contains data relative to a result

func (*Result) Encode

func (r *Result) Encode() []byte

Encode returns a marshalled Result

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) Close

func (r *Round) Close()

Close terminate the round

func (*Round) GetLeaderID

func (r *Round) GetLeaderID() identity.ID

GetLeaderID returns the ID and position of the leader

func (*Round) Start

func (r *Round) Start()

Start run the Round

func (*Round) WaitForResult

func (r *Round) WaitForResult()

WaitForResult waits for the round aggregation result to be published on-chain

func (*Round) WithTopicProvider

func (r *Round) WithTopicProvider() *Round

WithTopicProvider add a topic provider in the Round object

type Task

type Task func(context.Context, *Proposal) error

Task is the function processing the job

type TopicProvider

type TopicProvider struct {
	Network network.PubSub
	Round   *Round
}

TopicProvider is a helper to interact with topics in a friendly way

func (*TopicProvider) JobTopic

func (t *TopicProvider) JobTopic(ctx context.Context, ID identity.ID) network.Topic

JobTopic returns the appropriate job topic

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

func (t *TopicProvider) ResultTopic(ctx context.Context, label int) network.Topic

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 NewWorker

func NewWorker(r *Round) *Worker

NewWorker returns a newly constructed worker

func (*Worker) Aggregate

func (w *Worker) Aggregate(job *Job) (*Result, error)

Aggregate performs an aggregation

func (*Worker) PublishProposal

func (w *Worker) PublishProposal() error

PublishProposal to alert the leader, we are ready

func (*Worker) Start

func (w *Worker) Start() error

Start the Worker routine

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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