Skip to content

Commit

Permalink
Merge pull request #160 from attestantio/update-client
Browse files Browse the repository at this point in the history
Update dependencies.
  • Loading branch information
mcdee authored Nov 19, 2023
2 parents a230ffe + 438ef77 commit 92a8034
Show file tree
Hide file tree
Showing 47 changed files with 339 additions and 542 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)),
Expand All @@ -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")
Expand Down Expand Up @@ -1020,7 +1019,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),
Expand Down Expand Up @@ -1540,7 +1539,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")
}
Expand Down
86 changes: 15 additions & 71 deletions mock/eth2client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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{}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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).
Expand Down Expand Up @@ -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{
{
Expand Down
13 changes: 5 additions & 8 deletions services/accountmanager/dirk/service_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
19 changes: 8 additions & 11 deletions services/accountmanager/dirk/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions services/accountmanager/wallet/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
})
}

Expand Down Expand Up @@ -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")
Expand Down
50 changes: 31 additions & 19 deletions services/accountmanager/wallet/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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()).
Expand All @@ -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)
}
Expand Down Expand Up @@ -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]
}
}
Expand Down
Loading

0 comments on commit 92a8034

Please sign in to comment.