Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: integrating go-eth2-client@v0.21.1 #2986

Merged
merged 40 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a3b8849
integrating go-eth2-client@v0.21.0 wip
pinebit Mar 22, 2024
ba4de18
removed unused code
pinebit Mar 22, 2024
a876a1c
corrected fetcher implementation
pinebit Mar 22, 2024
b91f271
fixed sigadd_test.go
pinebit Mar 22, 2024
ac9d461
fixed eth2wrap_test.go
pinebit Mar 22, 2024
d47e595
improved bcast_test.go
pinebit Mar 22, 2024
1a71ee2
fixed test and vmock
pinebit Mar 22, 2024
bd9fab3
dutydb to not serve builder duty
pinebit Mar 22, 2024
9bfc53c
removed leftovers
pinebit Mar 22, 2024
b69b6c7
unsinged data json serialization
pinebit Mar 25, 2024
a37e3bf
fixed ssz serialization
pinebit Mar 25, 2024
8c3cfaf
Deprecated DutyBuilderProposal usage
pinebit Mar 26, 2024
3f14735
Fixed linter issues
pinebit Mar 26, 2024
6b3958c
Fixed linter issues
pinebit Mar 26, 2024
ec098ae
Updated architecture.md
pinebit Mar 26, 2024
1d6ceee
Merge branch 'main' into pinebit/integrating-v3
pinebit Mar 26, 2024
db9906c
Added mockery and lazy_test.go
pinebit Mar 26, 2024
6574da9
Merge branch 'main' into pinebit/integrating-v3
pinebit Mar 26, 2024
7e85112
codecov to ignore mocks
pinebit Mar 26, 2024
27e8e1d
fixing flakey test
pinebit Mar 26, 2024
dd28585
improved test coverage for signeddata_test.go
pinebit Mar 26, 2024
ec9dd8c
bumped go-eth2-client to v0.21.1
pinebit Mar 27, 2024
2eb8ae7
added signed and unsigned data tests
pinebit Mar 27, 2024
f1b930b
workaround for ssz
pinebit Mar 27, 2024
2aa75ee
workaround for ssz
pinebit Mar 27, 2024
d587e0a
disabled integration tests with teku
pinebit Mar 27, 2024
721e528
ssz respecting blinded flag
pinebit Mar 27, 2024
4f2c374
improved test coverage
pinebit Mar 27, 2024
f67ae28
improved test coverage
pinebit Mar 27, 2024
a68ea76
improved test coverage
pinebit Mar 27, 2024
1de2c5d
improved test coverage
pinebit Mar 28, 2024
41b7755
improved test coverage
pinebit Mar 28, 2024
8e01adb
improved test coverage and updated docs
pinebit Mar 29, 2024
df5f70c
Addressed PR feedback
pinebit Apr 3, 2024
da588bf
Fixed spec compatibility issues
pinebit Apr 4, 2024
4cb7a83
Code refactoring
pinebit Apr 4, 2024
03cbf9a
Tracker: changed error level back to warning
pinebit Apr 4, 2024
fd10c0e
Merge branch 'main' into pinebit/integrating-v3
pinebit Apr 9, 2024
ae2ed1f
Merge branch 'main' into pinebit/integrating-v3
pinebit Apr 12, 2024
61eda91
Merge branch 'main' into pinebit/integrating-v3
pinebit May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@
return err
}

fetch, err := fetcher.New(eth2Cl, feeRecipientFunc)
fetch, err := fetcher.New(eth2Cl, feeRecipientFunc, mutableConf.BuilderAPI)

Check warning on line 440 in app/app.go

View check run for this annotation

Codecov / codecov/patch

app/app.go#L440

Added line #L440 was not covered by tests
if err != nil {
return err
}
Expand Down
151 changes: 1 addition & 150 deletions app/eth2wrap/eth2wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/obolnetwork/charon/app/forkjoin"
"github.com/obolnetwork/charon/app/promauto"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/eth2util/eth2exp"
)

