Skip to content

Commit

Permalink
Merge branch 'alan/no-fork' into alan/dual-subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
y0sher committed Jul 24, 2024
2 parents ee4f197 + ec363f8 commit d731820
Show file tree
Hide file tree
Showing 31 changed files with 515 additions and 249 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ COV_CMD="-cover"
ifeq ($(COVERAGE),true)
COV_CMD=-coverpkg=./... -covermode="atomic" -coverprofile="coverage.out"
endif
UNFORMATTED=$(shell gofmt -s -l .)
UNFORMATTED=$(shell gofmt -l .)

#Lint
.PHONY: lint-prepare
Expand Down
14 changes: 1 addition & 13 deletions eth/eventhandler/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,11 @@ func (eh *EventHandler) validatorAddedEventToShare(
selfOperatorID := eh.operatorDataStore.GetOperatorID()
var shareSecret *bls.SecretKey

operators := make([]*spectypes.Operator, 0)
committee := make([]*spectypes.CommitteeMember, 0)
shareMembers := make([]*spectypes.ShareMember, 0)

for i := range event.OperatorIds {
operatorID := event.OperatorIds[i]
od, found, err := eh.nodeStorage.GetOperatorData(txn, operatorID)
_, found, err := eh.nodeStorage.GetOperatorData(txn, operatorID)
if err != nil {
return nil, nil, fmt.Errorf("could not get operator data: %w", err)
}
Expand All @@ -293,11 +291,6 @@ func (eh *EventHandler) validatorAddedEventToShare(
}
}

committee = append(committee, &spectypes.CommitteeMember{
OperatorID: operatorID,
SSVOperatorPubKey: od.PublicKey,
})

shareMembers = append(shareMembers, &spectypes.ShareMember{
Signer: operatorID,
SharePubKey: sharePublicKeys[i],
Expand Down Expand Up @@ -327,11 +320,6 @@ func (eh *EventHandler) validatorAddedEventToShare(
Err: errors.New("share private key does not match public key"),
}
}

operators = append(operators, &spectypes.Operator{
OperatorID: operatorID,
SSVOperatorPubKey: od.PublicKey,
})
}

validatorShare.DomainType = eh.networkConfig.DomainType()
Expand Down
3 changes: 2 additions & 1 deletion ibft/storage/stores_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func TestQBFTStores(t *testing.T) {

id := []byte{1, 2, 3}

qbftMap.Each(func(role convert.RunnerRole, store qbftstorage.QBFTStore) error {
err = qbftMap.Each(func(role convert.RunnerRole, store qbftstorage.QBFTStore) error {
return store.SaveInstance(&qbftstorage.StoredInstance{State: &specqbft.State{Height: 1, ID: id}})
})
require.NoError(t, err)

instance, err := qbftMap.Get(convert.RoleCommittee).GetInstance(id, 1)
require.NoError(t, err)
Expand Down
26 changes: 13 additions & 13 deletions integration/qbft/tests/scenario_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"context"
"github.com/ssvlabs/ssv/exporter/convert"
"testing"
"time"

Expand Down Expand Up @@ -81,12 +82,13 @@ func (s *Scenario) Run(t *testing.T, role spectypes.BeaconRole) {

//validating state of validator after invoking duties
for id, validationFunc := range s.ValidationFunctions {
identifier := spectypes.NewMsgID(networkconfig.TestNetwork.Domain, getKeySet(s.Committee).ValidatorPK.Serialize(), spectypes.MapDutyToRunnerRole(role))
identifier := spectypes.NewMsgID(networkconfig.TestNetwork.DomainType(), getKeySet(s.Committee).ValidatorPK.Serialize(), spectypes.MapDutyToRunnerRole(role))
//getting stored state of validator
var storedInstance *protocolstorage.StoredInstance
for {
role := convert.MessageIDFromBytes(identifier[:]).GetRoleType()
var err error
storedInstance, err = s.validators[id].Storage.Get(spectypes.MessageIDFromBytes(identifier[:]).GetRoleType()).GetHighestInstance(identifier[:])
storedInstance, err = s.validators[id].Storage.Get(role).GetHighestInstance(identifier[:])
require.NoError(t, err)

if storedInstance != nil {
Expand Down Expand Up @@ -143,7 +145,6 @@ func testingShare(keySet *spectestingutils.TestKeySet, id spectypes.OperatorID)
ValidatorPubKey: spectypes.ValidatorPK(keySet.ValidatorPK.Serialize()),
SharePubKey: keySet.Shares[id].GetPublicKey().Serialize(),
DomainType: testingutils.TestingSSVDomainType,
Quorum: keySet.Threshold,
Committee: keySet.Committee(),
}
}
Expand All @@ -160,17 +161,16 @@ func newStores(logger *zap.Logger) *qbftstorage.QBFTStores {

storageMap := qbftstorage.NewStores()

roles := []spectypes.BeaconRole{
spectypes.BNRoleAttester,
spectypes.BNRoleProposer,
spectypes.BNRoleAggregator,
spectypes.BNRoleSyncCommittee,
spectypes.BNRoleSyncCommitteeContribution,
spectypes.BNRoleValidatorRegistration,
spectypes.BNRoleVoluntaryExit,
roles := []convert.RunnerRole{
convert.RoleCommittee,
convert.RoleProposer,
convert.RoleAggregator,
convert.RoleSyncCommitteeContribution,
convert.RoleValidatorRegistration,
convert.RoleVoluntaryExit,
}
for _, role := range roles {
storageMap.Add(spectypes.MapDutyToRunnerRole(role), qbftstorage.New(db, role.String()))
storageMap.Add(role, qbftstorage.New(db, role.String()))
}

return storageMap
Expand Down Expand Up @@ -200,7 +200,7 @@ func createValidator(t *testing.T, pCtx context.Context, id spectypes.OperatorID
Liquidated: false,
},
},
Beacon: spectestingutils.NewTestingBeaconNode(),
Beacon: NewTestingBeaconNodeWrapped(),
Signer: km,
}

Expand Down
42 changes: 21 additions & 21 deletions integration/qbft/tests/temp_testing_beacon_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,73 @@ import (

type TestingBeaconNodeWrapped struct {
beacon.BeaconNode
bn *spectestingutils.TestingBeaconNode
Bn *spectestingutils.TestingBeaconNode
}

func (bn *TestingBeaconNodeWrapped) SetSyncCommitteeAggregatorRootHexes(roots map[string]bool) {
bn.bn.SetSyncCommitteeAggregatorRootHexes(roots)
bn.Bn.SetSyncCommitteeAggregatorRootHexes(roots)
}

func (bn *TestingBeaconNodeWrapped) GetBroadcastedRoots() []phase0.Root {
return bn.bn.BroadcastedRoots
return bn.Bn.BroadcastedRoots
}

func (bn *TestingBeaconNodeWrapped) GetBeaconNode() *spectestingutils.TestingBeaconNode {
return bn.bn
return bn.Bn
}

func (bn *TestingBeaconNodeWrapped) GetAttestationData(slot phase0.Slot, committeeIndex phase0.CommitteeIndex) (*phase0.AttestationData, spec.DataVersion, error) {
return bn.bn.GetAttestationData(slot, committeeIndex)
return bn.Bn.GetAttestationData(slot, committeeIndex)
}
func (bn *TestingBeaconNodeWrapped) DomainData(epoch phase0.Epoch, domain phase0.DomainType) (phase0.Domain, error) {
return bn.bn.DomainData(epoch, domain)
return bn.Bn.DomainData(epoch, domain)
}
func (bn *TestingBeaconNodeWrapped) SyncCommitteeSubnetID(index phase0.CommitteeIndex) (uint64, error) {
return bn.bn.SyncCommitteeSubnetID(index)
return bn.Bn.SyncCommitteeSubnetID(index)
}
func (bn *TestingBeaconNodeWrapped) IsSyncCommitteeAggregator(proof []byte) (bool, error) {
return bn.bn.IsSyncCommitteeAggregator(proof)
return bn.Bn.IsSyncCommitteeAggregator(proof)
}
func (bn *TestingBeaconNodeWrapped) GetSyncCommitteeContribution(slot phase0.Slot, selectionProofs []phase0.BLSSignature, subnetIDs []uint64) (ssz.Marshaler, spec.DataVersion, error) {
return bn.bn.GetSyncCommitteeContribution(slot, selectionProofs, subnetIDs)
return bn.Bn.GetSyncCommitteeContribution(slot, selectionProofs, subnetIDs)
}
func (bn *TestingBeaconNodeWrapped) SubmitAggregateSelectionProof(slot phase0.Slot, committeeIndex phase0.CommitteeIndex, committeeLength uint64, index phase0.ValidatorIndex, slotSig []byte) (ssz.Marshaler, spec.DataVersion, error) {
return bn.bn.SubmitAggregateSelectionProof(slot, committeeIndex, committeeLength, index, slotSig)
return bn.Bn.SubmitAggregateSelectionProof(slot, committeeIndex, committeeLength, index, slotSig)
}
func (bn *TestingBeaconNodeWrapped) GetBeaconNetwork() spectypes.BeaconNetwork {
return bn.bn.GetBeaconNetwork()
return bn.Bn.GetBeaconNetwork()
}
func (bn *TestingBeaconNodeWrapped) GetBeaconBlock(slot phase0.Slot, graffiti, randao []byte) (ssz.Marshaler, spec.DataVersion, error) {
return bn.bn.GetBeaconBlock(slot, graffiti, randao)
return bn.Bn.GetBeaconBlock(slot, graffiti, randao)
}
func (bn *TestingBeaconNodeWrapped) SubmitValidatorRegistration(pubkey []byte, feeRecipient bellatrix.ExecutionAddress, sig phase0.BLSSignature) error {
return bn.bn.SubmitValidatorRegistration(pubkey, feeRecipient, sig)
return bn.Bn.SubmitValidatorRegistration(pubkey, feeRecipient, sig)
}
func (bn *TestingBeaconNodeWrapped) SubmitVoluntaryExit(voluntaryExit *phase0.SignedVoluntaryExit) error {
return bn.bn.SubmitVoluntaryExit(voluntaryExit)
return bn.Bn.SubmitVoluntaryExit(voluntaryExit)
}
func (bn *TestingBeaconNodeWrapped) SubmitAttestations(attestations []*phase0.Attestation) error {
return bn.bn.SubmitAttestations(attestations)
return bn.Bn.SubmitAttestations(attestations)
}
func (bn *TestingBeaconNodeWrapped) SubmitSyncMessages(msgs []*altair.SyncCommitteeMessage) error {
return bn.bn.SubmitSyncMessages(msgs)
return bn.Bn.SubmitSyncMessages(msgs)
}
func (bn *TestingBeaconNodeWrapped) SubmitBlindedBeaconBlock(block *api.VersionedBlindedProposal, sig phase0.BLSSignature) error {
return bn.bn.SubmitBlindedBeaconBlock(block, sig)
return bn.Bn.SubmitBlindedBeaconBlock(block, sig)
}
func (bn *TestingBeaconNodeWrapped) SubmitSignedContributionAndProof(contribution *altair.SignedContributionAndProof) error {
return bn.bn.SubmitSignedContributionAndProof(contribution)
return bn.Bn.SubmitSignedContributionAndProof(contribution)
}
func (bn *TestingBeaconNodeWrapped) SubmitSignedAggregateSelectionProof(msg *phase0.SignedAggregateAndProof) error {
return bn.bn.SubmitSignedAggregateSelectionProof(msg)
return bn.Bn.SubmitSignedAggregateSelectionProof(msg)
}
func (bn *TestingBeaconNodeWrapped) SubmitBeaconBlock(block *api.VersionedProposal, sig phase0.BLSSignature) error {
return bn.bn.SubmitBeaconBlock(block, sig)
return bn.Bn.SubmitBeaconBlock(block, sig)
}

func NewTestingBeaconNodeWrapped() beacon.BeaconNode {
bnw := &TestingBeaconNodeWrapped{}
bnw.bn = spectestingutils.NewTestingBeaconNode()
bnw.Bn = spectestingutils.NewTestingBeaconNode()

return bnw
}
8 changes: 6 additions & 2 deletions message/validation/common_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,19 @@ func (mv *messageValidator) validateBeaconDuty(
// Rule: For a proposal duty message, we check if the validator is assigned to it
if role == spectypes.RoleProposer {
epoch := mv.netCfg.Beacon.EstimatedEpochAtSlot(slot)
if mv.dutyStore.Proposer.ValidatorDuty(epoch, slot, indices[0]) == nil {
// Non-committee roles always have one validator index.
validatorIndex := indices[0]
if mv.dutyStore.Proposer.ValidatorDuty(epoch, slot, validatorIndex) == nil {
return ErrNoDuty
}
}

// Rule: For a sync committee aggregation duty message, we check if the validator is assigned to it
if role == spectypes.RoleSyncCommitteeContribution {
period := mv.netCfg.Beacon.EstimatedSyncCommitteePeriodAtEpoch(mv.netCfg.Beacon.EstimatedEpochAtSlot(slot))
if mv.dutyStore.SyncCommittee.Duty(period, indices[0]) == nil {
// Non-committee roles always have one validator index.
validatorIndex := indices[0]
if mv.dutyStore.SyncCommittee.Duty(period, validatorIndex) == nil {
return ErrNoDuty
}
}
Expand Down
4 changes: 0 additions & 4 deletions message/validation/consensus_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,6 @@ func (mv *messageValidator) processSignerState(signedSSVMessage *spectypes.Signe
return nil
}

func (mv *messageValidator) maxSlotsInState() phase0.Slot {
return phase0.Slot(mv.netCfg.SlotsPerEpoch()) + lateSlotAllowance
}

func (mv *messageValidator) validateJustifications(message *specqbft.Message) error {
pj, err := message.GetPrepareJustifications()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion network/discovery/dv5_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package discovery

import (
"context"
"github.com/ssvlabs/ssv/networkconfig"
"net"
"os"
"testing"
Expand Down Expand Up @@ -116,7 +117,7 @@ func TestCheckPeer(t *testing.T) {
ctx: ctx,
conns: &mock.MockConnectionIndex{LimitValue: true},
subnetsIdx: subnetIndex,
domainType: &TestDomainType{myDomainType},
domainType: networkconfig.TestNetwork,
subnets: mySubnets,
}

Expand Down
Loading

0 comments on commit d731820

Please sign in to comment.