Skip to content

Commit f7ce4dd

Browse files
nkryuchkovy0sherMatusKysel
committed
refactor(networkconfig): extract beacon parameters from BeaconNetwork interface (#2145)
* networkconfig: split beacon and ssv configs * move most parameters outside of BeaconNetwork interface * get rid of BeaconNetwork interface * some leftovers * fix linter * fix message validation tests * fix linter again * leftovers after merging * fix issues after merging * fix network name bug * code review comments * fix issues after merging * update go.mod * fix ekm tests * remove unused import * update go.mod * fix issues after merging * format/imports * revert preparationSlots type change * use uint64 for amount of slots and epochs * use github.com/ssvlabs/eth2-key-manager@v1.5.5 * spec-alignment * feat(networkconfig,beacon/goclient): get beacon config from beacon node (#2153) * beacon/goclient: get beacon config from beacon node * use beacon config obtained from beacon node * log config as JSON * delete a comment * use Stringer to log node * guard beacon config reads with mutex * add a timeout log * delete hardcoded beacon configs * Revert "delete hardcoded beacon configs" This reverts commit c2e2f8f. * fix issues after merging * code review comments * unexport supportedSSVConfigs * fix a context bug * pass network config name * feat(networkconfig): CLI for custom SSV config generation (#2156) * networkconfig: CLI for custom SSV config generation * implement JSON marshaling and YAML marshaling/unmarshaling * remove TotalEthereumValidators * simplify marshaling/unmarshaling logic * fix markdown formatting * use yaml@v3 * add tests * simplify unmarshaling * fix linter * add missing fields to LocalTestnet * update go.mod * networkconfig: make hardcoded values configurable (#2164) * beacon/goclient: get beacon config from beacon node * use beacon config obtained from beacon node * log config as JSON * networkconfig: CLI for custom SSV config generation * implement JSON marshaling and YAML marshaling/unmarshaling * remove TotalEthereumValidators * simplify marshaling/unmarshaling logic * fix markdown formatting * use yaml@v3 * add tests * simplify unmarshaling * delete a comment * use Stringer to log node * guard beacon config reads with mutex * add a timeout log * delete hardcoded beacon configs * Revert "delete hardcoded beacon configs" This reverts commit c2e2f8f. * networkconfig: make hardcoded values configurable * fix issues after merging * code review comments * fix issues after merging * delete outer metrics for genesisForClient * rewrite modulo calculation * code review comments * unexport supportedSSVConfigs * revert the modulo calculation * add EpochDuration mock * G115 * fill missing fields in configs * add a comment about eth spec * fix error text * use genesis validators root from config in computeVoluntaryExitDomain * fix linter * fix a typo * remove redundant comments * fix a context bug * fix issues after merging * pass network config name * networkconfig: narrow config usage (#2172) * use SSV/Beacon configs instead of NetworkConfig where possible * fix linter * fix a comment * fix issues after merging * fix issues after merging * beacon,networkconfig: move fork handling from beacon to networkconfig (#2178) * beacon/goclient: get beacon config from beacon node * use beacon config obtained from beacon node * log config as JSON * networkconfig: CLI for custom SSV config generation * implement JSON marshaling and YAML marshaling/unmarshaling * remove TotalEthereumValidators * simplify marshaling/unmarshaling logic * fix markdown formatting * use yaml@v3 * add tests * simplify unmarshaling * delete a comment * use Stringer to log node * guard beacon config reads with mutex * add a timeout log * delete hardcoded beacon configs * Revert "delete hardcoded beacon configs" This reverts commit c2e2f8f. * networkconfig: make hardcoded values configurable * fix issues after merging * code review comments * fix issues after merging * delete outer metrics for genesisForClient * rewrite modulo calculation * code review comments * unexport supportedSSVConfigs * revert the modulo calculation * add EpochDuration mock * G115 * fill missing fields in configs * add a comment about eth spec * fix error text * use genesis validators root from config in computeVoluntaryExitDomain * beacon,networkconfig: move forks from beacon to networkconfig * get rid of using Genesis method * use ForkAtEpoch instead of DataVersion * generate mocks * fix linter * fix beacon tests * beacon: delete ForkAtEpoch * fix ekm tests * update go.mod * fix some TODOs * fix linter * fix a typo * remove redundant comments * remove Spec method * delete a comment * uncomment config print * fix a context bug * fix issues after merging * pass network config name * update go.mod * fix issues after merging * networkconfig: delete hardcoded beacon configs (#2183) * beacon/goclient: get beacon config from beacon node * use beacon config obtained from beacon node * log config as JSON * networkconfig: CLI for custom SSV config generation * implement JSON marshaling and YAML marshaling/unmarshaling * remove TotalEthereumValidators * simplify marshaling/unmarshaling logic * fix markdown formatting * use yaml@v3 * add tests * simplify unmarshaling * delete a comment * use Stringer to log node * guard beacon config reads with mutex * add a timeout log * delete hardcoded beacon configs * Revert "delete hardcoded beacon configs" This reverts commit c2e2f8f. * networkconfig: make hardcoded values configurable * fix issues after merging * code review comments * fix issues after merging * delete outer metrics for genesisForClient * rewrite modulo calculation * code review comments * unexport supportedSSVConfigs * revert the modulo calculation * add EpochDuration mock * G115 * fill missing fields in configs * add a comment about eth spec * fix error text * use genesis validators root from config in computeVoluntaryExitDomain * beacon,networkconfig: move forks from beacon to networkconfig * get rid of using Genesis method * use ForkAtEpoch instead of DataVersion * generate mocks * fix linter * fix beacon tests * beacon: delete ForkAtEpoch * fix ekm tests * update go.mod * fix some TODOs * networkconfig: delete mainnet beacon config * networkconfig: delete rest of configs * replace TestRealNetwork with TestNetwork * fix linter * fix a typo * remove redundant comments * remove Spec method * delete a comment * uncomment config print * fix a context bug * fix issues after merging * delete TestRealNetwork * pass network config name * update go.mod * fix issues after merging * fix issues after merging * rename BeaconName to NetworkName * refactor getting spec parameters * update go.mod * fix type assertion * fix spec align --------- Co-authored-by: y0sher <lyosher@gmail.com> Co-authored-by: Matus Kysel <matus@ssvlabs.io>
1 parent 10dcef2 commit f7ce4dd

File tree

158 files changed

+3638
-3161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+3638
-3161
lines changed

beacon/goclient/aggregator.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (gc *GoClient) SubmitAggregateSelectionProof(
3030
gc.waitToSlotTwoThirds(slot)
3131

3232
// differ from spec because we need to subscribe to subnet
33-
isAggregator := isAggregator(committeeLength, slotSig)
33+
isAggregator := gc.isAggregator(committeeLength, slotSig)
3434
if !isAggregator {
3535
return nil, DataVersionNil, fmt.Errorf("validator is not an aggregator")
3636
}
@@ -39,7 +39,9 @@ func (gc *GoClient) SubmitAggregateSelectionProof(
3939
if err != nil {
4040
return nil, DataVersionNil, fmt.Errorf("failed to get attestation data: %w", err)
4141
}
42-
if gc.DataVersion(gc.network.EstimatedEpochAtSlot(attData.Slot)) < spec.DataVersionElectra {
42+
43+
dataVersion, _ := gc.beaconConfig.ForkAtEpoch(gc.getBeaconConfig().EstimatedEpochAtSlot(attData.Slot))
44+
if dataVersion < spec.DataVersionElectra {
4345
attData.Index = committeeIndex
4446
}
4547

@@ -188,8 +190,8 @@ func (gc *GoClient) SubmitSignedAggregateSelectionProof(
188190
// committee = get_beacon_committee(state, slot, index)
189191
// modulo = max(1, len(committee) // TARGET_AGGREGATORS_PER_COMMITTEE)
190192
// return bytes_to_uint64(hash(slot_signature)[0:8]) % modulo == 0
191-
func isAggregator(committeeCount uint64, slotSig []byte) bool {
192-
modulo := committeeCount / TargetAggregatorsPerCommittee
193+
func (gc *GoClient) isAggregator(committeeCount uint64, slotSig []byte) bool {
194+
modulo := committeeCount / gc.beaconConfig.TargetAggregatorsPerCommittee
193195
if modulo == 0 {
194196
// Modulo must be at least 1.
195197
modulo = 1
@@ -201,9 +203,9 @@ func isAggregator(committeeCount uint64, slotSig []byte) bool {
201203

202204
// waitToSlotTwoThirds waits until two-third of the slot has transpired (SECONDS_PER_SLOT * 2 / 3 seconds after slot start time)
203205
func (gc *GoClient) waitToSlotTwoThirds(slot phase0.Slot) {
204-
oneThird := gc.network.SlotDurationSec() / 3 /* one third of slot duration */
205-
206-
finalTime := gc.slotStartTime(slot).Add(2 * oneThird)
206+
config := gc.getBeaconConfig()
207+
oneInterval := config.IntervalDuration()
208+
finalTime := config.GetSlotStartTime(slot).Add(2 * oneInterval)
207209
wait := time.Until(finalTime)
208210
if wait <= 0 {
209211
return

beacon/goclient/attest_test.go

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ import (
1515
"github.com/attestantio/go-eth2-client/spec"
1616
"github.com/attestantio/go-eth2-client/spec/phase0"
1717
"github.com/sourcegraph/conc/pool"
18-
"github.com/ssvlabs/ssv-spec/types"
1918
"github.com/stretchr/testify/require"
2019
"go.uber.org/zap"
2120

22-
"github.com/ssvlabs/ssv/operator/slotticker"
23-
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
2421
"github.com/ssvlabs/ssv/utils/hashmap"
2522
)
2623

@@ -61,30 +58,36 @@ var (
6158
}`),
6259
"/eth/v1/beacon/genesis": []byte(`{
6360
"data": {
64-
"genesis_time": "1695902400",
65-
"genesis_validators_root": "0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1",
61+
"genesis_time": "1606824023",
62+
"genesis_validators_root": "0x4b363db94e28612020049ce3795b0252c16c4241df2bc9ef221abde47527c0d0",
6663
"genesis_fork_version": "0x00000000"
6764
}
6865
}`),
6966
"/eth/v1/config/spec": []byte(`{
7067
"data": {
71-
"CONFIG_NAME": "holesky",
68+
"CONFIG_NAME": "mainnet",
7269
"GENESIS_FORK_VERSION": "0x00000000",
73-
"CAPELLA_FORK_VERSION": "0x04017000",
74-
"MIN_GENESIS_TIME": "1695902100",
70+
"ALTAIR_FORK_VERSION": "0x01000000",
71+
"ALTAIR_FORK_EPOCH": "74240",
72+
"BELLATRIX_FORK_VERSION": "0x02000000",
73+
"BELLATRIX_FORK_EPOCH": "144896",
74+
"CAPELLA_FORK_VERSION": "0x03000000",
75+
"CAPELLA_FORK_EPOCH": "194048",
76+
"DENEB_FORK_VERSION": "0x04000000",
77+
"DENEB_FORK_EPOCH": "269568",
78+
"ELECTRA_FORK_VERSION": "0x05000000",
79+
"ELECTRA_FORK_EPOCH": "364032",
80+
"FULU_FORK_VERSION": "0x06000000",
81+
"FULU_FORK_EPOCH": "18446744073709551615",
82+
"MIN_GENESIS_TIME": "1606824000",
7583
"SECONDS_PER_SLOT": "12",
7684
"SLOTS_PER_EPOCH": "32",
7785
"EPOCHS_PER_SYNC_COMMITTEE_PERIOD": "256",
7886
"SYNC_COMMITTEE_SIZE": "512",
7987
"SYNC_COMMITTEE_SUBNET_COUNT": "4",
8088
"TARGET_AGGREGATORS_PER_COMMITTEE": "16",
8189
"TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE": "16",
82-
"INTERVALS_PER_SLOT": "3",
83-
"ALTAIR_FORK_EPOCH": "74240",
84-
"BELLATRIX_FORK_EPOCH": "144896",
85-
"CAPELLA_FORK_EPOCH": "194048",
86-
"DENEB_FORK_EPOCH": "269568",
87-
"ELECTRA_FORK_EPOCH": "18446744073709551615"
90+
"INTERVALS_PER_SLOT": "3"
8891
}
8992
}`),
9093
}
@@ -205,17 +208,10 @@ func TestGoClient_GetAttestationData_Simple(t *testing.T) {
205208
t.Context(),
206209
zap.NewNop(),
207210
Options{
208-
Network: beacon.NewNetwork(types.MainNetwork),
209211
BeaconNodeAddr: server.URL,
210212
CommonTimeout: 1 * time.Second,
211213
LongTimeout: 1 * time.Second,
212214
},
213-
func() slotticker.SlotTicker {
214-
return slotticker.New(zap.NewNop(), slotticker.Config{
215-
SlotDuration: 12 * time.Second,
216-
GenesisTime: time.Now(),
217-
})
218-
},
219215
)
220216
require.NoError(t, err)
221217

@@ -501,18 +497,11 @@ func createClient(
501497
ctx,
502498
zap.NewNop(),
503499
Options{
504-
Network: beacon.NewNetwork(types.MainNetwork),
505500
BeaconNodeAddr: beaconServerURL,
506501
CommonTimeout: defaultHardTimeout,
507502
LongTimeout: time.Second,
508503
WithWeightedAttestationData: withWeightedAttestationData,
509504
},
510-
func() slotticker.SlotTicker {
511-
return slotticker.New(zap.NewNop(), slotticker.Config{
512-
SlotDuration: 12 * time.Second,
513-
GenesisTime: time.Now(),
514-
})
515-
},
516505
)
517506
return client, err
518507
}

beacon/goclient/current_fork.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

beacon/goclient/current_fork_test.go

Lines changed: 0 additions & 139 deletions
This file was deleted.

0 commit comments

Comments
 (0)