README ¶
Reduction components
This package defines the components for both the first and second step of reduction individually, as specified in the Binary Reduction Phase of the SBA* consensus protocol.
Due to small, but intricate differences between the two steps, the components are defined individually, with a minimal amount of shared code. This was done in an effort to increase readability, since it avoids massive amounts of abstraction which, on earlier iterations of the package, caused some confusion for readers. That said, code which is identical across the two components is defined in the top-level of the package, and imported down.
Values
Block Reduction Event
Field | Type |
---|---|
signedblockhash | BLS Signature |
Architecture
At the core, a Reducer
works like this:
- It gets triggered by a call to the
Run
function. This instantiates anAggregator
, starts a timer, and gossips aReduction
message (using the provided keys on startup) - The queue is flushed, and it starts collecting Reduction messages, passing them down to the
Aggregator
- When the
Aggregator
reaches quorum, or when the timer is triggered, theReducer
will return a message - The component is then finished and waits for the next call to
Run
Differences between the two components
Since there are subtle differences in the actions that need to be taken per step, the reducers have been split up in a first step and second step. Between the two, these differences can be found:
- Upon reaching quorum, the first step reducer will attempt to retrieve the candidate block corresponding to the winning hash (either through the DB or the network), and attempt to verify it, to make sure it's okay to continue voting on this block for the second step
- When reaching quorum, the first step reducer will return a
StepVotes
message, which is passed on to the second step reducer. The second step reducer will instead gossip anAgreement
message, using the combinedStepVotes
of the first and second step to create a certificate. The second step reducer does not return anything
Aggregator
Each Reducer
makes use of an Aggregator
, which is a component akin to a storage for incoming messages. The Aggregator
will receive any incoming Reduction messages after they are filtered by the Reducer
. It will separate messages by their block hash, and proceed to aggregate the included signedblockhash
with other collected signatures for this hash (if any). Additionally, it saves the senders BLS public key in a sortedset.Set
. Once the amount of keys and signatures for a certain blockhash exceeds a threshold, the Aggregator
will return the collected information.
Documentation ¶
Index ¶
- Variables
- func PrepareSendReductionTest(hlp *Helper, stepFn consensus.PhaseFn) func(t *testing.T)
- func ShouldProcess(m message.Message, round uint64, step uint8, queue *consensus.Queue) bool
- type Aggregator
- type Handler
- func (b *Handler) AmMember(round uint64, step uint8) bool
- func (b *Handler) Committee(round uint64, step uint8) user.VotingCommittee
- func (b *Handler) IsMember(pubKeyBLS []byte, round uint64, step uint8) bool
- func (b *Handler) Quorum(round uint64) int
- func (b *Handler) VerifySignature(red message.Reduction) error
- func (b *Handler) VotesFor(pubKeyBLS []byte, round uint64, step uint8) int
- type Helper
- func (hlp *Helper) FailOnVerification(flag bool)
- func (hlp *Helper) ProcessCandidateVerificationRequest(blk block.Block) error
- func (hlp *Helper) Spawn(hash []byte, round uint64, step uint8) []message.Reduction
- func (hlp *Helper) Verify(hash []byte, sv message.StepVotes, round uint64, step uint8) error
- type Reduction
- type Result
Constants ¶
This section is empty.
Variables ¶
var EmptyHash [32]byte
EmptyHash ...
var EmptyStepVotes = message.StepVotes{}
EmptyStepVotes ...
Functions ¶
func PrepareSendReductionTest ¶ added in v0.4.0
PrepareSendReductionTest tests that the reduction step completes without problems and produces a StepVotesMsg in case it receives enough valid Reduction messages.
func ShouldProcess ¶ added in v0.4.0
ShouldProcess checks whether a message is consistent with the current round and step. If it is not, it either discards it or stores it for later. The function potentially mutates the consensus.Queue.
Types ¶
type Aggregator ¶ added in v0.4.0
type Aggregator struct {
// contains filtered or unexported fields
}
The Aggregator acts as a de facto storage unit for Reduction messages. Any message it receives will be Aggregated into a StepVotes struct, organized by block hash. Once the key set for a StepVotes of a certain block hash reaches quorum, this StepVotes is passed on to the Reducer by use of the `haltChan` channel. An Aggregator should be instantiated on a per-step basis and is no longer usable after reaching quorum and sending on `haltChan`.
func NewAggregator ¶ added in v0.4.0
func NewAggregator(handler *Handler) *Aggregator
NewAggregator returns an instantiated Aggregator, ready for use by both reduction steps.
func (*Aggregator) CollectVote ¶ added in v0.4.0
func (a *Aggregator) CollectVote(ev message.Reduction) *Result
CollectVote collects a Reduction message, and add its sender public key and signature to the StepVotes/Set kept under the corresponding block hash. If the Set reaches or exceeds quorum, a result is created with the voted hash and the related StepVotes added. The validation of the candidate block is left to the caller.
type Handler ¶ added in v0.2.0
Handler is responsible for performing operations that need to know about specific event fields.
func NewHandler ¶ added in v0.2.0
func NewHandler(keys key.Keys, p user.Provisioners) *Handler
NewHandler will return a Handler, injected with the passed committee and an unmarshaller which uses the injected validation function.
func (*Handler) Committee ¶ added in v0.2.0
func (b *Handler) Committee(round uint64, step uint8) user.VotingCommittee
Committee returns a VotingCommittee for a given round and step.
func (*Handler) IsMember ¶ added in v0.2.0
IsMember delegates the committee.Handler to check if a BLS public key belongs to a committee for the specified round and step.
func (*Handler) Quorum ¶ added in v0.2.0
Quorum returns the amount of committee votes to reach a quorum.
func (*Handler) VerifySignature ¶ added in v0.2.0
VerifySignature verifies the BLS signature of the Reduction event. Since the payload is nil, verifying the signature equates to verifying solely the Header.
type Helper ¶ added in v0.2.0
type Helper struct { *consensus.Emitter ThisSender []byte ProvisionersKeys []key.Keys P *user.Provisioners Nr int Handler *Handler // contains filtered or unexported fields }
Helper for reducing test boilerplate.
func (*Helper) FailOnVerification ¶ added in v0.4.0
FailOnVerification tells the RPC bus to return an error.
func (*Helper) ProcessCandidateVerificationRequest ¶ added in v0.4.0
ProcessCandidateVerificationRequest is a callback used by the firststep reduction to verify potential winning candidates.
type Reduction ¶
Reduction is a struct to be embedded in the reduction steps.
func (*Reduction) IncreaseTimeout ¶ added in v0.4.0
IncreaseTimeout is used when reduction does not reach the quorum or converges over an empty block.