Skip to content

Commit

Permalink
*: fix compatibility with latest go-eth2-client (#2650)
Browse files Browse the repository at this point in the history
Fix charon's compatibility with latest release of `go-eth2-client` which contains breaking changes, notably the ETH2 client interface methods. This PR also enables easy integration of deneb fork as the data structures for deneb are included in the new release. An example of the API change is as follows:

Earlier
```
validatorsProvider.Validators(ctx, "head", nil)
```
Now
```
validatorsProvider.Validators(ctx, &api.ValidatorsOpts{
  State: "head",
})
```

Also fix corresponding tests.

category: feature 
ticket: #2646
  • Loading branch information
xenowits authored Oct 30, 2023
1 parent 1e87eb9 commit 4632e21
Show file tree
Hide file tree
Showing 64 changed files with 4,106 additions and 1,543 deletions.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,12 @@ func newETH2Client(ctx context.Context, conf Config, life *lifecycle.Manager,
}

// Check BN chain/network.
schedule, err := eth2Cl.ForkSchedule(ctx)
eth2Resp, err := eth2Cl.ForkSchedule(ctx)
if err != nil {
return nil, errors.Wrap(err, "fetch fork schedule")
}
schedule := eth2Resp.Data

var ok bool
for _, fork := range schedule {
if bytes.Equal(fork.CurrentVersion[:], forkVersion) {
Expand Down
11 changes: 6 additions & 5 deletions app/eth2wrap/eth2wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"time"

eth2api "github.com/attestantio/go-eth2-client/api"
eth2http "github.com/attestantio/go-eth2-client/http"
"github.com/attestantio/go-eth2-client/spec/bellatrix"
eth2p0 "github.com/attestantio/go-eth2-client/spec/phase0"
Expand Down Expand Up @@ -329,12 +330,12 @@ func incError(endpoint string) {
// wrapError returns the error as a wrapped structured error.
func wrapError(ctx context.Context, err error, label string, fields ...z.Field) error {
// Decompose go-eth2-client http errors
if e2err := new(eth2http.Error); errors.As(err, e2err) {
if apiErr := new(eth2api.Error); errors.As(err, apiErr) {
err = errors.New("nok http response",
z.Int("status_code", e2err.StatusCode),
z.Str("endpoint", e2err.Endpoint),
z.Str("method", e2err.Method),
z.Str("data", string(e2err.Data)),
z.Int("status_code", apiErr.StatusCode),
z.Str("endpoint", apiErr.Endpoint),
z.Str("method", apiErr.Method),
z.Str("data", string(apiErr.Data)),
)
}

Expand Down
278 changes: 116 additions & 162 deletions app/eth2wrap/eth2wrap_gen.go

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions app/eth2wrap/eth2wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func TestSyncState(t *testing.T) {

resp, err := eth2Cl.NodeSyncing(context.Background())
require.NoError(t, err)
require.False(t, resp.IsSyncing)
require.False(t, resp.Data.IsSyncing)
}

func TestErrors(t *testing.T) {
Expand Down Expand Up @@ -203,18 +203,6 @@ func TestErrors(t *testing.T) {
require.ErrorContains(t, err, "beacon api slots_per_epoch: context canceled")
})

t.Run("go-eth2-client http error", func(t *testing.T) {
bmock, err := beaconmock.New()
require.NoError(t, err)
eth2Cl, err := eth2wrap.NewMultiHTTP(time.Second, bmock.Address())
require.NoError(t, err)

_, err = eth2Cl.AggregateAttestation(ctx, 0, eth2p0.Root{})
log.Error(ctx, "See this error log for fields", err)
require.Error(t, err)
require.ErrorContains(t, err, "beacon api aggregate_attestation: nok http response")
})

t.Run("zero net op error", func(t *testing.T) {
bmock, err := beaconmock.New()
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions app/eth2wrap/genwrap/genwrap.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions app/eth2wrap/success.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
package eth2wrap

import (
"github.com/attestantio/go-eth2-client/api"
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
)

// isSyncStateOk returns tue if the sync state is not syncing.
func isSyncStateOk(s *apiv1.SyncState) bool {
return !s.IsSyncing
// isSyncStateOk returns true if the sync state is not syncing.
func isSyncStateOk(resp *api.Response[*apiv1.SyncState]) bool {
return !resp.Data.IsSyncing
}

// isAggregateAttestationOk returns true if the aggregate attestation is not nil (which can happen if the subscription wasn't successful).
func isAggregateAttestationOk(att *phase0.Attestation) bool {
return att != nil
func isAggregateAttestationOk(resp *api.Response[*phase0.Attestation]) bool {
return resp.Data != nil
}
Loading

0 comments on commit 4632e21

Please sign in to comment.