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

feat(network/config): pass custom ssv config & get beacon config from node & remove hardcoded network values #1308

Open
wants to merge 85 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
cd05e18
override spec beacon network & pass custom network config in yaml
nkryuchkov Nov 11, 2024
2ac7d3d
script for custom config generation
nkryuchkov Nov 11, 2024
b25cf45
initial implementation of reading beacon config from beacon node
nkryuchkov Nov 11, 2024
1f18945
remove duty data
nkryuchkov Nov 11, 2024
76b96d2
remove beacon from event handler
nkryuchkov Nov 11, 2024
d797baa
add BeaconConfig to TestNetwork
nkryuchkov Nov 12, 2024
4b7f274
get rid of beacon network in beacon client
nkryuchkov Nov 12, 2024
2a3633c
WIP on getting rid of BeaconNetwork
nkryuchkov Nov 12, 2024
dbe9725
WIP on getting rid of BeaconNetwork [2]
nkryuchkov Nov 12, 2024
cd7640a
WIP on getting rid of BeaconNetwork [3]
nkryuchkov Nov 12, 2024
6ffbc96
WIP on getting rid of BeaconNetwork [4]
nkryuchkov Nov 12, 2024
fcab193
WIP on getting rid of BeaconNetwork [5]
nkryuchkov Nov 12, 2024
f84aec6
WIP on getting rid of BeaconNetwork [6]
nkryuchkov Nov 12, 2024
7bfa465
WIP on getting rid of BeaconNetwork [7]
nkryuchkov Nov 12, 2024
70017f5
WIP on getting rid of BeaconNetwork [8]
nkryuchkov Nov 12, 2024
c5ea310
WIP on getting rid of BeaconNetwork [9]
nkryuchkov Nov 12, 2024
814f35b
WIP on getting rid of BeaconNetwork [10]
nkryuchkov Nov 12, 2024
95f18de
WIP on getting rid of BeaconNetwork [11]
nkryuchkov Nov 12, 2024
8c5c3d8
simplify BeaconNode interface
nkryuchkov Nov 12, 2024
8182c1c
refactor network config
nkryuchkov Nov 13, 2024
d975009
replace methods with fields in beacon config
nkryuchkov Nov 13, 2024
23bbee8
remove BeaconNetwork from Committee
nkryuchkov Nov 13, 2024
3394f30
remove GetBeaconNetwork from beacon client
nkryuchkov Nov 13, 2024
5a22d3d
fix TestNetworkConfig
nkryuchkov Nov 13, 2024
f2c0793
fix message validation tests
nkryuchkov Nov 13, 2024
b3f6c83
fix event handler tests
nkryuchkov Nov 14, 2024
01c0db3
fix roundtimer tests
nkryuchkov Nov 14, 2024
409a7df
fix voluntary exit tests
nkryuchkov Nov 16, 2024
e118c84
fix some duty scheduler tests
nkryuchkov Nov 18, 2024
5eeca6b
fix duty scheduler tests
nkryuchkov Nov 18, 2024
59a4061
Merge branch 'stage' into override-spec-beacon-config
nkryuchkov Nov 18, 2024
f06341b
fix build/lint issues after merging
nkryuchkov Nov 18, 2024
e531b20
fix beacon client tests
nkryuchkov Nov 18, 2024
85bbc8f
fix ekm tests
nkryuchkov Nov 18, 2024
7537661
fix testing config
nkryuchkov Nov 19, 2024
0068eb7
fix spec tests
nkryuchkov Nov 19, 2024
d056a5a
move networkconfig to network/config
nkryuchkov Nov 19, 2024
ee34910
fix goclient error return
nkryuchkov Nov 19, 2024
efb3795
improve comments on beacon node response examples
nkryuchkov Nov 19, 2024
df09d46
rename and move some things
nkryuchkov Nov 19, 2024
efed41c
add TODOs
nkryuchkov Nov 19, 2024
cfd5e6e
use one epoch duration from network config
nkryuchkov Nov 19, 2024
384d38f
get missing beacon network parameters from beacon client
nkryuchkov Nov 19, 2024
3aa7449
use default beacon configuration values if they cannot be fetched fro…
nkryuchkov Nov 19, 2024
bb2e872
fix linter
nkryuchkov Nov 19, 2024
3c27ea0
fix duty scheduler tests
nkryuchkov Nov 19, 2024
eea1b29
fix config setup logic
nkryuchkov Nov 20, 2024
b525ed6
add readme
nkryuchkov Nov 20, 2024
ea0aa7a
Merge branch 'stage' into override-spec-beacon-config
nkryuchkov Nov 20, 2024
ee272a8
fix issues after merging
nkryuchkov Nov 20, 2024
0ee2c78
add a TODO
nkryuchkov Nov 20, 2024
373349c
get genesis delay from beacon node
nkryuchkov Nov 20, 2024
ba1cbc5
get rid of GenesisEpoch
nkryuchkov Nov 20, 2024
3c1c6db
delete json tags
nkryuchkov Nov 20, 2024
b042f3f
use genesis data from /eth/v1/beacon/genesis instead of /eth/v1/confi…
nkryuchkov Nov 20, 2024
d5b3c15
cleanup
nkryuchkov Nov 20, 2024
f69d910
cleanup [2]
nkryuchkov Nov 20, 2024
bc2b80f
add MaxValidatorsPerCommittee and TotalEthereumValidators to SSV config
nkryuchkov Nov 20, 2024
56d0fec
fix SSV config receiver names
nkryuchkov Nov 20, 2024
cd1a337
delete genesis epoch leftovers
nkryuchkov Nov 20, 2024
36df187
fix names of params
nkryuchkov Nov 20, 2024
edbf9ea
fix duty scheduler tests
nkryuchkov Nov 20, 2024
c3b7777
fix message rate tests
nkryuchkov Nov 20, 2024
711db0d
fix remaining issues in config generation
nkryuchkov Nov 29, 2024
cc613ca
revert moving networkconfig package
nkryuchkov Jan 13, 2025
d774784
Merge branch 'stage' into override-spec-beacon-config
nkryuchkov Jan 15, 2025
a0d2bf2
fix issues after merging
nkryuchkov Jan 15, 2025
31cd282
don't pass network config to NewSignerStorage
nkryuchkov Jan 15, 2025
38a43ef
don't pass network config to migrations
nkryuchkov Jan 15, 2025
53115ac
delete MaxValidatorsPerCommittee from network config
nkryuchkov Jan 15, 2025
7197e34
delete beacon configs for real network as they are to be obtained fro…
nkryuchkov Jan 15, 2025
e2589ab
cleanup network config method usage in task executor
nkryuchkov Jan 15, 2025
cffb127
use BaseRunner.NetworkConfig instead of BaseRunner.DomainType
nkryuchkov Jan 15, 2025
3ee547e
don't use BaseRunner.DomainType
nkryuchkov Jan 15, 2025
9f0bec3
get rid of DomainType in BaseRunner
nkryuchkov Jan 15, 2025
f447724
use beacon config instead of network config in committee runner
nkryuchkov Jan 15, 2025
9863041
attempt to fix config validation
nkryuchkov Jan 15, 2025
d1535c5
fix e2m tests
nkryuchkov Jan 15, 2025
ab1e63c
Merge branch 'stage' into override-spec-beacon-config
nkryuchkov Jan 16, 2025
923127b
fix build issues after merging
nkryuchkov Jan 16, 2025
c1862c2
delete network config from exporter handler
nkryuchkov Jan 16, 2025
f5331dd
delete network config from non-committee validator
nkryuchkov Jan 16, 2025
600751e
fix comments
nkryuchkov Jan 17, 2025
38d0503
remove redundant parentheses
nkryuchkov Jan 17, 2025
fd82a62
add metrics for Spec and Genesis calls
nkryuchkov Jan 17, 2025
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
2 changes: 0 additions & 2 deletions api/handlers/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import (

"github.com/attestantio/go-eth2-client/spec/phase0"
spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/networkconfig"
qbftstorage "github.com/ssvlabs/ssv/protocol/v2/qbft/storage"

"github.com/ssvlabs/ssv/api"
ibftstorage "github.com/ssvlabs/ssv/ibft/storage"
)

