selection

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: MIT Imports: 14 Imported by: 0

README

Selection

Abstract

Block Generators (a role taken outside of the Provisioner) participate in a non-interactive lottery to be able to forge a candidate block. In order to decide which Block to select among the various candidates, the Block Generators propagate a score associated with their candidate block, which is the result of the lottery run in a non-interactive fashion. Together with the score, the Block Generators publish a zero-knowledge proof of correctness of the score computation according to the rules outlined in the Blind Bid algorithm (LINK HERE).

The Score Selector is the component appointed to collect the scores, verify the zero-knowledge proof thereto associated and to propagate the block hash associated with the highest score observed during a period of time denoted as timeLength. The block hash is then forwarded to the EventBus to be picked up by the Block Reducer

Values

Score Message
Field Type
score uint256
proof proof
identity hash uint256
bid list []byte (variable size)
seed BLS signature
previous block hash uint256
candidate block hash uint256

Architecture

The Selector is triggered by a Generation message, which denotes the reset of the consensus loop. Upon receiving this message, the Selector will start a timer. Between the start and the expiry of the timer, the Selector will enable streaming of Score events. Any time a Score event is received, it goes through this processing flow:

  1. Check if the event score is higher than the current bestEvent. If not, the flow ends here.
  2. Verify the proof, included in the Score event. If the verification fails, the flow ends here.
  3. The Score event is repropagated to the network.
  4. The bestEvent will now be set to the new Score event.

The purpose of this processing flow is to have the Score event with the highest score in memory when the timer expires. Once this timer expires, the selector will pause event streaming, and publish this Score event internally, under the BestScore topic.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory added in v0.2.0

type Factory struct {
	Bus eventbus.Broker
	// contains filtered or unexported fields
}

Factory creates the selection component.

func NewFactory added in v0.2.0

func NewFactory(bus eventbus.Broker, timeout time.Duration) *Factory

NewFactory instantiates a Factory.

func (*Factory) Instantiate added in v0.2.0

func (f *Factory) Instantiate() consensus.Component

Instantiate a Selector and return it. Implements consensus.ComponentFactory.

type Handler added in v0.2.0

type Handler interface {
	Verify(message.Score) error
	ResetThreshold()
	LowerThreshold()
	Priority(message.Score, message.Score) bool
}

Handler is an abstraction of the selection component event handler. It is primarily used for testing purposes, to bypass the zkproof verification.

type Helper added in v0.2.0

type Helper struct {
	*Factory
	BidList  user.BidList
	Selector *Selector
	*consensus.SimplePlayer

	BestScoreChan chan message.Message
	// contains filtered or unexported fields
}

Helper for reducing selection test boilerplate

func NewHelper added in v0.2.0

func NewHelper(eb *eventbus.EventBus) *Helper

NewHelper creates a Helper

func (*Helper) Initialize added in v0.2.0

func (h *Helper) Initialize(ru consensus.RoundUpdate)

Initialize the selector with the given round update.

func (*Helper) SendBatch added in v0.2.0

func (h *Helper) SendBatch(hash []byte)

SendBatch generates a batch of score events and sends them to the selector.

func (*Helper) SetHandler added in v0.2.0

func (h *Helper) SetHandler(handler Handler)

SetHandler sets the handler on the Selector. Used for bypassing zkproof verification calls during tests.

func (*Helper) Spawn added in v0.2.0

func (h *Helper) Spawn(hash []byte) []message.Score

Spawn a set of score events.

func (*Helper) StartSelection added in v0.2.0

func (h *Helper) StartSelection()

StartSelection forces the Selector to start the selection

type ScoreHandler added in v0.2.0

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

ScoreHandler manages the score threshold, performs verification of message.Score, keeps tab of the highest score so far

func NewScoreHandler added in v0.2.0

func NewScoreHandler(bidList user.BidList) *ScoreHandler

NewScoreHandler returns a new instance if ScoreHandler

func (*ScoreHandler) LowerThreshold added in v0.2.0

func (sh *ScoreHandler) LowerThreshold()

LowerThreshold lowers the threshold after a timespan when no BlockGenerator could send a valid score

func (*ScoreHandler) Priority added in v0.2.0

func (sh *ScoreHandler) Priority(first, second message.Score) bool

Priority returns true if the first element has priority over the second, false otherwise

func (*ScoreHandler) ResetThreshold added in v0.2.0

func (sh *ScoreHandler) ResetThreshold()

ResetThreshold resets the score threshold that sets the absolute minimum for a score to be eligible for sending

func (*ScoreHandler) Verify added in v0.2.0

func (sh *ScoreHandler) Verify(m message.Score) error

Verify a score by delegating the ZK library to validate the proof

type Selector added in v0.2.0

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

Selector is the component responsible for collecting score events and propagating the best one after a timeout.

func NewComponent added in v0.2.0

func NewComponent(publisher eventbus.Publisher, timeout time.Duration) *Selector

NewComponent creates and launches the component which responsibility is to validate and select the best score among the blind bidders. The component publishes under the topic BestScoreTopic

func (*Selector) CollectGeneration added in v0.2.0

func (s *Selector) CollectGeneration(packet consensus.InternalPacket) error

CollectGeneration signals the selection start by triggering `EventPlayer.Play`

func (*Selector) CollectScoreEvent added in v0.2.0

func (s *Selector) CollectScoreEvent(packet consensus.InternalPacket) error

CollectScoreEvent checks the score of an incoming Event and, in case it has a higher score, verifies, propagates and saves it

func (*Selector) Finalize added in v0.2.0

func (s *Selector) Finalize()

Finalize pauses event streaming and stops the timer. Implements consensus.Component.

func (*Selector) ID added in v0.2.0

func (s *Selector) ID() uint32

ID returns the ID of the Score message Listener. Implements consensus.Component

func (*Selector) IncreaseTimeOut added in v0.2.0

func (s *Selector) IncreaseTimeOut()

IncreaseTimeOut increases the timeout after a failed selection

func (*Selector) Initialize added in v0.2.0

func (s *Selector) Initialize(eventPlayer consensus.EventPlayer, signer consensus.Signer, r consensus.RoundUpdate) []consensus.TopicListener

Initialize the Selector, by creating the handler and returning the needed Listeners. Implements consensus.Component.

Jump to

Keyboard shortcuts

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