From 21183537934bdfda1e1a692a7134e25590d76d7c Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Fri, 17 Nov 2023 17:20:42 +0000 Subject: [PATCH 1/2] Update dependencies. --- go.mod | 4 +- go.sum | 8 +- main.go | 10 +-- mock/eth2client.go | 86 ++++--------------- .../dirk/service_internal_test.go | 13 ++- services/accountmanager/dirk/service_test.go | 19 ++-- services/accountmanager/wallet/parameters.go | 12 +-- services/accountmanager/wallet/service.go | 50 +++++++---- .../standard/parameters.go | 37 +++----- .../attestationaggregator/standard/service.go | 25 ++++-- services/attester/standard/parameters.go | 12 +-- services/attester/standard/service.go | 14 ++- .../standard/prepare_test.go | 19 ++-- .../beaconblockproposer/standard/propose.go | 63 ++------------ .../standard/propose_test.go | 19 ++-- .../standard/service_test.go | 19 ++-- .../standard/service_test.go | 8 +- .../standard/proposerconfig_test.go | 21 ++--- services/blockrelay/standard/service_test.go | 20 ++--- services/chaintime/standard/parameters.go | 37 +++----- services/chaintime/standard/service.go | 32 +++++-- services/chaintime/standard/service_test.go | 78 ++++++----------- services/controller/standard/parameters.go | 3 +- services/controller/standard/service.go | 11 +-- services/controller/standard/service_test.go | 19 ++-- services/metrics/prometheus/service_test.go | 8 +- .../proposalpreparer/standard/service_test.go | 20 ++--- .../standard/updatepreparations_test.go | 14 ++- services/signer/standard/service.go | 3 +- services/submitter/multinode/helpers.go | 3 +- .../standard/service.go | 2 +- .../standard/service.go | 2 +- .../standard/service_test.go | 19 ++-- .../best/attestationdata_test.go | 13 +-- .../attestationdata/best/service_test.go | 26 ++---- .../best/beaconblockproposal_test.go | 14 ++- .../best/events_internal_test.go | 12 +-- .../best/score_internal_test.go | 12 +-- .../beaconblockproposal/best/service.go | 3 +- .../beaconblockproposal/best/service_test.go | 12 +-- .../best/blindedbeaconblockproposal_test.go | 16 ++-- .../best/events_internal_test.go | 12 +-- .../blindedbeaconblockproposal/best/score.go | 16 ++-- .../best/score_internal_test.go | 12 +-- .../best/service.go | 3 +- .../best/service_test.go | 12 +-- strategies/builderbid/best/service.go | 3 +- 47 files changed, 337 insertions(+), 539 deletions(-) diff --git a/go.mod b/go.mod index 5b612cdd..62db6f16 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.20 require ( github.com/attestantio/go-block-relay v0.2.0 - github.com/attestantio/go-builder-client v0.4.0 - github.com/attestantio/go-eth2-client v0.19.4 + github.com/attestantio/go-builder-client v0.4.1 + github.com/attestantio/go-eth2-client v0.19.5 github.com/aws/aws-sdk-go v1.46.4 github.com/holiman/uint256 v1.2.3 github.com/mitchellh/go-homedir v1.1.0 diff --git a/go.sum b/go.sum index c433e196..22f22b72 100644 --- a/go.sum +++ b/go.sum @@ -76,10 +76,10 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/attestantio/go-block-relay v0.2.0 h1:RiIDW6nLAfTYsD7bQ4W3MJVDlTIifyDUsHQvm5HWF3k= github.com/attestantio/go-block-relay v0.2.0/go.mod h1:6pjIGKOdIwP1AF0+TFF9kBVS1CueHec5sLSZX4U9XBg= -github.com/attestantio/go-builder-client v0.4.0 h1:GgVraoNtRhNZehTitdJx+68Ys25EatyiaNDBemphcpw= -github.com/attestantio/go-builder-client v0.4.0/go.mod h1:/UPtakG1fmY/MuxB0y3zmSbh+C1tJVB4TZM9kkfSEZ0= -github.com/attestantio/go-eth2-client v0.19.4 h1:SiiqYqx1EhIgdaToer4FrUuiyG3wnTR4Xwb7/YkbGxA= -github.com/attestantio/go-eth2-client v0.19.4/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM= +github.com/attestantio/go-builder-client v0.4.1 h1:1F4JVW9ElebH8cVhxs3jFSaWHy4NXGCePdUM7em/fLs= +github.com/attestantio/go-builder-client v0.4.1/go.mod h1:3u2Y8lHSPFaNJSRG1QFQsh11w+x7+5SLBNM6ajbqyxU= +github.com/attestantio/go-eth2-client v0.19.5 h1:4V+vhXsCYji5jWrlONbr03GV7qoLRdzq96dLgXaqmek= +github.com/attestantio/go-eth2-client v0.19.5/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM= github.com/aws/aws-sdk-go v1.44.81/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go v1.46.4 h1:48tKgtm9VMPkb6y7HuYlsfhQmoIRAsTEXTsWLVlty4M= github.com/aws/aws-sdk-go v1.46.4/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= diff --git a/main.go b/main.go index adab1d9f..f0d73fa6 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,7 @@ import ( "github.com/attestantio/go-block-relay/services/blockauctioneer" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/bellatrix" "github.com/attestantio/vouch/services/accountmanager" dirkaccountmanager "github.com/attestantio/vouch/services/accountmanager/dirk" @@ -448,9 +449,8 @@ func startBasicServices(ctx context.Context, log.Trace().Msg("Starting chain time service") chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(util.LogLevel("chaintime")), - standardchaintime.WithGenesisTimeProvider(eth2Client.(eth2client.GenesisTimeProvider)), - standardchaintime.WithSlotDurationProvider(eth2Client.(eth2client.SlotDurationProvider)), - standardchaintime.WithSlotsPerEpochProvider(eth2Client.(eth2client.SlotsPerEpochProvider)), + standardchaintime.WithGenesisProvider(eth2Client.(eth2client.GenesisProvider)), + standardchaintime.WithSpecProvider(eth2Client.(eth2client.SpecProvider)), ) if err != nil { return nil, nil, nil, errors.Wrap(err, "failed to start chain time service") @@ -1020,7 +1020,7 @@ func startAccountManager(ctx context.Context, monitor metrics.Service, eth2Clien walletaccountmanager.WithAccountPaths(viper.GetStringSlice("accountmanager.wallet.accounts")), walletaccountmanager.WithPassphrases(passphrases), walletaccountmanager.WithLocations(viper.GetStringSlice("accountmanager.wallet.locations")), - walletaccountmanager.WithSlotsPerEpochProvider(eth2Client.(eth2client.SlotsPerEpochProvider)), + walletaccountmanager.WithSpecProvider(eth2Client.(eth2client.SpecProvider)), walletaccountmanager.WithFarFutureEpochProvider(eth2Client.(eth2client.FarFutureEpochProvider)), walletaccountmanager.WithDomainProvider(eth2Client.(eth2client.DomainProvider)), walletaccountmanager.WithCurrentEpochProvider(chainTime), @@ -1540,7 +1540,7 @@ func runCommands(ctx context.Context, func consensusClientCapabilities(ctx context.Context, consensusClient eth2client.Service) (bool, bool, bool, error) { // Decide if the ETH2 client is capable of Altair. altairCapable := false - specResponse, err := consensusClient.(eth2client.SpecProvider).Spec(ctx) + specResponse, err := consensusClient.(eth2client.SpecProvider).Spec(ctx, &api.SpecOpts{}) if err != nil { return false, false, false, errors.Wrap(err, "failed to obtain spec") } diff --git a/mock/eth2client.go b/mock/eth2client.go index 3fb17c20..6768e5ac 100644 --- a/mock/eth2client.go +++ b/mock/eth2client.go @@ -33,51 +33,25 @@ import ( "github.com/prysmaticlabs/go-bitfield" ) -// GenesisTimeProvider is a mock for eth2client.GenesisTimeProvider. -type GenesisTimeProvider struct { +// GenesisProvider is a mock for eth2client.GenesisProvider. +type GenesisProvider struct { genesisTime time.Time } -// NewGenesisTimeProvider returns a mock genesis time provider with the provided value. -func NewGenesisTimeProvider(genesisTime time.Time) eth2client.GenesisTimeProvider { - return &GenesisTimeProvider{ +// NewGenesisProvider returns a mock genesis provider with the provided value. +func NewGenesisProvider(genesisTime time.Time) eth2client.GenesisProvider { + return &GenesisProvider{ genesisTime: genesisTime, } } -// GenesisTime is a mock. -func (m *GenesisTimeProvider) GenesisTime(_ context.Context) (time.Time, error) { - return m.genesisTime, nil -} - -// SlotDurationProvider is a mock for eth2client.SlotDurationProvider. -type SlotDurationProvider struct { - slotDuration time.Duration -} - -// NewSlotDurationProvider returns a mock slot duration provider with the provided value. -func NewSlotDurationProvider(slotDuration time.Duration) eth2client.SlotDurationProvider { - return &SlotDurationProvider{ - slotDuration: slotDuration, - } -} - -// SlotDuration is a mock. -func (m *SlotDurationProvider) SlotDuration(_ context.Context) (time.Duration, error) { - return m.slotDuration, nil -} - -// ErroringSlotDurationProvider is a mock for eth2client.SlotDurationProvider. -type ErroringSlotDurationProvider struct{} - -// NewErroringSlotDurationProvider returns a mock slot duration provider that errors. -func NewErroringSlotDurationProvider() eth2client.SlotDurationProvider { - return &ErroringSlotDurationProvider{} -} - -// SlotDuration is a mock. -func (*ErroringSlotDurationProvider) SlotDuration(_ context.Context) (time.Duration, error) { - return 0, errors.New("mock") +// Genesis is a mock. +func (m *GenesisProvider) Genesis(_ context.Context, _ *api.GenesisOpts) (*api.Response[*apiv1.Genesis], error) { + return &api.Response[*apiv1.Genesis]{ + Data: &apiv1.Genesis{ + GenesisTime: m.genesisTime, + }, + }, nil } // FarFutureEpochProvider is a mock for eth2client.FarFutureEpochProvider. @@ -97,36 +71,6 @@ func (m *FarFutureEpochProvider) FarFutureEpoch(_ context.Context) (phase0.Epoch return m.farFutureEpoch, nil } -// SlotsPerEpochProvider is a mock for eth2client.SlotsPerEpochProvider. -type SlotsPerEpochProvider struct { - slotsPerEpoch uint64 -} - -// NewSlotsPerEpochProvider returns a mock slots per epoch provider with the provided value. -func NewSlotsPerEpochProvider(slotsPerEpoch uint64) eth2client.SlotsPerEpochProvider { - return &SlotsPerEpochProvider{ - slotsPerEpoch: slotsPerEpoch, - } -} - -// SlotsPerEpoch is a mock. -func (m *SlotsPerEpochProvider) SlotsPerEpoch(_ context.Context) (uint64, error) { - return m.slotsPerEpoch, nil -} - -// ErroringSlotsPerEpochProvider is a mock for eth2client.SlotsPerEpochProvider. -type ErroringSlotsPerEpochProvider struct{} - -// NewErroringSlotsPerEpochProvider returns a mock slots per epoch provider that errors. -func NewErroringSlotsPerEpochProvider() eth2client.SlotsPerEpochProvider { - return &ErroringSlotsPerEpochProvider{} -} - -// SlotsPerEpoch is a mock. -func (*ErroringSlotsPerEpochProvider) SlotsPerEpoch(_ context.Context) (uint64, error) { - return 0, errors.New("error") -} - // ProposerDutiesProvider is a mock for eth2client.ProposerDutiesProvider. type ProposerDutiesProvider struct{} @@ -1263,7 +1207,7 @@ func NewErroringSpecProvider() eth2client.SpecProvider { } // Spec is a mock. -func (*ErroringSpecProvider) Spec(_ context.Context) (*api.Response[map[string]any], error) { +func (*ErroringSpecProvider) Spec(_ context.Context, _ *api.SpecOpts) (*api.Response[map[string]any], error) { return nil, errors.New("error") } @@ -1276,7 +1220,7 @@ func NewSpecProvider() eth2client.SpecProvider { } // Spec is a mock. -func (*SpecProvider) Spec(_ context.Context) (*api.Response[map[string]any], error) { +func (*SpecProvider) Spec(_ context.Context, _ *api.SpecOpts) (*api.Response[map[string]any], error) { return &api.Response[map[string]any]{ Data: map[string]any{ // Mainnet params (give or take). @@ -1312,7 +1256,7 @@ func NewForkScheduleProvider() eth2client.ForkScheduleProvider { } // ForkSchedule is a mock. -func (*ForkScheduleProvider) ForkSchedule(_ context.Context) (*api.Response[[]*phase0.Fork], error) { +func (*ForkScheduleProvider) ForkSchedule(_ context.Context, _ *api.ForkScheduleOpts) (*api.Response[[]*phase0.Fork], error) { return &api.Response[[]*phase0.Fork]{ Data: []*phase0.Fork{ { diff --git a/services/accountmanager/dirk/service_internal_test.go b/services/accountmanager/dirk/service_internal_test.go index 03e5387a..4d34b257 100644 --- a/services/accountmanager/dirk/service_internal_test.go +++ b/services/accountmanager/dirk/service_internal_test.go @@ -174,15 +174,12 @@ func TestAccounts(t *testing.T) { func setupService(ctx context.Context, t *testing.T, endpoints []string, accountPaths []string) (*Service, error) { genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - mockGenesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - mockSlotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - mockSlotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(mockGenesisTimeProvider), - standardchaintime.WithSlotDurationProvider(mockSlotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/services/accountmanager/dirk/service_test.go b/services/accountmanager/dirk/service_test.go index ab1d0a47..9bef55ff 100644 --- a/services/accountmanager/dirk/service_test.go +++ b/services/accountmanager/dirk/service_test.go @@ -32,21 +32,18 @@ func TestService(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - mockGenesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - mockSlotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - mockSlotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() + chainTime, err := standardchaintime.New(ctx, + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), + ) + require.NoError(t, err) domainProvider := mock.NewDomainProvider() validatorsManager := mock.NewValidatorsManager() farFutureEpochProvider := mock.NewFarFutureEpochProvider(0xffffffffffffffff) - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(mockGenesisTimeProvider), - standardchaintime.WithSlotDurationProvider(mockSlotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), - ) - require.NoError(t, err) tests := []struct { name string diff --git a/services/accountmanager/wallet/parameters.go b/services/accountmanager/wallet/parameters.go index 1a01fd24..e9d3917c 100644 --- a/services/accountmanager/wallet/parameters.go +++ b/services/accountmanager/wallet/parameters.go @@ -30,7 +30,7 @@ type parameters struct { accountPaths []string passphrases [][]byte validatorsManager validatorsmanager.Service - slotsPerEpochProvider eth2client.SlotsPerEpochProvider + specProvider eth2client.SpecProvider domainProvider eth2client.DomainProvider farFutureEpochProvider eth2client.FarFutureEpochProvider currentEpochProvider chaintime.Service @@ -96,10 +96,10 @@ func WithValidatorsManager(manager validatorsmanager.Service) Parameter { }) } -// WithSlotsPerEpochProvider sets the slots per epoch provider. -func WithSlotsPerEpochProvider(provider eth2client.SlotsPerEpochProvider) Parameter { +// WithSpecProvider sets the specification provider. +func WithSpecProvider(provider eth2client.SpecProvider) Parameter { return parameterFunc(func(p *parameters) { - p.slotsPerEpochProvider = provider + p.specProvider = provider }) } @@ -150,8 +150,8 @@ func parseAndCheckParameters(params ...Parameter) (*parameters, error) { if parameters.validatorsManager == nil { return nil, errors.New("no validators manager specified") } - if parameters.slotsPerEpochProvider == nil { - return nil, errors.New("no slots per epoch provider specified") + if parameters.specProvider == nil { + return nil, errors.New("no spec provider specified") } if parameters.farFutureEpochProvider == nil { return nil, errors.New("no far future epoch provider specified") diff --git a/services/accountmanager/wallet/service.go b/services/accountmanager/wallet/service.go index 54801164..47c59755 100644 --- a/services/accountmanager/wallet/service.go +++ b/services/accountmanager/wallet/service.go @@ -21,7 +21,8 @@ import ( "sync" eth2client "github.com/attestantio/go-eth2-client" - api "github.com/attestantio/go-eth2-client/api/v1" + "github.com/attestantio/go-eth2-client/api" + apiv1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/chaintime" "github.com/attestantio/vouch/services/metrics" @@ -85,10 +86,21 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { } } - slotsPerEpoch, err := parameters.slotsPerEpochProvider.SlotsPerEpoch(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { - return nil, errors.Wrap(err, "failed to obtain slots per epoch") + return nil, errors.Wrap(err, "failed to obtain spec") } + spec := specResponse.Data + + tmp, exists := spec["SLOTS_PER_EPOCH"] + if !exists { + return nil, errors.New("failed to obtain SLOTS_PER_EPOCH") + } + slotsPerEpoch, ok := tmp.(uint64) + if !ok { + return nil, errors.New("SLOTS_PER_EPOCH of unexpected type") + } + farFutureEpoch, err := parameters.farFutureEpochProvider.FarFutureEpoch(ctx) if err != nil { return nil, errors.Wrap(err, "failed to obtain far future epoch") @@ -199,17 +211,17 @@ func (s *Service) ValidatingAccountsForEpoch(ctx context.Context, epoch phase0.E defer span.End() // stateCount is used to update metrics. - stateCount := map[api.ValidatorState]uint64{ - api.ValidatorStateUnknown: 0, - api.ValidatorStatePendingInitialized: 0, - api.ValidatorStatePendingQueued: 0, - api.ValidatorStateActiveOngoing: 0, - api.ValidatorStateActiveExiting: 0, - api.ValidatorStateActiveSlashed: 0, - api.ValidatorStateExitedUnslashed: 0, - api.ValidatorStateExitedSlashed: 0, - api.ValidatorStateWithdrawalPossible: 0, - api.ValidatorStateWithdrawalDone: 0, + stateCount := map[apiv1.ValidatorState]uint64{ + apiv1.ValidatorStateUnknown: 0, + apiv1.ValidatorStatePendingInitialized: 0, + apiv1.ValidatorStatePendingQueued: 0, + apiv1.ValidatorStateActiveOngoing: 0, + apiv1.ValidatorStateActiveExiting: 0, + apiv1.ValidatorStateActiveSlashed: 0, + apiv1.ValidatorStateExitedUnslashed: 0, + apiv1.ValidatorStateExitedSlashed: 0, + apiv1.ValidatorStateWithdrawalPossible: 0, + apiv1.ValidatorStateWithdrawalDone: 0, } validatingAccounts := make(map[phase0.ValidatorIndex]e2wtypes.Account) @@ -220,9 +232,9 @@ func (s *Service) ValidatingAccountsForEpoch(ctx context.Context, epoch phase0.E validators := s.validatorsManager.ValidatorsByPubKey(ctx, pubKeys) for index, validator := range validators { - state := api.ValidatorToState(validator, nil, epoch, s.farFutureEpoch) + state := apiv1.ValidatorToState(validator, nil, epoch, s.farFutureEpoch) stateCount[state]++ - if state == api.ValidatorStateActiveOngoing || state == api.ValidatorStateActiveExiting { + if state == apiv1.ValidatorStateActiveOngoing || state == apiv1.ValidatorStateActiveExiting { account := s.accounts[validator.PublicKey] log.Trace(). Str("name", account.Name()). @@ -236,7 +248,7 @@ func (s *Service) ValidatingAccountsForEpoch(ctx context.Context, epoch phase0.E // Update metrics if this is the current epoch. if epoch == s.currentEpochProvider.CurrentEpoch() { - stateCount[api.ValidatorStateUnknown] += uint64(len(s.accounts) - len(validators)) + stateCount[apiv1.ValidatorStateUnknown] += uint64(len(s.accounts) - len(validators)) for state, count := range stateCount { s.monitor.Accounts(strings.ToLower(state.String()), count) } @@ -267,8 +279,8 @@ func (s *Service) ValidatingAccountsForEpochByIndex(ctx context.Context, epoch p if _, present := indexPresenceMap[index]; !present { continue } - state := api.ValidatorToState(validator, nil, epoch, s.farFutureEpoch) - if state == api.ValidatorStateActiveOngoing || state == api.ValidatorStateActiveExiting { + state := apiv1.ValidatorToState(validator, nil, epoch, s.farFutureEpoch) + if state == apiv1.ValidatorStateActiveOngoing || state == apiv1.ValidatorStateActiveExiting { validatingAccounts[index] = s.accounts[validator.PublicKey] } } diff --git a/services/attestationaggregator/standard/parameters.go b/services/attestationaggregator/standard/parameters.go index 60fbda87..349bc52a 100644 --- a/services/attestationaggregator/standard/parameters.go +++ b/services/attestationaggregator/standard/parameters.go @@ -24,15 +24,14 @@ import ( ) type parameters struct { - logLevel zerolog.Level - monitor metrics.AttestationAggregationMonitor - slotsPerEpochProvider eth2client.SlotsPerEpochProvider - targetAggregatorsPerCommitteeProvider eth2client.TargetAggregatorsPerCommitteeProvider - validatingAccountsProvider accountmanager.ValidatingAccountsProvider - aggregateAttestationProvider eth2client.AggregateAttestationProvider - aggregateAttestationsSubmitter submitter.AggregateAttestationsSubmitter - slotSelectionSigner signer.SlotSelectionSigner - aggregateAndProofSigner signer.AggregateAndProofSigner + logLevel zerolog.Level + monitor metrics.AttestationAggregationMonitor + specProvider eth2client.SpecProvider + validatingAccountsProvider accountmanager.ValidatingAccountsProvider + aggregateAttestationProvider eth2client.AggregateAttestationProvider + aggregateAttestationsSubmitter submitter.AggregateAttestationsSubmitter + slotSelectionSigner signer.SlotSelectionSigner + aggregateAndProofSigner signer.AggregateAndProofSigner } // Parameter is the interface for service parameters. @@ -53,17 +52,10 @@ func WithLogLevel(logLevel zerolog.Level) Parameter { }) } -// WithSlotsPerEpochProvider sets the slots per epoch provider. -func WithSlotsPerEpochProvider(provider eth2client.SlotsPerEpochProvider) Parameter { +// WithSpecProvider sets the specification provider. +func WithSpecProvider(provider eth2client.SpecProvider) Parameter { return parameterFunc(func(p *parameters) { - p.slotsPerEpochProvider = provider - }) -} - -// WithTargetAggregatorsPerCommitteeProvider sets the target aggregators per attestation provider. -func WithTargetAggregatorsPerCommitteeProvider(provider eth2client.TargetAggregatorsPerCommitteeProvider) Parameter { - return parameterFunc(func(p *parameters) { - p.targetAggregatorsPerCommitteeProvider = provider + p.specProvider = provider }) } @@ -120,11 +112,8 @@ func parseAndCheckParameters(params ...Parameter) (*parameters, error) { } } - if parameters.targetAggregatorsPerCommitteeProvider == nil { - return nil, errors.New("no target aggregators per committee provider specified") - } - if parameters.slotsPerEpochProvider == nil { - return nil, errors.New("no slots per epoch provider specified") + if parameters.specProvider == nil { + return nil, errors.New("no spec provider specified") } if parameters.monitor == nil { return nil, errors.New("no monitor specified") diff --git a/services/attestationaggregator/standard/service.go b/services/attestationaggregator/standard/service.go index ccf757de..5fb0e894 100644 --- a/services/attestationaggregator/standard/service.go +++ b/services/attestationaggregator/standard/service.go @@ -62,13 +62,28 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - targetAggregatorsPerCommittee, err := parameters.targetAggregatorsPerCommitteeProvider.TargetAggregatorsPerCommittee(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { - return nil, errors.Wrap(err, "failed to obtain target aggregators per committee") + return nil, errors.Wrap(err, "failed to obtain spec") } - slotsPerEpoch, err := parameters.slotsPerEpochProvider.SlotsPerEpoch(ctx) - if err != nil { - return nil, errors.Wrap(err, "failed to obtain slots per epoch") + spec := specResponse.Data + + tmp, exists := spec["SLOTS_PER_EPOCH"] + if !exists { + return nil, errors.New("SLOTS_PER_EPOCH not found in spec") + } + slotsPerEpoch, ok := tmp.(uint64) + if !ok { + return nil, errors.New("SLOTS_PER_EPOCH of unexpected type") + } + + tmp, exists = spec["TARGET_AGGREGATORS_PER_COMMITTEE"] + if !exists { + return nil, errors.New("TARGET_AGGREGATORS_PER_COMMITTEE not found in spec") + } + targetAggregatorsPerCommittee, ok := tmp.(uint64) + if !ok { + return nil, errors.New("TARGET_AGGREGATORS_PER_COMMITTEE of unexpected type") } s := &Service{ diff --git a/services/attester/standard/parameters.go b/services/attester/standard/parameters.go index 5381430c..6c3ddc18 100644 --- a/services/attester/standard/parameters.go +++ b/services/attester/standard/parameters.go @@ -29,7 +29,7 @@ type parameters struct { processConcurrency int64 monitor metrics.AttestationMonitor chainTimeService chaintime.Service - slotsPerEpochProvider eth2client.SlotsPerEpochProvider + specProvider eth2client.SpecProvider attestationDataProvider eth2client.AttestationDataProvider attestationsSubmitter submitter.AttestationsSubmitter validatingAccountsProvider accountmanager.ValidatingAccountsProvider @@ -68,10 +68,10 @@ func WithChainTimeService(service chaintime.Service) Parameter { }) } -// WithSlotsPerEpochProvider sets the slots per epoch provider. -func WithSlotsPerEpochProvider(provider eth2client.SlotsPerEpochProvider) Parameter { +// WithSpecProvider sets the specification provider. +func WithSpecProvider(provider eth2client.SpecProvider) Parameter { return parameterFunc(func(p *parameters) { - p.slotsPerEpochProvider = provider + p.specProvider = provider }) } @@ -127,8 +127,8 @@ func parseAndCheckParameters(params ...Parameter) (*parameters, error) { if parameters.chainTimeService == nil { return nil, errors.New("no chain time service specified") } - if parameters.slotsPerEpochProvider == nil { - return nil, errors.New("no slots per epoch provider specified") + if parameters.specProvider == nil { + return nil, errors.New("no spec provider specified") } if parameters.attestationDataProvider == nil { return nil, errors.New("no attestation data provider specified") diff --git a/services/attester/standard/service.go b/services/attester/standard/service.go index 71742fdb..925142aa 100644 --- a/services/attester/standard/service.go +++ b/services/attester/standard/service.go @@ -68,9 +68,19 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - slotsPerEpoch, err := parameters.slotsPerEpochProvider.SlotsPerEpoch(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { - return nil, errors.Wrap(err, "failed to obtain slots per epoch") + return nil, errors.Wrap(err, "failed to obtain spec") + } + spec := specResponse.Data + + tmp, exists := spec["SLOTS_PER_EPOCH"] + if !exists { + return nil, errors.New("SLOTS_PER_EPOCH not found in spec") + } + slotsPerEpoch, ok := tmp.(uint64) + if !ok { + return nil, errors.New("SLOTS_PER_EPOCH of unexpected type") } s := &Service{ diff --git a/services/beaconblockproposer/standard/prepare_test.go b/services/beaconblockproposer/standard/prepare_test.go index 14c3eee9..29a6f1ed 100644 --- a/services/beaconblockproposer/standard/prepare_test.go +++ b/services/beaconblockproposer/standard/prepare_test.go @@ -39,23 +39,18 @@ func TestPrepare(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - - validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() - signer := mocksigner.New() - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() + signer := mocksigner.New() + consensusClient, err := mockconsensusclient.New(ctx) require.NoError(t, err) graffitiProvider, err := staticgraffitiprovider.New(ctx) diff --git a/services/beaconblockproposer/standard/propose.go b/services/beaconblockproposer/standard/propose.go index 2b8c6694..7a4eaeff 100644 --- a/services/beaconblockproposer/standard/propose.go +++ b/services/beaconblockproposer/standard/propose.go @@ -460,27 +460,6 @@ func (s *Service) signCompositeProposal(ctx context.Context, return nil, errors.Wrap(err, "failed to sign beacon proposal") } - blobSidecars, err := proposal.BlobSidecars() - if err != nil { - return nil, errors.Wrap(err, "failed to obtain blob sidecars of proposal") - } - blobSidecarSigs := make([]phase0.BLSSignature, len(blobSidecars)) - for i := range blobSidecars { - root, err := blobSidecars[i].HashTreeRoot() - if err != nil { - return nil, errors.Wrap(err, "failed to obtain hash tree root of blob sidecar") - } - - blobSidecarSigs[i], err = s.blobSidecarSigner.SignBlobSidecar(ctx, - duty.Account(), - duty.Slot(), - root, - ) - if err != nil { - return nil, errors.Wrap(err, "failed to sign blob sidecar") - } - } - signedProposal := &api.VersionedSignedProposal{ Version: proposal.Version, } @@ -492,13 +471,6 @@ func (s *Service) signCompositeProposal(ctx context.Context, Message: proposal.Deneb.Block, Signature: sig, }, - SignedBlobSidecars: make([]*deneb.SignedBlobSidecar, len(blobSidecars)), - } - for i := range blobSidecars { - signedProposal.Deneb.SignedBlobSidecars[i] = &deneb.SignedBlobSidecar{ - Message: blobSidecars[i], - Signature: blobSidecarSigs[i], - } } default: return nil, errors.New("unhandled composite proposal version") @@ -682,36 +654,11 @@ func (s *Service) signBlindedProposal(ctx context.Context, Signature: sig, } case spec.DataVersionDeneb: - signedProposal.Deneb = &apiv1deneb.SignedBlindedBlockContents{ - SignedBlindedBlock: &apiv1deneb.SignedBlindedBeaconBlock{ - Message: proposal.Deneb.BlindedBlock, - Signature: sig, - }, - } - - blobSidecars := proposal.Deneb.BlindedBlobSidecars - signedBlobSidecars := make([]*apiv1deneb.SignedBlindedBlobSidecar, len(blobSidecars)) - for i := range blobSidecars { - signedBlobSidecars[i] = &apiv1deneb.SignedBlindedBlobSidecar{ - Message: blobSidecars[i], - } - } - for i := range blobSidecars { - root, err := blobSidecars[i].HashTreeRoot() - if err != nil { - return nil, errors.Wrap(err, "failed to obtain hash tree root of blob sidecar") - } - - signedBlobSidecars[i].Signature, err = s.blobSidecarSigner.SignBlobSidecar(ctx, - duty.Account(), - duty.Slot(), - root, - ) - if err != nil { - return nil, errors.Wrap(err, "failed to sign blob sidecar") - } - } - signedProposal.Deneb.SignedBlindedBlobSidecars = signedBlobSidecars + return nil, errors.New("unsupported proposal version deneb") + // signedProposal.Deneb = &apiv1deneb.SignedBlindedBeaconBlock{ + // Message: proposal.Deneb, + // Signature: sig, + // } default: return nil, fmt.Errorf("unknown proposal version %v", signedProposal.Version) } diff --git a/services/beaconblockproposer/standard/propose_test.go b/services/beaconblockproposer/standard/propose_test.go index 17ae552b..a74a2a84 100644 --- a/services/beaconblockproposer/standard/propose_test.go +++ b/services/beaconblockproposer/standard/propose_test.go @@ -53,23 +53,18 @@ func TestPropose(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - - validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() - signer := mocksigner.New() - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() + signer := mocksigner.New() + consensusClient, err := mockconsensusclient.New(ctx) require.NoError(t, err) graffitiProvider, err := staticgraffitiprovider.New(ctx) diff --git a/services/beaconblockproposer/standard/service_test.go b/services/beaconblockproposer/standard/service_test.go index e50ace02..9141948e 100644 --- a/services/beaconblockproposer/standard/service_test.go +++ b/services/beaconblockproposer/standard/service_test.go @@ -38,23 +38,18 @@ func TestService(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - - validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() - signer := mocksigner.New() - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + validatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() + signer := mocksigner.New() + consensusClient, err := mockconsensusclient.New(ctx) require.NoError(t, err) graffitiProvider, err := staticgraffitiprovider.New(ctx) diff --git a/services/beaconcommitteesubscriber/standard/service_test.go b/services/beaconcommitteesubscriber/standard/service_test.go index 48362677..2104a049 100644 --- a/services/beaconcommitteesubscriber/standard/service_test.go +++ b/services/beaconcommitteesubscriber/standard/service_test.go @@ -30,11 +30,13 @@ import ( func TestService(t *testing.T) { ctx := context.Background() + genesisTime := time.Now() + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(mock.NewGenesisTimeProvider(time.Now())), - standardchaintime.WithSlotDurationProvider(mock.NewSlotDurationProvider(12*time.Second)), - standardchaintime.WithSlotsPerEpochProvider(mock.NewSlotsPerEpochProvider(32)), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/services/blockrelay/standard/proposerconfig_test.go b/services/blockrelay/standard/proposerconfig_test.go index d451bd9d..7aeb5355 100644 --- a/services/blockrelay/standard/proposerconfig_test.go +++ b/services/blockrelay/standard/proposerconfig_test.go @@ -51,11 +51,14 @@ func TestProposerConfig(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() + chainTime, err := standardchaintime.New(ctx, + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), + ) + require.NoError(t, err) mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() mockAccountsProvider := mockaccountmanager.NewAccountsProvider() @@ -74,14 +77,6 @@ func TestProposerConfig(t *testing.T) { require.NoError(t, err) mockValidatingAccountsProvider.AddAccount(1, testAccount) - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), - ) - require.NoError(t, err) - majordomoSvc, err := standardmajordomo.New(ctx) require.NoError(t, err) fileConfidant, err := fileconfidant.New(ctx) diff --git a/services/blockrelay/standard/service_test.go b/services/blockrelay/standard/service_test.go index 4eb93f0d..49b9e182 100644 --- a/services/blockrelay/standard/service_test.go +++ b/services/blockrelay/standard/service_test.go @@ -39,22 +39,18 @@ func TestService(t *testing.T) { zerolog.SetGlobalLevel(zerolog.Disabled) genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - - mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() - mockAccountsProvider := mockaccountmanager.NewAccountsProvider() - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() + mockAccountsProvider := mockaccountmanager.NewAccountsProvider() + prometheusMetrics, err := prometheusmetrics.New(ctx, prometheusmetrics.WithAddress(":12345"), prometheusmetrics.WithChainTime(chainTime), diff --git a/services/chaintime/standard/parameters.go b/services/chaintime/standard/parameters.go index 0b5ebccc..f6897a91 100644 --- a/services/chaintime/standard/parameters.go +++ b/services/chaintime/standard/parameters.go @@ -20,10 +20,9 @@ import ( ) type parameters struct { - logLevel zerolog.Level - genesisTimeProvider eth2client.GenesisTimeProvider - slotDurationProvider eth2client.SlotDurationProvider - slotsPerEpochProvider eth2client.SlotsPerEpochProvider + logLevel zerolog.Level + genesisProvider eth2client.GenesisProvider + specProvider eth2client.SpecProvider } // Parameter is the interface for service parameters. @@ -44,24 +43,17 @@ func WithLogLevel(logLevel zerolog.Level) Parameter { }) } -// WithGenesisTimeProvider sets the genesis time provider. -func WithGenesisTimeProvider(provider eth2client.GenesisTimeProvider) Parameter { +// WithGenesisProvider sets the genesis provider. +func WithGenesisProvider(provider eth2client.GenesisProvider) Parameter { return parameterFunc(func(p *parameters) { - p.genesisTimeProvider = provider + p.genesisProvider = provider }) } -// WithSlotDurationProvider sets the seconds per slot provider. -func WithSlotDurationProvider(provider eth2client.SlotDurationProvider) Parameter { +// WithSpecProvider sets the spec provider. +func WithSpecProvider(provider eth2client.SpecProvider) Parameter { return parameterFunc(func(p *parameters) { - p.slotDurationProvider = provider - }) -} - -// WithSlotsPerEpochProvider sets the slots per epoch provider. -func WithSlotsPerEpochProvider(provider eth2client.SlotsPerEpochProvider) Parameter { - return parameterFunc(func(p *parameters) { - p.slotsPerEpochProvider = provider + p.specProvider = provider }) } @@ -76,14 +68,11 @@ func parseAndCheckParameters(params ...Parameter) (*parameters, error) { } } - if parameters.genesisTimeProvider == nil { - return nil, errors.New("no genesis time provider specified") - } - if parameters.slotDurationProvider == nil { - return nil, errors.New("no slot duration provider specified") + if parameters.genesisProvider == nil { + return nil, errors.New("no genesis provider specified") } - if parameters.slotsPerEpochProvider == nil { - return nil, errors.New("no slots per epoch provider specified") + if parameters.specProvider == nil { + return nil, errors.New("no spec provider specified") } return ¶meters, nil diff --git a/services/chaintime/standard/service.go b/services/chaintime/standard/service.go index bad27cf2..69227f19 100644 --- a/services/chaintime/standard/service.go +++ b/services/chaintime/standard/service.go @@ -1,4 +1,4 @@ -// Copyright © 2020 Attestant Limited. +// Copyright © 2020 - 2023 Attestant Limited. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -17,6 +17,7 @@ import ( "context" "time" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/pkg/errors" "github.com/rs/zerolog" @@ -46,21 +47,36 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - genesisTime, err := parameters.genesisTimeProvider.GenesisTime(ctx) + genesisResponse, err := parameters.genesisProvider.Genesis(ctx, &api.GenesisOpts{}) if err != nil { - return nil, errors.Wrap(nil, "failed to obtain genesis time") + return nil, errors.Wrap(err, "failed to obtain genesis") } + genesisTime := genesisResponse.Data.GenesisTime log.Trace().Time("genesis_time", genesisTime).Msg("Obtained genesis time") - slotDuration, err := parameters.slotDurationProvider.SlotDuration(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { - return nil, errors.Wrap(nil, "failed to obtain slot duration") + return nil, errors.Wrap(err, "failed to obtain spec") + } + spec := specResponse.Data + + tmp, exists := spec["SECONDS_PER_SLOT"] + if !exists { + return nil, errors.New("SECONDS_PER_SLOT not found in spec") + } + slotDuration, ok := tmp.(time.Duration) + if !ok { + return nil, errors.New("SECONDS_PER_SLOT of unexpected type") } log.Trace().Dur("slot_duration", slotDuration).Msg("Obtained slot duration") - slotsPerEpoch, err := parameters.slotsPerEpochProvider.SlotsPerEpoch(ctx) - if err != nil { - return nil, errors.Wrap(nil, "failed to obtain slots per epoch") + tmp, exists = spec["SLOTS_PER_EPOCH"] + if !exists { + return nil, errors.New("SLOTS_PER_EPOCH not found in spec") + } + slotsPerEpoch, ok := tmp.(uint64) + if !ok { + return nil, errors.New("SLOTS_PER_EPOCH of unexpected type") } log.Trace().Uint64("slots_per_epoch", slotsPerEpoch).Msg("Obtained slots per epoch") diff --git a/services/chaintime/standard/service_test.go b/services/chaintime/standard/service_test.go index 2330eabb..d03d4c6d 100644 --- a/services/chaintime/standard/service_test.go +++ b/services/chaintime/standard/service_test.go @@ -29,50 +29,36 @@ import ( func TestService(t *testing.T) { genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - mockGenesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - mockSlotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - mockSlotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + mockGenesisProvider := mock.NewGenesisProvider(genesisTime) + mockSpecProvider := mock.NewSpecProvider() + tests := []struct { name string params []standard.Parameter err string }{ { - name: "GenesisTimeProviderMissing", - params: []standard.Parameter{ - standard.WithLogLevel(zerolog.Disabled), - standard.WithSlotDurationProvider(mockSlotDurationProvider), - standard.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), - }, - err: "problem with parameters: no genesis time provider specified", - }, - { - name: "SlotDurationProviderMissing", + name: "GenesisProviderMissing", params: []standard.Parameter{ standard.WithLogLevel(zerolog.Disabled), - standard.WithGenesisTimeProvider(mockGenesisTimeProvider), - standard.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), + standard.WithSpecProvider(mockSpecProvider), }, - err: "problem with parameters: no slot duration provider specified", + err: "problem with parameters: no genesis provider specified", }, { - name: "SlotsPerEpochProviderMissing", + name: "SpecProviderMissing", params: []standard.Parameter{ standard.WithLogLevel(zerolog.Disabled), - standard.WithGenesisTimeProvider(mockGenesisTimeProvider), - standard.WithSlotDurationProvider(mockSlotDurationProvider), + standard.WithGenesisProvider(mockGenesisProvider), }, - err: "problem with parameters: no slots per epoch provider specified", + err: "problem with parameters: no spec provider specified", }, { name: "Good", params: []standard.Parameter{ standard.WithLogLevel(zerolog.Disabled), - standard.WithGenesisTimeProvider(mockGenesisTimeProvider), - standard.WithSlotDurationProvider(mockSlotDurationProvider), - standard.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), + standard.WithGenesisProvider(mockGenesisProvider), + standard.WithSpecProvider(mockSpecProvider), }, }, } @@ -89,24 +75,20 @@ func TestService(t *testing.T) { } } -func createMockService(slotDuration time.Duration, slotsPerEpoch uint64, genesisTime time.Time) (chaintime.Service, error) { - mockGenesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - mockSlotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - mockSlotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) +func createMockService(genesisTime time.Time) (chaintime.Service, error) { + mockGenesisProvider := mock.NewGenesisProvider(genesisTime) + mockSpecProvider := mock.NewSpecProvider() s, err := standard.New(context.Background(), - standard.WithGenesisTimeProvider(mockGenesisTimeProvider), - standard.WithSlotDurationProvider(mockSlotDurationProvider), - standard.WithSlotsPerEpochProvider(mockSlotsPerEpochProvider), + standard.WithGenesisProvider(mockGenesisProvider), + standard.WithSpecProvider(mockSpecProvider), ) return s, err } func TestGenesisTime(t *testing.T) { - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now() - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, genesisTime, s.GenesisTime()) @@ -114,10 +96,9 @@ func TestGenesisTime(t *testing.T) { func TestStartOfSlot(t *testing.T) { slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now() - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, genesisTime, s.StartOfSlot(0)) @@ -129,7 +110,7 @@ func TestStartOfEpoch(t *testing.T) { slotsPerEpoch := uint64(32) genesisTime := time.Now() - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, genesisTime, s.StartOfEpoch(0)) @@ -138,21 +119,18 @@ func TestStartOfEpoch(t *testing.T) { func TestCurrentSlot(t *testing.T) { slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now().Add(-5 * slotDuration) - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, phase0.Slot(5), s.CurrentSlot()) } func TestCurrentSlotPreGenesis(t *testing.T) { - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now().Add(3 * time.Hour) - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, phase0.Slot(0), s.CurrentSlot()) @@ -163,18 +141,16 @@ func TestCurrentEpoch(t *testing.T) { slotsPerEpoch := uint64(32) genesisTime := time.Now().Add(time.Duration(int64(-2)*int64(slotsPerEpoch)) * slotDuration) - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, phase0.Epoch(2), s.CurrentEpoch()) } func TestCurrentEpochPreGenesis(t *testing.T) { - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now().Add(3 * time.Hour) - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) require.Equal(t, phase0.Epoch(0), s.CurrentEpoch()) @@ -203,11 +179,9 @@ func TestSlotToEpoch(t *testing.T) { }, } - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now() - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) for _, test := range tests { @@ -241,11 +215,9 @@ func TestFirstSlotOfEpoch(t *testing.T) { }, } - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) genesisTime := time.Now() - s, err := createMockService(slotDuration, slotsPerEpoch, genesisTime) + s, err := createMockService(genesisTime) require.NoError(t, err) for _, test := range tests { diff --git a/services/controller/standard/parameters.go b/services/controller/standard/parameters.go index d32b3d1f..c36192c2 100644 --- a/services/controller/standard/parameters.go +++ b/services/controller/standard/parameters.go @@ -18,6 +18,7 @@ import ( "time" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/vouch/services/accountmanager" "github.com/attestantio/vouch/services/attestationaggregator" "github.com/attestantio/vouch/services/attester" @@ -333,7 +334,7 @@ func parseAndCheckParameters(params ...Parameter) (*parameters, error) { if parameters.blockToSlotSetter == nil { return nil, errors.New("no block to slot setter specified") } - specResponse, err := parameters.specProvider.Spec(context.Background()) + specResponse, err := parameters.specProvider.Spec(context.Background(), &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/services/controller/standard/service.go b/services/controller/standard/service.go index ad799863..b36c446b 100644 --- a/services/controller/standard/service.go +++ b/services/controller/standard/service.go @@ -1,4 +1,4 @@ -// Copyright © 2020 - 2022 Attestant Limited. +// Copyright © 2020 - 2023 Attestant Limited. // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -20,6 +20,7 @@ import ( "time" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/accountmanager" "github.com/attestantio/vouch/services/attestationaggregator" @@ -468,7 +469,7 @@ func fetchAltairForkEpoch(ctx context.Context, error, ) { // Fetch the fork version. - specResponse, err := specProvider.Spec(ctx) + specResponse, err := specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return 0, errors.Wrap(err, "failed to obtain spec") } @@ -494,7 +495,7 @@ func fetchBellatrixForkEpoch(ctx context.Context, error, ) { // Fetch the fork version. - specResponse, err := specProvider.Spec(ctx) + specResponse, err := specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return 0, errors.Wrap(err, "failed to obtain spec") } @@ -520,7 +521,7 @@ func fetchCapellaForkEpoch(ctx context.Context, error, ) { // Fetch the fork version. - specResponse, err := specProvider.Spec(ctx) + specResponse, err := specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return 0, errors.Wrap(err, "failed to obtain spec") } @@ -597,7 +598,7 @@ func obtainSpecValues(ctx context.Context, uint64, error, ) { - specResponse, err := specProvider.Spec(ctx) + specResponse, err := specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return 0, 0, 0, errors.Wrap(err, "failed to obtain spec") } diff --git a/services/controller/standard/service_test.go b/services/controller/standard/service_test.go index 31cd5279..f7909881 100644 --- a/services/controller/standard/service_test.go +++ b/services/controller/standard/service_test.go @@ -46,12 +46,14 @@ func TestService(t *testing.T) { zerolog.SetGlobalLevel(zerolog.Disabled) genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() + chainTime, err := standardchaintime.New(ctx, + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), + ) + require.NoError(t, err) mockBlockHeadersProvider := mock.NewBeaconBlockHeadersProvider() mockSignedBeaconBlockProvider := mock.NewSignedBeaconBlockProvider() @@ -72,13 +74,6 @@ func TestService(t *testing.T) { mockBeaconCommitteeSubscriber := mockbeaconcommitteesubscriber.New() mockBlockToSlotSetter := mockcache.New(map[phase0.Root]phase0.Slot{}).(cache.BlockRootToSlotSetter) - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), - ) - require.NoError(t, err) - tests := []struct { name string params []standard.Parameter diff --git a/services/metrics/prometheus/service_test.go b/services/metrics/prometheus/service_test.go index bcac5873..1fef4d96 100644 --- a/services/metrics/prometheus/service_test.go +++ b/services/metrics/prometheus/service_test.go @@ -29,11 +29,13 @@ import ( func TestService(t *testing.T) { ctx := context.Background() + genesisTime := time.Now() + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(mock.NewGenesisTimeProvider(time.Now())), - standardchaintime.WithSlotDurationProvider(mock.NewSlotDurationProvider(12*time.Second)), - standardchaintime.WithSlotsPerEpochProvider(mock.NewSlotsPerEpochProvider(32)), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/services/proposalpreparer/standard/service_test.go b/services/proposalpreparer/standard/service_test.go index 139130b1..21e25852 100644 --- a/services/proposalpreparer/standard/service_test.go +++ b/services/proposalpreparer/standard/service_test.go @@ -35,23 +35,19 @@ func TestService(t *testing.T) { zerolog.SetGlobalLevel(zerolog.Disabled) genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() + chainTime, err := standardchaintime.New(ctx, + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), + ) + require.NoError(t, err) mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() mockProposalPreparationsSubmitter := mock.NewProposalPreparationsSubmitter() mockBlockRelay := mockblockrelay.New() - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), - ) - require.NoError(t, err) - prometheusMetrics, err := prometheusmetrics.New(ctx, prometheusmetrics.WithAddress(":12345"), prometheusmetrics.WithChainTime(chainTime), diff --git a/services/proposalpreparer/standard/updatepreparations_test.go b/services/proposalpreparer/standard/updatepreparations_test.go index 12ee53be..3bb35008 100644 --- a/services/proposalpreparer/standard/updatepreparations_test.go +++ b/services/proposalpreparer/standard/updatepreparations_test.go @@ -34,16 +34,12 @@ func TestUpdatePreparations(t *testing.T) { zerolog.SetGlobalLevel(zerolog.Disabled) genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/services/signer/standard/service.go b/services/signer/standard/service.go index 00b89f14..fa8d4d10 100644 --- a/services/signer/standard/service.go +++ b/services/signer/standard/service.go @@ -18,6 +18,7 @@ import ( "fmt" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/metrics" "github.com/pkg/errors" @@ -59,7 +60,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/services/submitter/multinode/helpers.go b/services/submitter/multinode/helpers.go index 2c2366bb..acda7d36 100644 --- a/services/submitter/multinode/helpers.go +++ b/services/submitter/multinode/helpers.go @@ -18,6 +18,7 @@ import ( "strings" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" ) // serviceInfo returns the service name and provider information. @@ -28,7 +29,7 @@ func (*Service) serviceInfo(ctx context.Context, submitter interface{}) (string, provider = service.Address() } if service, isService := submitter.(eth2client.NodeVersionProvider); isService { - nodeVersionResponse, err := service.NodeVersion(ctx) + nodeVersionResponse, err := service.NodeVersion(ctx, &api.NodeVersionOpts{}) if err == nil { nodeVersion := strings.ToLower(nodeVersionResponse.Data) switch { diff --git a/services/synccommitteeaggregator/standard/service.go b/services/synccommitteeaggregator/standard/service.go index 3d445d9f..2aa45190 100644 --- a/services/synccommitteeaggregator/standard/service.go +++ b/services/synccommitteeaggregator/standard/service.go @@ -65,7 +65,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/services/synccommitteemessenger/standard/service.go b/services/synccommitteemessenger/standard/service.go index 60e16a7b..ef35ea33 100644 --- a/services/synccommitteemessenger/standard/service.go +++ b/services/synccommitteemessenger/standard/service.go @@ -72,7 +72,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/services/synccommitteemessenger/standard/service_test.go b/services/synccommitteemessenger/standard/service_test.go index 488e29b1..ac094c88 100644 --- a/services/synccommitteemessenger/standard/service_test.go +++ b/services/synccommitteemessenger/standard/service_test.go @@ -36,12 +36,14 @@ func TestService(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() + chainTime, err := standardchaintime.New(ctx, + standardchaintime.WithLogLevel(zerolog.Disabled), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), + ) + require.NoError(t, err) mockSyncCommitteeAggregator := mocksynccommitteeaggregator.New() mockSigner := mocksigner.New() @@ -51,13 +53,6 @@ func TestService(t *testing.T) { require.NoError(t, err) mockValidatingAccountsProvider := mockaccountmanager.NewValidatingAccountsProvider() - chainTime, err := standardchaintime.New(ctx, - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), - ) - - require.NoError(t, err) tests := []struct { name string params []standard.Parameter diff --git a/strategies/attestationdata/best/attestationdata_test.go b/strategies/attestationdata/best/attestationdata_test.go index abe6788e..3559a980 100644 --- a/strategies/attestationdata/best/attestationdata_test.go +++ b/strategies/attestationdata/best/attestationdata_test.go @@ -35,17 +35,12 @@ func TestAttestationData(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/attestationdata/best/service_test.go b/strategies/attestationdata/best/service_test.go index 8cc8effb..d7e7ddb0 100644 --- a/strategies/attestationdata/best/service_test.go +++ b/strategies/attestationdata/best/service_test.go @@ -37,17 +37,12 @@ func TestService(t *testing.T) { } genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) @@ -165,17 +160,12 @@ func TestInterfaces(t *testing.T) { } genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - + genesisProvider := mock.NewGenesisProvider(genesisTime) + specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/beaconblockproposal/best/beaconblockproposal_test.go b/strategies/beaconblockproposal/best/beaconblockproposal_test.go index 6005edc0..00450f72 100644 --- a/strategies/beaconblockproposal/best/beaconblockproposal_test.go +++ b/strategies/beaconblockproposal/best/beaconblockproposal_test.go @@ -35,20 +35,16 @@ func TestProposal(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - signedBeaconBlockProvider := mock.NewSignedBeaconBlockProvider() + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + + signedBeaconBlockProvider := mock.NewSignedBeaconBlockProvider() cacheSvc := mockcache.New(map[phase0.Root]phase0.Slot{}) blockToSlotCache := cacheSvc.(cache.BlockRootToSlotProvider) diff --git a/strategies/beaconblockproposal/best/events_internal_test.go b/strategies/beaconblockproposal/best/events_internal_test.go index ef52f731..cf960bb0 100644 --- a/strategies/beaconblockproposal/best/events_internal_test.go +++ b/strategies/beaconblockproposal/best/events_internal_test.go @@ -136,18 +136,12 @@ func TestUpdateBlockVotes(t *testing.T) { } genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/beaconblockproposal/best/score_internal_test.go b/strategies/beaconblockproposal/best/score_internal_test.go index dafc936b..138c474f 100644 --- a/strategies/beaconblockproposal/best/score_internal_test.go +++ b/strategies/beaconblockproposal/best/score_internal_test.go @@ -858,18 +858,12 @@ func TestScore(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/beaconblockproposal/best/service.go b/strategies/beaconblockproposal/best/service.go index e78f1f4d..99351d89 100644 --- a/strategies/beaconblockproposal/best/service.go +++ b/strategies/beaconblockproposal/best/service.go @@ -19,6 +19,7 @@ import ( "time" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/cache" "github.com/attestantio/vouch/services/chaintime" @@ -77,7 +78,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/strategies/beaconblockproposal/best/service_test.go b/strategies/beaconblockproposal/best/service_test.go index 14e1e529..11a03b52 100644 --- a/strategies/beaconblockproposal/best/service_test.go +++ b/strategies/beaconblockproposal/best/service_test.go @@ -34,18 +34,12 @@ func TestService(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/blindedbeaconblockproposal/best/blindedbeaconblockproposal_test.go b/strategies/blindedbeaconblockproposal/best/blindedbeaconblockproposal_test.go index 0b97d20f..886bc918 100644 --- a/strategies/blindedbeaconblockproposal/best/blindedbeaconblockproposal_test.go +++ b/strategies/blindedbeaconblockproposal/best/blindedbeaconblockproposal_test.go @@ -34,21 +34,17 @@ import ( func TestBlindedProposal(t *testing.T) { ctx := context.Background() - genesisTime := time.Unix(1669161600, 0) - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) - signedBeaconBlockProvider := mock.NewSignedBeaconBlockProvider() + genesisTime := time.Now() + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) + + signedBeaconBlockProvider := mock.NewSignedBeaconBlockProvider() cacheSvc := mockcache.New(map[phase0.Root]phase0.Slot{}) blockToSlotCache := cacheSvc.(cache.BlockRootToSlotProvider) diff --git a/strategies/blindedbeaconblockproposal/best/events_internal_test.go b/strategies/blindedbeaconblockproposal/best/events_internal_test.go index a26b9da4..cf9ad8de 100644 --- a/strategies/blindedbeaconblockproposal/best/events_internal_test.go +++ b/strategies/blindedbeaconblockproposal/best/events_internal_test.go @@ -136,18 +136,12 @@ func TestUpdateBlockVotes(t *testing.T) { } genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/blindedbeaconblockproposal/best/score.go b/strategies/blindedbeaconblockproposal/best/score.go index e7e9fde6..196b9e8e 100644 --- a/strategies/blindedbeaconblockproposal/best/score.go +++ b/strategies/blindedbeaconblockproposal/best/score.go @@ -253,7 +253,7 @@ func (s *Service) scoreCapellaBlindedProposal(ctx context.Context, func (s *Service) scoreDenebBlindedProposal(ctx context.Context, name string, parentSlot phase0.Slot, - proposal *apiv1deneb.BlindedBlockContents, + proposal *apiv1deneb.BlindedBeaconBlock, ) float64 { attestationScore := float64(0) immediateAttestationScore := float64(0) @@ -261,7 +261,7 @@ func (s *Service) scoreDenebBlindedProposal(ctx context.Context, // We need to avoid duplicates in attestations. // Map is attestation slot -> committee index -> validator committee index -> aggregate. attested := make(map[phase0.Slot]map[phase0.CommitteeIndex]bitfield.Bitlist) - for _, attestation := range proposal.BlindedBlock.Body.Attestations { + for _, attestation := range proposal.Body.Attestations { data := attestation.Data if _, exists := attested[data.Slot]; !exists { attested[data.Slot] = make(map[phase0.CommitteeIndex]bitfield.Bitlist) @@ -272,7 +272,7 @@ func (s *Service) scoreDenebBlindedProposal(ctx context.Context, } } - priorVotes, err := s.priorVotesForAttestation(ctx, attestation, proposal.BlindedBlock.ParentRoot) + priorVotes, err := s.priorVotesForAttestation(ctx, attestation, proposal.ParentRoot) if err != nil { log.Debug().Err(err).Msg("Failed to obtain prior votes for attestation; assuming no votes") } @@ -297,9 +297,9 @@ func (s *Service) scoreDenebBlindedProposal(ctx context.Context, // We can calculate if the head vote is correct, but not target so for the // purposes of the calculation we assume that it is. - headCorrect := denebHeadCorrect(proposal.BlindedBlock, attestation) + headCorrect := denebHeadCorrect(proposal, attestation) targetCorrect := s.bellatrixTargetCorrect(ctx, attestation) - inclusionDistance := proposal.BlindedBlock.Slot - attestation.Data.Slot + inclusionDistance := proposal.Slot - attestation.Data.Slot score := 0.0 if targetCorrect { @@ -320,13 +320,13 @@ func (s *Service) scoreDenebBlindedProposal(ctx context.Context, } } - attesterSlashingScore, proposerSlashingScore := scoreSlashings(proposal.BlindedBlock.Body.AttesterSlashings, proposal.BlindedBlock.Body.ProposerSlashings) + attesterSlashingScore, proposerSlashingScore := scoreSlashings(proposal.Body.AttesterSlashings, proposal.Body.ProposerSlashings) // Add sync committee score. - syncCommitteeScore := float64(proposal.BlindedBlock.Body.SyncAggregate.SyncCommitteeBits.Count()) * float64(s.syncRewardWeight) / float64(s.weightDenominator) + syncCommitteeScore := float64(proposal.Body.SyncAggregate.SyncCommitteeBits.Count()) * float64(s.syncRewardWeight) / float64(s.weightDenominator) log.Trace(). - Uint64("slot", uint64(proposal.BlindedBlock.Slot)). + Uint64("slot", uint64(proposal.Slot)). Uint64("parent_slot", uint64(parentSlot)). Str("provider", name). Float64("immediate_attestations", immediateAttestationScore). diff --git a/strategies/blindedbeaconblockproposal/best/score_internal_test.go b/strategies/blindedbeaconblockproposal/best/score_internal_test.go index 6d4c5e9a..18f20238 100644 --- a/strategies/blindedbeaconblockproposal/best/score_internal_test.go +++ b/strategies/blindedbeaconblockproposal/best/score_internal_test.go @@ -485,18 +485,12 @@ func TestScore(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/blindedbeaconblockproposal/best/service.go b/strategies/blindedbeaconblockproposal/best/service.go index 6f5fdc23..56377d33 100644 --- a/strategies/blindedbeaconblockproposal/best/service.go +++ b/strategies/blindedbeaconblockproposal/best/service.go @@ -19,6 +19,7 @@ import ( "time" eth2client "github.com/attestantio/go-eth2-client" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/cache" "github.com/attestantio/vouch/services/chaintime" @@ -76,7 +77,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { log = log.Level(parameters.logLevel) } - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } diff --git a/strategies/blindedbeaconblockproposal/best/service_test.go b/strategies/blindedbeaconblockproposal/best/service_test.go index a19bbf38..55e88415 100644 --- a/strategies/blindedbeaconblockproposal/best/service_test.go +++ b/strategies/blindedbeaconblockproposal/best/service_test.go @@ -34,18 +34,12 @@ func TestService(t *testing.T) { ctx := context.Background() genesisTime := time.Now() - slotDuration := 12 * time.Second - slotsPerEpoch := uint64(32) - genesisTimeProvider := mock.NewGenesisTimeProvider(genesisTime) - slotDurationProvider := mock.NewSlotDurationProvider(slotDuration) - slotsPerEpochProvider := mock.NewSlotsPerEpochProvider(slotsPerEpoch) + genesisProvider := mock.NewGenesisProvider(genesisTime) specProvider := mock.NewSpecProvider() - chainTime, err := standardchaintime.New(ctx, standardchaintime.WithLogLevel(zerolog.Disabled), - standardchaintime.WithGenesisTimeProvider(genesisTimeProvider), - standardchaintime.WithSlotDurationProvider(slotDurationProvider), - standardchaintime.WithSlotsPerEpochProvider(slotsPerEpochProvider), + standardchaintime.WithGenesisProvider(genesisProvider), + standardchaintime.WithSpecProvider(specProvider), ) require.NoError(t, err) diff --git a/strategies/builderbid/best/service.go b/strategies/builderbid/best/service.go index 77b36285..5ae50af5 100644 --- a/strategies/builderbid/best/service.go +++ b/strategies/builderbid/best/service.go @@ -18,6 +18,7 @@ import ( "sync" "time" + "github.com/attestantio/go-eth2-client/api" "github.com/attestantio/go-eth2-client/spec/phase0" "github.com/attestantio/vouch/services/chaintime" "github.com/attestantio/vouch/services/metrics" @@ -57,7 +58,7 @@ func New(ctx context.Context, params ...Parameter) (*Service, error) { } // The application domain is static, so fetch it here once. - specResponse, err := parameters.specProvider.Spec(ctx) + specResponse, err := parameters.specProvider.Spec(ctx, &api.SpecOpts{}) if err != nil { return nil, errors.Wrap(err, "failed to obtain spec") } From 438ef77c804c8e12a949b1075e4eb8dd938d8abc Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Fri, 17 Nov 2023 17:25:07 +0000 Subject: [PATCH 2/2] Update parameters. --- main.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index f0d73fa6..cbc01c4c 100644 --- a/main.go +++ b/main.go @@ -681,7 +681,7 @@ func startSigningServices(ctx context.Context, standardattester.WithLogLevel(util.LogLevel("attester")), standardattester.WithProcessConcurrency(util.ProcessConcurrency("attester")), standardattester.WithChainTimeService(chainTime), - standardattester.WithSlotsPerEpochProvider(eth2Client.(eth2client.SlotsPerEpochProvider)), + standardattester.WithSpecProvider(eth2Client.(eth2client.SpecProvider)), standardattester.WithAttestationDataProvider(attestationDataProvider), standardattester.WithAttestationsSubmitter(submitterStrategy.(submitter.AttestationsSubmitter)), standardattester.WithMonitor(monitor.(metrics.AttestationMonitor)), @@ -695,14 +695,13 @@ func startSigningServices(ctx context.Context, log.Trace().Msg("Starting beacon attestation aggregator") attestationAggregator, err := standardattestationaggregator.New(ctx, standardattestationaggregator.WithLogLevel(util.LogLevel("attestationaggregator")), - standardattestationaggregator.WithTargetAggregatorsPerCommitteeProvider(eth2Client.(eth2client.TargetAggregatorsPerCommitteeProvider)), standardattestationaggregator.WithAggregateAttestationProvider(aggregateAttestationProvider), standardattestationaggregator.WithAggregateAttestationsSubmitter(submitterStrategy.(submitter.AggregateAttestationsSubmitter)), standardattestationaggregator.WithMonitor(monitor.(metrics.AttestationAggregationMonitor)), standardattestationaggregator.WithValidatingAccountsProvider(accountManager.(accountmanager.ValidatingAccountsProvider)), standardattestationaggregator.WithSlotSelectionSigner(signerSvc.(signer.SlotSelectionSigner)), standardattestationaggregator.WithAggregateAndProofSigner(signerSvc.(signer.AggregateAndProofSigner)), - standardattestationaggregator.WithSlotsPerEpochProvider(eth2Client.(eth2client.SlotsPerEpochProvider)), + standardattestationaggregator.WithSpecProvider(eth2Client.(eth2client.SpecProvider)), ) if err != nil { return nil, nil, nil, nil, errors.Wrap(err, "failed to start beacon attestation aggregator service")