Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec alignment review #1509

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions operator/validator/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,7 @@ func SetupRunners(
qbftCtrl := buildController(spectypes.RoleSyncCommitteeContribution, syncCommitteeContributionValueCheckF)
runners[role] = runner.NewSyncCommitteeAggregatorRunner(options.NetworkConfig, options.NetworkConfig.Beacon.GetBeaconNetwork(), shareMap, qbftCtrl, options.Beacon, options.Network, options.Signer, options.OperatorSigner, syncCommitteeContributionValueCheckF, 0)
case spectypes.RoleValidatorRegistration:
qbftCtrl := buildController(spectypes.RoleValidatorRegistration, nil)
runners[role] = runner.NewValidatorRegistrationRunner(options.NetworkConfig, options.NetworkConfig.Beacon.GetBeaconNetwork(), shareMap, qbftCtrl, options.Beacon, options.Network, options.Signer, options.OperatorSigner)
runners[role] = runner.NewValidatorRegistrationRunner(options.NetworkConfig, options.NetworkConfig.Beacon.GetBeaconNetwork(), shareMap, options.Beacon, options.Network, options.Signer, options.OperatorSigner)
case spectypes.RoleVoluntaryExit:
runners[role] = runner.NewVoluntaryExitRunner(options.NetworkConfig, options.NetworkConfig.Beacon.GetBeaconNetwork(), shareMap, options.Beacon, options.Network, options.Signer, options.OperatorSigner)
}
Expand Down
3 changes: 2 additions & 1 deletion protocol/v2/qbft/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func (c *Controller) UponExistingInstanceMsg(logger *zap.Logger, msg *specqbft.P
logger.Debug("❌ failed to broadcast decided message", zap.Error(err))
}

