ceremonyclient/consensus/verification/signer.go
Cassandra Heart c797d482f9
v2.1.0.5 (#457)
* wip: conversion of hotstuff from flow into Q-oriented model

* bulk of tests

* remaining non-integration tests

* add integration test, adjust log interface, small tweaks

* further adjustments, restore full pacemaker shape

* add component lifecycle management+supervisor

* further refinements

* resolve timeout hanging

* mostly finalized state for consensus

* bulk of engine swap out

* lifecycle-ify most types

* wiring nearly complete, missing needed hooks for proposals

* plugged in, vetting message validation paths

* global consensus, plugged in and verified

* app shard now wired in too

* do not decode empty keys.yml (#456)

* remove obsolete engine.maxFrames config parameter (#454)

* default to Info log level unless debug is enabled (#453)

* respect config's  "logging" section params, remove obsolete single-file logging (#452)

* Trivial code cleanup aiming to reduce Go compiler warnings (#451)

* simplify range traversal

* simplify channel read for single select case

* delete rand.Seed() deprecated in Go 1.20 and no-op as of Go 1.24

* simplify range traversal

* simplify channel read for single select case

* remove redundant type from array

* simplify range traversal

* simplify channel read for single select case

* RC slate

* finalize 2.1.0.5

* Update comments in StrictMonotonicCounter

Fix comment formatting and clarify description.

---------

Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-11-11 05:00:17 -06:00

121 lines
3.0 KiB
Go

package verification
import (
"context"
"fmt"
"source.quilibrium.com/quilibrium/monorepo/consensus"
"source.quilibrium.com/quilibrium/monorepo/consensus/models"
)
// Signer creates votes for the collector clusters consensus. When a
// participant votes for a state, it _always_ provide the proving signature
// as part of their vote. Signer is responsible for creating correctly
// signed proposals and votes.
type Signer[
StateT models.Unique,
VoteT models.Unique,
PeerIDT models.Unique,
] struct {
voter consensus.VotingProvider[StateT, VoteT, PeerIDT]
}
var _ consensus.Signer[*nilUnique, *nilUnique] = (*Signer[*nilUnique, *nilUnique, *nilUnique])(nil)
// NewSigner instantiates a Signer, which signs votes and
// proposals with the proving key. The generated signatures are aggregatable.
func NewSigner[
StateT models.Unique,
VoteT models.Unique,
PeerIDT models.Unique,
](
voter consensus.VotingProvider[StateT, VoteT, PeerIDT],
) *Signer[StateT, VoteT, PeerIDT] {
sc := &Signer[StateT, VoteT, PeerIDT]{
voter: voter,
}
return sc
}
// CreateVote will create a vote with a proving signature for the given state.
func (c *Signer[StateT, VoteT, PeerIDT]) CreateVote(
state *models.State[StateT],
) (*VoteT, error) {
// create the signature data
vote, err := c.voter.SignVote(context.TODO(), state)
if err != nil {
return nil, fmt.Errorf("could not create signature: %w", err)
}
return vote, nil
}
// CreateTimeout will create a signed timeout state for the given rank.
func (c *Signer[StateT, VoteT, PeerIDT]) CreateTimeout(
curRank uint64,
newestQC models.QuorumCertificate,
previousRankTimeoutCert models.TimeoutCertificate,
) (*models.TimeoutState[VoteT], error) {
// create timeout state specific message
vote, err := c.voter.SignTimeoutVote(
context.TODO(),
newestQC.GetFilter(),
curRank,
newestQC.GetRank(),
)
if err != nil {
return nil, fmt.Errorf(
"could not generate signature for timeout state at rank %d: %w",
curRank,
err,
)
}
timeout := &models.TimeoutState[VoteT]{
Rank: curRank,
LatestQuorumCertificate: newestQC,
PriorRankTimeoutCertificate: previousRankTimeoutCert,
Vote: vote,
TimeoutTick: 0,
}
return timeout, nil
}
// Type used to satisfy generic arguments in compiler time type assertion check
type nilUnique struct{}
// GetSignature implements models.Unique.
func (n *nilUnique) GetSignature() []byte {
panic("unimplemented")
}
// GetTimestamp implements models.Unique.
func (n *nilUnique) GetTimestamp() uint64 {
panic("unimplemented")
}
// Source implements models.Unique.
func (n *nilUnique) Source() models.Identity {
panic("unimplemented")
}
// Clone implements models.Unique.
func (n *nilUnique) Clone() models.Unique {
panic("unimplemented")
}
// GetRank implements models.Unique.
func (n *nilUnique) GetRank() uint64 {
panic("unimplemented")
}
// Identity implements models.Unique.
func (n *nilUnique) Identity() models.Identity {
panic("unimplemented")
}
var _ models.Unique = (*nilUnique)(nil)