//go:generate go run genwrap/genwrap.go
Expand Down Expand Up @@ -80,6 +79,7 @@ func NewMultiHTTP(timeout time.Duration, addresses ...string) (Client, error) {
eth2http.WithLogLevel(zeroLogInfo),
eth2http.WithAddress(address),
eth2http.WithTimeout(timeout),
eth2http.WithAllowDelayedStart(true),
)
if err != nil {
return nil, wrapError(ctx, err, "new eth2 client", z.Str("address", address))
Expand All @@ -98,155 +98,6 @@ func NewMultiHTTP(timeout time.Duration, addresses ...string) (Client, error) {
return Instrument(clients...)
}

func newMulti(clients []Client) Client {
return multi{
clients: clients,
selector: newBestSelector(bestPeriod),
}
}

// multi implements Client by wrapping multiple clients, calling them in parallel
// and returning the first successful response.
// It also adds prometheus metrics and error wrapping.
// It also implements a best client selector.
type multi struct {
clients []Client
selector *bestSelector
}

func (multi) Name() string {
return "eth2wrap.multi"
}

func (m multi) Address() string {
address, ok := m.selector.BestAddress()
if !ok {
return m.clients[0].Address()
}

return address
}

func (m multi) SetValidatorCache(valCache func(context.Context) (ActiveValidators, error)) {
for _, cl := range m.clients {
cl.SetValidatorCache(valCache)
}
}

func (m multi) SetForkVersion(forkVersion [4]byte) {
for _, c := range m.clients {
c.SetForkVersion(forkVersion)
}
}

func (m multi) ActiveValidators(ctx context.Context) (ActiveValidators, error) {
const label = "active_validators"
// No latency since this is a cached endpoint.

res0, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) (ActiveValidators, error) {
return cl.ActiveValidators(ctx)
},
nil, nil,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res0, err
}

func (m multi) ProposerConfig(ctx context.Context) (*eth2exp.ProposerConfigResponse, error) {
const label = "proposer_config"
defer latency(label)()

res0, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) (*eth2exp.ProposerConfigResponse, error) {
return cl.ProposerConfig(ctx)
},
nil, m.selector,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res0, err
}

func (m multi) AggregateBeaconCommitteeSelections(ctx context.Context, selections []*eth2exp.BeaconCommitteeSelection) ([]*eth2exp.BeaconCommitteeSelection, error) {
const label = "aggregate_beacon_committee_selections"
defer latency(label)()

res0, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) ([]*eth2exp.BeaconCommitteeSelection, error) {
return cl.AggregateBeaconCommitteeSelections(ctx, selections)
},
nil, m.selector,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res0, err
}

func (m multi) AggregateSyncCommitteeSelections(ctx context.Context, selections []*eth2exp.SyncCommitteeSelection) ([]*eth2exp.SyncCommitteeSelection, error) {
const label = "aggregate_sync_committee_selections"
defer latency(label)()

res, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) ([]*eth2exp.SyncCommitteeSelection, error) {
return cl.AggregateSyncCommitteeSelections(ctx, selections)
},
nil, m.selector,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res, err
}

func (m multi) BlockAttestations(ctx context.Context, stateID string) ([]*eth2p0.Attestation, error) {
const label = "block_attestations"
defer latency(label)()

res, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) ([]*eth2p0.Attestation, error) {
return cl.BlockAttestations(ctx, stateID)
},
nil, m.selector,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res, err
}

func (m multi) NodePeerCount(ctx context.Context) (int, error) {
const label = "node_peer_count"
defer latency(label)()

res, err := provide(ctx, m.clients,
func(ctx context.Context, cl Client) (int, error) {
return cl.NodePeerCount(ctx)
},
nil, m.selector,
)
if err != nil {
incError(label)
err = wrapError(ctx, err, label)
}

return res, err
}

// provide calls the work function with each client in parallel, returning the
// first successful result or first error.
// The bestIdxFunc is called with the index of the client returning a successful response.
Expand Down
47 changes: 8 additions & 39 deletions app/eth2wrap/eth2wrap_gen.go

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