// TODO: spec checks if prevDecided (and returns if so) right after inst.ProcessMsg. Should we align?
y0sher marked this conversation as resolved.
Show resolved Hide resolved
if prevDecided {
return nil, err
}
Expand Down Expand Up @@ -220,7 +221,7 @@ func (c *Controller) addAndStoreNewInstance() *instance.Instance {
func (c *Controller) GetRoot() ([32]byte, error) {
marshaledRoot, err := json.Marshal(c)
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode state")
return [32]byte{}, errors.Wrap(err, "could not encode controller")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/qbft/controller/decided.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func ValidateDecided(
return errors.Wrap(err, "invalid decided msg")
}

if err := msg.SignedMessage.Validate(); err != nil {
if err := msg.Validate(); err != nil {
return errors.Wrap(err, "invalid decided")
}

Expand Down
4 changes: 4 additions & 0 deletions protocol/v2/qbft/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ func (i *Instance) Broadcast(logger *zap.Logger, msg *spectypes.SignedSSVMessage
if !i.CanProcessMessages() {
return errors.New("instance stopped processing messages")
}
// TODO: In spec, the below assignment doesn't exist.
// In fact, the msg should already have the correct identifier. Why are we setting it again?
// Also, even though it doesn't change anything, we shouldn't change the message's content
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not changing the message content, just creating the messageID.
infact in broadcast i.config.GetNetwork().Broadcast(msgID, msg) below, msgID is never used, we are using the msgid from the message there.

maybe its time to not use separate msgid in the Broadcast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh true. I didn't realise it. Yup, at least for the scope of this PR, in spec we also use msgID in Broadcast, but from the msg itself.

Regarding changing the Broadcast function, we would also need to do a change in spec. Maybe it's not the scope of this PR but we can add it later on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@y0sher Can I align this to spec, to use the ID from the msg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I'm aligning it. Afterwards, if we find it necessary, we can go back to copying the ID from the state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's no special reason to use the msgid from the state, the message is ok.

// after signing it.
msgID := spectypes.MessageID{}
copy(msgID[:], i.State.ID)

Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func validSignedPrepareForHeightRoundAndRootIgnoreSignature(
return errors.New("wrong msg round")
}

if err := msg.SignedMessage.Validate(); err != nil {
if err := msg.Validate(); err != nil {
return errors.Wrap(err, "prepareData invalid")
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func isValidProposal(
return errors.New("proposal leader invalid")
}

if err := msg.SignedMessage.Validate(); err != nil {
if err := msg.Validate(); err != nil {
return errors.Wrap(err, "proposal invalid")
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/qbft/instance/round_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func validRoundChangeForDataIgnoreSignature(
return errors.New("msg allows 1 signer")
}

if err := msg.SignedMessage.Validate(); err != nil {
if err := msg.Validate(); err != nil {
return errors.Wrap(err, "roundChange invalid")
}

Expand Down
4 changes: 2 additions & 2 deletions protocol/v2/ssv/runner/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (r *AggregatorRunner) expectedPostConsensusRootsAndDomain() ([]ssz.HashRoot
cd := &spectypes.ValidatorConsensusData{}
err := cd.Decode(r.GetState().DecidedValue)
if err != nil {
return nil, spectypes.DomainAggregateAndProof, err
return nil, spectypes.DomainError, errors.Wrap(err, "could not create consensus data")
}
aggregateAndProof, err := cd.GetAggregateAndProof()
if err != nil {
Expand Down Expand Up @@ -370,7 +370,7 @@ func (r *AggregatorRunner) Decode(data []byte) error {
func (r *AggregatorRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := r.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode AggregatorRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
14 changes: 8 additions & 6 deletions protocol/v2/ssv/runner/committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ func (cr *CommitteeRunner) Decode(data []byte) error {
func (cr *CommitteeRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := cr.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode CommitteeRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
}

func (cr *CommitteeRunner) MarshalJSON() ([]byte, error) {
type CommitteeAlias struct {
type CommitteeRunnerAlias struct {
BaseRunner *BaseRunner
beacon beacon.BeaconNode
network specqbft.Network
Expand All @@ -118,7 +118,7 @@ func (cr *CommitteeRunner) MarshalJSON() ([]byte, error) {
}

// Create object and marshal
alias := &CommitteeAlias{
alias := &CommitteeRunnerAlias{
BaseRunner: cr.BaseRunner,
beacon: cr.beacon,
network: cr.network,
Expand All @@ -133,7 +133,7 @@ func (cr *CommitteeRunner) MarshalJSON() ([]byte, error) {
}

func (cr *CommitteeRunner) UnmarshalJSON(data []byte) error {
type CommitteeAlias struct {
type CommitteeRunnerAlias struct {
BaseRunner *BaseRunner
beacon beacon.BeaconNode
network specqbft.Network
Expand All @@ -145,7 +145,7 @@ func (cr *CommitteeRunner) UnmarshalJSON(data []byte) error {
}

// Unmarshal the JSON data into the auxiliary struct
aux := &CommitteeAlias{}
aux := &CommitteeRunnerAlias{}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
Expand Down Expand Up @@ -369,7 +369,7 @@ func (cr *CommitteeRunner) ProcessPostConsensus(logger *zap.Logger, signedMsg *s
// If the reconstructed signature verification failed, fall back to verifying each partial signature
// TODO should we return an error here? maybe other sigs are fine?
if err != nil {
for _, root := range roots {
for root := range rootSet {
cr.BaseRunner.FallBackAndVerifyEachSignature(cr.BaseRunner.State.PostConsensusContainer, root,
share.Committee, validator)
}
Expand Down Expand Up @@ -539,12 +539,14 @@ func findValidators(

// Unneeded since no preconsensus phase
func (cr CommitteeRunner) expectedPreConsensusRootsAndDomain() ([]ssz.HashRoot, phase0.DomainType, error) {
// TODO: spec uses a panic here since this function should never be used. Should we align?
nkryuchkov marked this conversation as resolved.
Show resolved Hide resolved
return nil, spectypes.DomainError, errors.New("no pre consensus root for committee runner")
}

// This function signature returns only one domain type... but we can have mixed domains
// instead we rely on expectedPostConsensusRootsAndBeaconObjects that is called later
func (cr CommitteeRunner) expectedPostConsensusRootsAndDomain() ([]ssz.HashRoot, phase0.DomainType, error) {
// TODO: spec uses a panic here since this function should never be used. Should we align?
return []ssz.HashRoot{}, spectypes.DomainAttester, nil
}

Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/ssv/runner/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func (r *ProposerRunner) Decode(data []byte) error {
func (r *ProposerRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := r.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode ProposerRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
1 change: 1 addition & 0 deletions protocol/v2/ssv/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (b *BaseRunner) baseConsensusMsgProcessing(logger *zap.Logger, runner Runne
}

decidedMsg, err := b.QBFTController.ProcessMsg(logger, msg)
// TODO: Should we remove this function since it doesn't do anything?
nkryuchkov marked this conversation as resolved.
Show resolved Hide resolved
b.compactInstanceIfNeeded(msg)
if err != nil {
return false, nil, err
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/ssv/runner/runner_signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (b *BaseRunner) validatePartialSigMsgForSlot(
slot spec.Slot,
) error {
if err := psigMsgs.Validate(); err != nil {
return errors.Wrap(err, "SignedPartialSignatureMessage invalid")
return errors.Wrap(err, "PartialSignatureMessages invalid")
}

if psigMsgs.Slot != slot {
Expand Down
6 changes: 3 additions & 3 deletions protocol/v2/ssv/runner/runner_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (pcs *State) MarshalJSON() ([]byte, error) {
RunningInstance *instance.Instance
DecidedValue []byte
Finished bool
BeaconDuty *spectypes.ValidatorDuty `json:"ValidatorDuty,omitempty"`
ValidatorDuty *spectypes.ValidatorDuty `json:"ValidatorDuty,omitempty"`
CommitteeDuty *spectypes.CommitteeDuty `json:"CommitteeDuty,omitempty"`
}

Expand All @@ -86,8 +86,8 @@ func (pcs *State) MarshalJSON() ([]byte, error) {
}

if pcs.StartingDuty != nil {
if BeaconDuty, ok := pcs.StartingDuty.(*spectypes.ValidatorDuty); ok {
alias.BeaconDuty = BeaconDuty
if ValidatorDuty, ok := pcs.StartingDuty.(*spectypes.ValidatorDuty); ok {
alias.ValidatorDuty = ValidatorDuty
} else if committeeDuty, ok := pcs.StartingDuty.(*spectypes.CommitteeDuty); ok {
alias.CommitteeDuty = committeeDuty
} else {
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/ssv/runner/sync_committee_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (r *SyncCommitteeAggregatorRunner) Decode(data []byte) error {
func (r *SyncCommitteeAggregatorRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := r.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode SyncCommitteeAggregatorRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
16 changes: 8 additions & 8 deletions protocol/v2/ssv/runner/validator_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ssvlabs/ssv/logging/fields"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/protocol/v2/qbft/controller"
"github.com/ssvlabs/ssv/protocol/v2/ssv/runner/metrics"
ssvtypes "github.com/ssvlabs/ssv/protocol/v2/types"
)
Expand All @@ -37,7 +36,6 @@ func NewValidatorRegistrationRunner(
domainTypeProvider networkconfig.DomainTypeProvider,
beaconNetwork spectypes.BeaconNetwork,
share map[phase0.ValidatorIndex]*spectypes.Share,
qbftController *controller.Controller,
beacon beacon.BeaconNode,
network specqbft.Network,
signer spectypes.BeaconSigner,
Expand All @@ -49,7 +47,6 @@ func NewValidatorRegistrationRunner(
DomainTypeProvider: domainTypeProvider,
BeaconNetwork: beaconNetwork,
Share: share,
QBFTController: qbftController,
},

beacon: beacon,
Expand Down Expand Up @@ -124,7 +121,10 @@ func (r *ValidatorRegistrationRunner) ProcessPostConsensus(logger *zap.Logger, s
}

func (r *ValidatorRegistrationRunner) expectedPreConsensusRootsAndDomain() ([]ssz.HashRoot, phase0.DomainType, error) {
vr, err := r.calculateValidatorRegistration()
if r.BaseRunner.State == nil || r.BaseRunner.State.StartingDuty == nil {
return nil, spectypes.DomainError, errors.New("no running duty to compute preconsensus roots and domain")
}
vr, err := r.calculateValidatorRegistration(r.BaseRunner.State.StartingDuty)
if err != nil {
return nil, spectypes.DomainError, errors.Wrap(err, "could not calculate validator registration")
}
Expand All @@ -137,7 +137,7 @@ func (r *ValidatorRegistrationRunner) expectedPostConsensusRootsAndDomain() ([]s
}

func (r *ValidatorRegistrationRunner) executeDuty(logger *zap.Logger, duty spectypes.Duty) error {
vr, err := r.calculateValidatorRegistration()
vr, err := r.calculateValidatorRegistration(duty)
if err != nil {
return errors.Wrap(err, "could not calculate validator registration")
}
Expand Down Expand Up @@ -188,7 +188,7 @@ func (r *ValidatorRegistrationRunner) executeDuty(logger *zap.Logger, duty spect
return nil
}

func (r *ValidatorRegistrationRunner) calculateValidatorRegistration() (*v1.ValidatorRegistration, error) {
func (r *ValidatorRegistrationRunner) calculateValidatorRegistration(duty spectypes.Duty) (*v1.ValidatorRegistration, error) {
share := r.GetShare()
if share == nil {
return nil, errors.New("no share to get validator public key")
Expand All @@ -197,7 +197,7 @@ func (r *ValidatorRegistrationRunner) calculateValidatorRegistration() (*v1.Vali
pk := phase0.BLSPubKey{}
copy(pk[:], share.ValidatorPubKey[:])

epoch := r.BaseRunner.BeaconNetwork.EstimatedEpochAtSlot(r.BaseRunner.State.StartingDuty.DutySlot())
epoch := r.BaseRunner.BeaconNetwork.EstimatedEpochAtSlot(duty.DutySlot())

return &v1.ValidatorRegistration{
FeeRecipient: share.FeeRecipientAddress,
Expand Down Expand Up @@ -255,7 +255,7 @@ func (r *ValidatorRegistrationRunner) Decode(data []byte) error {
func (r *ValidatorRegistrationRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := r.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode ValidatorRegistrationRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
2 changes: 1 addition & 1 deletion protocol/v2/ssv/runner/voluntary_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (r *VoluntaryExitRunner) Decode(data []byte) error {
func (r *VoluntaryExitRunner) GetRoot() ([32]byte, error) {
marshaledRoot, err := r.Encode()
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not encode DutyRunnerState")
return [32]byte{}, errors.Wrap(err, "could not encode VoluntaryExitRunner")
}
ret := sha256.Sum256(marshaledRoot)
return ret, nil
Expand Down
2 changes: 0 additions & 2 deletions protocol/v2/ssv/testing/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ var baseRunner = func(
networkconfig.TestNetwork,
spectypes.BeaconTestNetwork,
shareMap,
contr,
tests.NewTestingBeaconNodeWrapped(),
net,
km,
Expand Down Expand Up @@ -390,7 +389,6 @@ var baseRunnerWithShareMap = func(
networkconfig.TestNetwork,
spectypes.BeaconTestNetwork,
shareMap,
contr,
tests.NewTestingBeaconNodeWrapped(),
net,
km,
Expand Down
Loading