selection

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: MIT Imports: 17 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

func MarshalScore added in v0.2.0

func MarshalScore(r *bytes.Buffer, ev wire.Event) error

MarshalScore the buffer into a committee Event Field order is the following: * Blind Bid Fields [Score, Proof, Z, BidList, Seed, Candidate Block Hash]

func MockSelectionEventBuffer

func MockSelectionEventBuffer(hash []byte) *bytes.Buffer

MockSelectionEventBuffer mocks a Selection event, marshals it, and returns the resulting buffer.

func UnmarshalScore added in v0.2.0

func UnmarshalScore(r *bytes.Buffer, ev wire.Event) error

UnmarshalScore unmarshals the buffer into a Score Event Field order is the following: * Score Payload [score, proof, Z, BidList, Seed, Block Candidate Hash]

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(Score) error
	ResetThreshold()
	LowerThreshold()
	Priority(Score, 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 bytes.Buffer
	// 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) GenerateEd25519Fields added in v0.2.0

func (h *Helper) GenerateEd25519Fields(ev consensus.Event) []byte

GenerateEd25519Fields will return the Ed25519 header fields for a given consensus event.

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) []consensus.Event

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 Score added in v0.2.0

type Score struct {
	Score         []byte
	Proof         []byte
	Z             []byte
	BidListSubset []byte
	PrevHash      []byte
	Seed          []byte
	VoteHash      []byte
}

Score represents the Score Message with the fields consistent with the Blind Bid data structure

func MockSelectionEvent

func MockSelectionEvent(hash []byte) *Score

MockSelectionEvent mocks a Selection event and returns it.

func (Score) Equal added in v0.2.0

func (e Score) Equal(ev wire.Event) bool

Equal as specified in the Event interface

func (Score) Sender added in v0.2.0

func (e Score) Sender() []byte

Sender of a Score event is the anonymous Z

type ScoreHandler added in v0.2.0

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

func NewScoreHandler added in v0.2.0

func NewScoreHandler(bidList user.BidList) *ScoreHandler

func (*ScoreHandler) LowerThreshold added in v0.2.0

func (sh *ScoreHandler) LowerThreshold()

func (*ScoreHandler) Priority added in v0.2.0

func (sh *ScoreHandler) Priority(first, second 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()

func (*ScoreHandler) Verify added in v0.2.0

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

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(e consensus.Event) error

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

func (*Selector) CollectScoreEvent added in v0.2.0

func (s *Selector) CollectScoreEvent(e consensus.Event) 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