11 changes: 7 additions & 4 deletions app/eth2wrap/eth2wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,15 @@ func TestSyncState(t *testing.T) {

func TestErrors(t *testing.T) {
ctx := context.Background()

t.Run("network dial error", func(t *testing.T) {
cl, err := eth2wrap.NewMultiHTTP(time.Hour, "localhost:22222")
require.NoError(t, err)

_, err = cl.SlotsPerEpoch(ctx)
log.Error(ctx, "See this error log for fields", err)
require.Error(t, err)
require.ErrorContains(t, err, "beacon api new eth2 client: network operation error: dial: connect: connection refused")
require.ErrorContains(t, err, "beacon api slots_per_epoch: client is not active")
})

// Test http server that just hangs until request cancelled
Expand All @@ -189,7 +190,7 @@ func TestErrors(t *testing.T) {
_, err = cl.SlotsPerEpoch(ctx)
log.Error(ctx, "See this error log for fields", err)
require.Error(t, err)
require.ErrorContains(t, err, "beacon api new eth2 client: http request timeout: context deadline exceeded")
require.ErrorContains(t, err, "beacon api slots_per_epoch: client is not active")
})

t.Run("caller cancelled", func(t *testing.T) {
Expand Down Expand Up @@ -226,7 +227,7 @@ func TestErrors(t *testing.T) {
bmock.SignedBeaconBlockFunc = func(_ context.Context, blockID string) (*eth2spec.VersionedSignedBeaconBlock, error) {
return nil, &eth2api.Error{
Method: http.MethodGet,
Endpoint: fmt.Sprintf("/eth/v2/beacon/blocks/%s", blockID),
Endpoint: "/eth/v3/beacon/blocks/" + blockID,
StatusCode: http.StatusNotFound,
Data: []byte(fmt.Sprintf(`{"code":404,"message":"NOT_FOUND: beacon block at slot %s","stacktraces":[]}`, blockID)),
}
Expand Down Expand Up @@ -373,6 +374,9 @@ func TestOnlyTimeout(t *testing.T) {
require.Fail(t, "Expect this only to return after main ctx cancelled")
}()

// Allow the above goroutine to block on the .Spec() call.
time.Sleep(10 * time.Millisecond)

// testCtxCancel tests that no concurrent calls block if the user cancels the context.
testCtxCancel := func(t *testing.T, timeout time.Duration) {
t.Helper()
Expand Down Expand Up @@ -426,7 +430,6 @@ func TestLazy(t *testing.T) {
// Both proxies are disabled, so this should fail.
_, err = eth2Cl.NodeSyncing(ctx, nil)
require.Error(t, err)
require.Equal(t, "", eth2Cl.Address())
KaloyanTanev marked this conversation as resolved.
Show resolved Hide resolved

enabled1.Store(true)

Expand Down
30 changes: 30 additions & 0 deletions app/eth2wrap/lazy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
"github.com/obolnetwork/charon/eth2util/eth2exp"
)

//go:generate mockery --name=Client --output=mocks --outpkg=mocks --case=underscore

// NewLazyForT creates a new lazy client for testing.
func NewLazyForT(client Client) Client {
return &lazy{
provider: func(context.Context) (Client, error) {
return client, nil
},

Check warning on line 22 in app/eth2wrap/lazy.go

View check run for this annotation

Codecov / codecov/patch

app/eth2wrap/lazy.go#L21-L22

Added lines #L21 - L22 were not covered by tests
client: client,
}
}

// newLazy creates a new lazy client.
func newLazy(provider func(context.Context) (Client, error)) *lazy {
return &lazy{
Expand Down Expand Up @@ -107,6 +119,24 @@
return cl.Address()
}

func (l *lazy) IsActive() bool {
cl, ok := l.getClient()
if !ok {
return false
}

Check warning on line 126 in app/eth2wrap/lazy.go

View check run for this annotation

Codecov / codecov/patch

app/eth2wrap/lazy.go#L125-L126

Added lines #L125 - L126 were not covered by tests

return cl.IsActive()
}

func (l *lazy) IsSynced() bool {
cl, ok := l.getClient()
if !ok {
return false
}

Check warning on line 135 in app/eth2wrap/lazy.go

View check run for this annotation

Codecov / codecov/patch

app/eth2wrap/lazy.go#L134-L135

Added lines #L134 - L135 were not covered by tests

return cl.IsSynced()
}

func (l *lazy) ActiveValidators(ctx context.Context) (ActiveValidators, error) {
cl, err := l.getOrCreateClient(ctx)
if err != nil {
Expand Down
Loading
Loading