type Exporter struct {
NetworkConfig networkconfig.NetworkConfig
ParticipantStores *ibftstorage.ParticipantStores
}

Expand Down
10 changes: 5 additions & 5 deletions beacon/goclient/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
gc.waitToSlotTwoThirds(slot)

// differ from spec because we need to subscribe to subnet
isAggregator, err := isAggregator(committeeLength, slotSig)
isAggregator, err := gc.isAggregator(committeeLength, slotSig)

Check warning on line 24 in beacon/goclient/aggregator.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/aggregator.go#L24

Added line #L24 was not covered by tests
if err != nil {
return nil, DataVersionNil, fmt.Errorf("failed to check if validator is an aggregator: %w", err)
}
Expand Down Expand Up @@ -94,8 +94,8 @@
// committee = get_beacon_committee(state, slot, index)
// modulo = max(1, len(committee) // TARGET_AGGREGATORS_PER_COMMITTEE)
// return bytes_to_uint64(hash(slot_signature)[0:8]) % modulo == 0
func isAggregator(committeeCount uint64, slotSig []byte) (bool, error) {
modulo := committeeCount / TargetAggregatorsPerCommittee
func (gc *GoClient) isAggregator(committeeCount uint64, slotSig []byte) (bool, error) {
modulo := committeeCount / gc.BeaconConfig().TargetAggregatorsPerCommittee

Check warning on line 98 in beacon/goclient/aggregator.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/aggregator.go#L97-L98

Added lines #L97 - L98 were not covered by tests
if modulo == 0 {
// Modulo must be at least 1.
modulo = 1
Expand All @@ -107,9 +107,9 @@

// waitToSlotTwoThirds waits until two-third of the slot has transpired (SECONDS_PER_SLOT * 2 / 3 seconds after the start of slot)
func (gc *GoClient) waitToSlotTwoThirds(slot phase0.Slot) {
oneThird := gc.network.SlotDurationSec() / 3 /* one third of slot duration */
oneThird := gc.BeaconConfig().SlotDuration / 3 /* one third of slot duration */

Check warning on line 110 in beacon/goclient/aggregator.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/aggregator.go#L110

Added line #L110 was not covered by tests

finalTime := gc.slotStartTime(slot).Add(2 * oneThird)
finalTime := gc.BeaconConfig().GetSlotStartTime(slot).Add(2 * oneThird)

Check warning on line 112 in beacon/goclient/aggregator.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/aggregator.go#L112

Added line #L112 was not covered by tests
wait := time.Until(finalTime)
if wait <= 0 {
return
Expand Down
51 changes: 27 additions & 24 deletions beacon/goclient/attest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ import (
"github.com/attestantio/go-eth2-client/spec"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/sourcegraph/conc/pool"
"github.com/ssvlabs/ssv-spec/types"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/slotticker"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
registrystorage "github.com/ssvlabs/ssv/registry/storage"
"github.com/ssvlabs/ssv/utils/hashmap"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ssvlabs/ssv/utils/hashmap"
)

func TestGoClient_GetAttestationData(t *testing.T) {
Expand Down Expand Up @@ -58,6 +54,29 @@ func TestGoClient_GetAttestationData(t *testing.T) {
"version": "Lighthouse/v4.5.0-441fc16/x86_64-linux"
}
}`),
"/eth/v1/config/spec": []byte(`{
"data": {
"CONFIG_NAME": "holesky",
"GENESIS_FORK_VERSION": "0x01017000",
"CAPELLA_FORK_VERSION": "0x04017000",
"MIN_GENESIS_TIME": "1695902100",
"SECONDS_PER_SLOT": "12",
"SLOTS_PER_EPOCH": "32",
"EPOCHS_PER_SYNC_COMMITTEE_PERIOD": "256",
"SYNC_COMMITTEE_SIZE": "512",
"SYNC_COMMITTEE_SUBNET_COUNT": "4",
"TARGET_AGGREGATORS_PER_COMMITTEE": "16",
"TARGET_AGGREGATORS_PER_SYNC_SUBCOMMITTEE": "16",
"INTERVALS_PER_SLOT": "3"
}
}`),
"/eth/v1/beacon/genesis": []byte(`{
"data": {
"genesis_time": "1695902400",
"genesis_validators_root": "0x9143aa7c615a7f7115e2b6aac319c03529df8242ae705fba9df39b79c59fa8b1",
"genesis_fork_version": "0x01017000"
}
}`),
}
for reqPath, respData := range expInitRequests {
if reqPath == r.URL.Path {
Expand Down Expand Up @@ -135,20 +154,12 @@ func TestGoClient_GetAttestationData(t *testing.T) {

client, err := New(
zap.NewNop(),
beacon.Options{
Options{
Context: ctx,
Network: beacon.NewNetwork(types.MainNetwork),
BeaconNodeAddr: server.URL,
CommonTimeout: 1 * time.Second,
LongTimeout: 1 * time.Second,
},
operatordatastore.New(&registrystorage.OperatorData{ID: 1}),
func() slotticker.SlotTicker {
return slotticker.New(zap.NewNop(), slotticker.Config{
SlotDuration: 12 * time.Second,
GenesisTime: time.Now(),
})
},
)
require.NoError(t, err)

Expand Down Expand Up @@ -245,20 +256,12 @@ func TestGoClient_GetAttestationData(t *testing.T) {

client, err := New(
zap.NewNop(),
beacon.Options{
Options{
Context: ctx,
Network: beacon.NewNetwork(types.MainNetwork),
BeaconNodeAddr: server.URL,
CommonTimeout: 1 * time.Second,
LongTimeout: 1 * time.Second,
},
operatordatastore.New(&registrystorage.OperatorData{ID: 1}),
func() slotticker.SlotTicker {
return slotticker.New(zap.NewNop(), slotticker.Config{
SlotDuration: 12 * time.Second,
GenesisTime: time.Now(),
})
},
)
require.NoError(t, err)

Expand Down
72 changes: 28 additions & 44 deletions beacon/goclient/goclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
"go.uber.org/zap"
"tailscale.com/util/singleflight"

spectypes "github.com/ssvlabs/ssv-spec/types"
"github.com/ssvlabs/ssv/logging/fields"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/slotticker"
beaconprotocol "github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
"github.com/ssvlabs/ssv/utils/casts"
"github.com/ssvlabs/ssv/networkconfig"
)

const (
Expand Down Expand Up @@ -108,19 +104,17 @@

// GoClient implementing Beacon struct
type GoClient struct {
log *zap.Logger
ctx context.Context
network beaconprotocol.Network
client Client
nodeVersion string
nodeClient NodeClient
gasLimit uint64
log *zap.Logger
ctx context.Context
beaconConfig *networkconfig.Beacon // using pointer to make sure it's fetched
client Client
nodeVersion string
nodeClient NodeClient
gasLimit uint64

syncDistanceTolerance phase0.Slot
nodeSyncingFn func(ctx context.Context, opts *api.NodeSyncingOpts) (*api.Response[*apiv1.SyncState], error)

operatorDataStore operatordatastore.OperatorDataStore

registrationMu sync.Mutex
registrationLastSlot phase0.Slot
registrationCache map[phase0.BLSPubKey]*api.VersionedSignedValidatorRegistration
Expand All @@ -141,11 +135,9 @@
// New init new client and go-client instance
func New(
logger *zap.Logger,
opt beaconprotocol.Options,
operatorDataStore operatordatastore.OperatorDataStore,
slotTickerProvider slotticker.Provider,
opt Options,
) (*GoClient, error) {
logger.Info("consensus client: connecting", fields.Address(opt.BeaconNodeAddr), fields.Network(string(opt.Network.BeaconNetwork)))
logger.Info("consensus client: connecting", fields.Address(opt.BeaconNodeAddr))

commonTimeout := opt.CommonTimeout
if commonTimeout == 0 {
Expand Down Expand Up @@ -175,19 +167,12 @@
client := &GoClient{
log: logger,
ctx: opt.Context,
network: opt.Network,
client: httpClient.(*eth2clienthttp.Service),
gasLimit: opt.GasLimit,
syncDistanceTolerance: phase0.Slot(opt.SyncDistanceTolerance),
operatorDataStore: operatorDataStore,
registrationCache: map[phase0.BLSPubKey]*api.VersionedSignedValidatorRegistration{},
attestationDataCache: ttlcache.New(
// we only fetch attestation data during the slot of the relevant duty (and never later),
// hence caching it for 2 slots is sufficient
ttlcache.WithTTL[phase0.Slot, *phase0.AttestationData](2 * opt.Network.SlotDurationSec()),
),
commonTimeout: commonTimeout,
longTimeout: longTimeout,
commonTimeout: commonTimeout,
longTimeout: longTimeout,
}

client.nodeSyncingFn = client.nodeSyncing
Expand All @@ -209,17 +194,29 @@
client.nodeVersion = nodeVersionResp.Data
client.nodeClient = ParseNodeClient(nodeVersionResp.Data)

beaconConfig, err := client.fetchBeaconConfig()
if err != nil {
return nil, fmt.Errorf("fetch spec config: %w", err)
}

Check warning on line 200 in beacon/goclient/goclient.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/goclient.go#L199-L200

Added lines #L199 - L200 were not covered by tests
client.beaconConfig = beaconConfig

client.attestationDataCache = ttlcache.New(
// we only fetch attestation data during the slot of the relevant duty (and never later),
// hence caching it for 2 slots is sufficient
ttlcache.WithTTL[phase0.Slot, *phase0.AttestationData](2 * beaconConfig.SlotDuration),
)

// Start automatic expired item deletion for attestationDataCache.
go client.attestationDataCache.Start()

logger.Info("consensus client connected",
fields.Name(httpClient.Name()),
fields.Address(httpClient.Address()),
zap.String("client", string(client.nodeClient)),
zap.String("version", client.nodeVersion),
zap.String("config", beaconConfig.String()),
)

go client.registrationSubmitter(slotTickerProvider)
y0sher marked this conversation as resolved.
Show resolved Hide resolved
// Start automatic expired item deletion for attestationDataCache.
go client.attestationDataCache.Start()

return client, nil
}

Expand Down Expand Up @@ -279,19 +276,6 @@
return nil
}

// GetBeaconNetwork returns the beacon network the node is on
func (gc *GoClient) GetBeaconNetwork() spectypes.BeaconNetwork {
return gc.network.BeaconNetwork
}

// SlotStartTime returns the start time in terms of its unix epoch
// value.
func (gc *GoClient) slotStartTime(slot phase0.Slot) time.Time {
duration := time.Second * casts.DurationFromUint64(uint64(slot)*uint64(gc.network.SlotDurationSec().Seconds()))
startTime := time.Unix(gc.network.MinGenesisTime(), 0).Add(duration)
return startTime
}

func (gc *GoClient) Events(ctx context.Context, topics []string, handler eth2client.EventHandlerFunc) error {
if err := gc.client.Events(ctx, topics, handler); err != nil {
gc.log.Error(clResponseErrMsg,
Expand Down
17 changes: 3 additions & 14 deletions beacon/goclient/goclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ import (
"github.com/attestantio/go-eth2-client/api"
v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ssvlabs/ssv-spec/types"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/slotticker"
"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
registrystorage "github.com/ssvlabs/ssv/registry/storage"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ssvlabs/ssv/protocol/v2/blockchain/beacon"
)

func TestHealthy(t *testing.T) {
Expand Down Expand Up @@ -162,20 +159,12 @@ func TestTimeouts(t *testing.T) {
func mockClient(ctx context.Context, serverURL string, commonTimeout, longTimeout time.Duration) (beacon.BeaconNode, error) {
return New(
zap.NewNop(),
beacon.Options{
Options{
Context: ctx,
Network: beacon.NewNetwork(types.MainNetwork),
BeaconNodeAddr: serverURL,
CommonTimeout: commonTimeout,
LongTimeout: longTimeout,
},
operatordatastore.New(&registrystorage.OperatorData{ID: 1}),
func() slotticker.SlotTicker {
return slotticker.New(zap.NewNop(), slotticker.Config{
SlotDuration: 12 * time.Second,
GenesisTime: time.Now(),
})
},
)
}

Expand Down
16 changes: 16 additions & 0 deletions beacon/goclient/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package goclient

import (
"context"
"time"
)

// Options for controller struct creation
type Options struct {
Context context.Context
BeaconNodeAddr string `yaml:"BeaconNodeAddr" env:"BEACON_NODE_ADDR" env-required:"true"`
SyncDistanceTolerance uint64 `yaml:"SyncDistanceTolerance" env:"BEACON_SYNC_DISTANCE_TOLERANCE" env-default:"4" env-description:"The number of out-of-sync slots we can tolerate"`
GasLimit uint64
CommonTimeout time.Duration // Optional.
LongTimeout time.Duration // Optional.
}
26 changes: 16 additions & 10 deletions beacon/goclient/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"github.com/attestantio/go-eth2-client/spec/phase0"
ssz "github.com/ferranbt/fastssz"
spectypes "github.com/ssvlabs/ssv-spec/types"
"go.uber.org/zap"

"github.com/ssvlabs/ssv/logging/fields"
operatordatastore "github.com/ssvlabs/ssv/operator/datastore"
"github.com/ssvlabs/ssv/operator/slotticker"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -302,7 +304,7 @@
Message: &eth2apiv1.ValidatorRegistration{
FeeRecipient: feeRecipient,
GasLimit: gc.gasLimit,
Timestamp: gc.network.GetSlotStartTime(gc.network.GetEpochFirstSlot(gc.network.EstimatedCurrentEpoch())),
Timestamp: gc.BeaconConfig().EstimatedCurrentEpochStartTime(),

Check warning on line 307 in beacon/goclient/proposer.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/proposer.go#L307

Added line #L307 was not covered by tests
Pubkey: pk,
},
Signature: sig,
Expand All @@ -311,10 +313,14 @@
return signedReg
}

func (gc *GoClient) registrationSubmitter(slotTickerProvider slotticker.Provider) {
operatorID := gc.operatorDataStore.AwaitOperatorID()
func (gc *GoClient) RegistrationSubmitter(operatorDataStore operatordatastore.OperatorDataStore) {
operatorID := operatorDataStore.AwaitOperatorID()

ticker := slotticker.New(gc.log, slotticker.Config{
SlotDuration: gc.BeaconConfig().SlotDuration,
GenesisTime: gc.BeaconConfig().GenesisTime(),
})

Check warning on line 322 in beacon/goclient/proposer.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/proposer.go#L316-L322

Added lines #L316 - L322 were not covered by tests

ticker := slotTickerProvider()
for {
select {
case <-gc.ctx.Done():
Expand All @@ -326,20 +332,20 @@
}

func (gc *GoClient) submitRegistrationsFromCache(currentSlot phase0.Slot, operatorID spectypes.OperatorID) {
slotsPerEpoch := gc.network.SlotsPerEpoch()
slotsPerEpoch := gc.BeaconConfig().SlotsPerEpoch

Check warning on line 335 in beacon/goclient/proposer.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/proposer.go#L335

Added line #L335 was not covered by tests

// Lock:
// - getting and updating last slot to avoid multiple submission (both should be an atomic action but cannot be done with CAS)
// - getting and updating registration cache
gc.registrationMu.Lock()

slotsSinceLastRegistration := currentSlot - gc.registrationLastSlot
operatorSubmissionSlotModulo := operatorID % slotsPerEpoch
operatorSubmissionSlotModulo := phase0.Slot(operatorID) % slotsPerEpoch

Check warning on line 343 in beacon/goclient/proposer.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/proposer.go#L343

Added line #L343 was not covered by tests

hasRegistrations := len(gc.registrationCache) != 0
operatorSubmissionSlot := uint64(currentSlot)%slotsPerEpoch == operatorSubmissionSlotModulo
oneEpochPassed := slotsSinceLastRegistration >= phase0.Slot(slotsPerEpoch)
twoEpochsAndOperatorDelayPassed := uint64(slotsSinceLastRegistration) >= slotsPerEpoch*2+operatorSubmissionSlotModulo
operatorSubmissionSlot := currentSlot%slotsPerEpoch == operatorSubmissionSlotModulo
oneEpochPassed := slotsSinceLastRegistration >= slotsPerEpoch
twoEpochsAndOperatorDelayPassed := slotsSinceLastRegistration >= slotsPerEpoch*2+operatorSubmissionSlotModulo

Check warning on line 348 in beacon/goclient/proposer.go

View check run for this annotation

Codecov / codecov/patch

beacon/goclient/proposer.go#L346-L348

Added lines #L346 - L348 were not covered by tests

if hasRegistrations && (oneEpochPassed && operatorSubmissionSlot || twoEpochsAndOperatorDelayPassed) {
gc.registrationLastSlot = currentSlot
Expand Down
Loading
Loading