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

Multiple BN HTTP resolver #13433

Merged
merged 48 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
206207b
http resolver
saolyn Jan 9, 2024
5437c44
Redo
saolyn Jan 23, 2024
a3eda2d
Revert "Redo"
saolyn Feb 17, 2024
d337580
Revert "http resolver"
saolyn Feb 17, 2024
d61d6f2
Merge branch 'develop' into http-resolver
saolyn Feb 17, 2024
1c72112
Add host change to ValidatorClient + Validator
saolyn Feb 17, 2024
b7e0af5
Update mockgen
saolyn Feb 20, 2024
078368f
Merge branch 'develop' into http-resolver
saolyn Feb 20, 2024
75c1059
Tidy
saolyn Feb 20, 2024
8903562
Add mock validator
saolyn Feb 20, 2024
ea93b95
Update gomock
saolyn Feb 20, 2024
e531899
Gaz
saolyn Feb 21, 2024
e0bd304
Solve interface issues
saolyn Feb 21, 2024
5b498ee
Fix host
saolyn Feb 21, 2024
0cbe1d2
Fix test
saolyn Feb 21, 2024
622e032
Add tests
saolyn Feb 21, 2024
e30b689
Merge branch 'develop' into http-resolver
saolyn Feb 21, 2024
0a3f42c
Merge branch 'develop' into http-resolver
saolyn Feb 21, 2024
275b106
Add endpoint change log
saolyn Feb 22, 2024
de49ead
Fix log
saolyn Feb 22, 2024
1d8051a
Merge branch 'develop' into http-resolver
saolyn Mar 21, 2024
7436737
Gen mock
saolyn Mar 21, 2024
f0c5481
Fix test
saolyn Mar 21, 2024
70cb837
Fix deepsource
saolyn Mar 21, 2024
23476db
Lint + deepsource
saolyn Mar 22, 2024
c8bcaa8
Move to healthCheckRoutine
saolyn Apr 3, 2024
db506e5
Fix build errors
saolyn Apr 22, 2024
836cbaa
Switch host to string
saolyn Apr 22, 2024
ad070af
Forgot a couple
saolyn Apr 23, 2024
991ccfe
Radek' review
saolyn Apr 23, 2024
1f9aebf
Add PushProposerSettings to goroutine
saolyn Apr 23, 2024
11c5644
Radek' review
saolyn Apr 24, 2024
29cb291
James' review + test fix
saolyn Apr 24, 2024
26b1326
Radek' suggestion
saolyn Apr 25, 2024
be1186f
Check if new node is healthy
saolyn Apr 25, 2024
046d107
Fix linter errors
saolyn Apr 25, 2024
aeee310
Add host switch logic to ChangeHost
saolyn May 6, 2024
7035b9b
Merge branch 'develop' into http-resolver
saolyn May 6, 2024
0a4e750
Lint + comment
saolyn May 6, 2024
c462648
Merge branch 'develop' into http-resolver
saolyn May 22, 2024
61e1f1a
Fix messy merge
saolyn May 22, 2024
02cd3c3
rename ChangeHost to SetHost
rkapka May 28, 2024
f822c3a
improve log
rkapka May 28, 2024
b0ef618
Merge branch '__develop' into http-resolver
rkapka May 28, 2024
bab817c
remove log
rkapka May 28, 2024
600cfe8
switch one node
rkapka May 28, 2024
d968a1d
rename param
rkapka May 28, 2024
9427db4
Merge branch 'develop' into http-resolver
rkapka May 29, 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
20 changes: 20 additions & 0 deletions testing/mock/node_service_mock.go

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

20 changes: 7 additions & 13 deletions testing/validator-mock/node_client_mock.go

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

26 changes: 26 additions & 0 deletions testing/validator-mock/validator_client_mock.go

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

5 changes: 4 additions & 1 deletion validator/accounts/cli_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ func (acm *CLIManager) prepareBeaconClients(ctx context.Context) (*iface.Validat
acm.beaconApiTimeout,
)

restHandler := beaconApi.NewBeaconApiJsonRestHandler(http.Client{Timeout: acm.beaconApiTimeout}, acm.beaconApiEndpoint)
restHandler := beaconApi.NewBeaconApiJsonRestHandler(
http.Client{Timeout: acm.beaconApiTimeout},
acm.beaconApiEndpoint,
)
validatorClient := validatorClientFactory.NewValidatorClient(conn, restHandler)
nodeClient := nodeClientFactory.NewNodeClient(conn, restHandler)

Expand Down
8 changes: 8 additions & 0 deletions validator/accounts/testing/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,11 @@ func (*Validator) EventStreamIsRunning() bool {
func (*Validator) HealthTracker() *beacon.NodeHealthTracker {
panic("implement me")
}

func (*Validator) RetrieveHost() string {
panic("implement me")
}

func (*Validator) UpdateHost(_ string) {
panic("implement me")
}
8 changes: 8 additions & 0 deletions validator/client/beacon-api/beacon_api_validator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,11 @@ func wrapInMetrics[Resp any](action string, f func() (Resp, error)) (Resp, error
}
return resp, err
}

func (c *beaconApiValidatorClient) RetrieveHost() string {
return c.jsonRestHandler.Host()
}

func (c *beaconApiValidatorClient) UpdateHost(host string) {
c.jsonRestHandler.ChangeHost(host)
}
29 changes: 29 additions & 0 deletions validator/client/beacon-api/beacon_api_validator_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,32 @@ func TestBeaconApiValidatorClient_ProposeBeaconBlockError(t *testing.T) {
assert.ErrorContains(t, expectedErr.Error(), err)
assert.DeepEqual(t, expectedResp, resp)
}

func TestBeaconApiValidatorClient_Host(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

hosts := []string{"http://localhost:8080", "http://localhost:8081"}
jsonRestHandler := mock.NewMockJsonRestHandler(ctrl)
jsonRestHandler.EXPECT().ChangeHost(
hosts[0],
).Times(1)
jsonRestHandler.EXPECT().Host().Return(
hosts[0],
).Times(1)

validatorClient := beaconApiValidatorClient{jsonRestHandler: jsonRestHandler}
validatorClient.UpdateHost(hosts[0])
host := validatorClient.RetrieveHost()
require.Equal(t, hosts[0], host)

jsonRestHandler.EXPECT().ChangeHost(
hosts[1],
).Times(1)
jsonRestHandler.EXPECT().Host().Return(
hosts[1],
).Times(1)
validatorClient.UpdateHost(hosts[1])
host = validatorClient.RetrieveHost()
require.Equal(t, hosts[1], host)
}
17 changes: 11 additions & 6 deletions validator/client/beacon-api/json_rest_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type JsonRestHandler interface {
Post(ctx context.Context, endpoint string, headers map[string]string, data *bytes.Buffer, resp interface{}) error
HttpClient() *http.Client
Host() string
ChangeHost(newHost string)
}

type BeaconApiJsonRestHandler struct {
Expand All @@ -33,19 +34,19 @@ func NewBeaconApiJsonRestHandler(client http.Client, host string) JsonRestHandle
}
}

// GetHttpClient returns the underlying HTTP client of the handler
func (c BeaconApiJsonRestHandler) HttpClient() *http.Client {
// HttpClient returns the underlying HTTP client of the handler
func (c *BeaconApiJsonRestHandler) HttpClient() *http.Client {
return &c.client
}

// GetHost returns the underlying HTTP host
func (c BeaconApiJsonRestHandler) Host() string {
// Host returns the underlying HTTP host
func (c *BeaconApiJsonRestHandler) Host() string {
return c.host
}

// Get sends a GET request and decodes the response body as a JSON object into the passed in object.
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
func (c BeaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp interface{}) error {
func (c *BeaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp interface{}) error {
url := c.host + endpoint
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
Expand All @@ -67,7 +68,7 @@ func (c BeaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp

// Post sends a POST request and decodes the response body as a JSON object into the passed in object.
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
func (c BeaconApiJsonRestHandler) Post(
func (c *BeaconApiJsonRestHandler) Post(
ctx context.Context,
apiEndpoint string,
headers map[string]string,
Expand Down Expand Up @@ -134,3 +135,7 @@ func decodeResp(httpResp *http.Response, resp interface{}) error {

return nil
}

func (c *BeaconApiJsonRestHandler) ChangeHost(newHost string) {
c.host = newHost
}
47 changes: 39 additions & 8 deletions validator/client/beacon-api/mock/json_rest_handler_mock.go

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

13 changes: 11 additions & 2 deletions validator/client/grpc-api/grpc_validator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ func (c *grpcValidatorClient) AggregatedSigAndAggregationBits(
return c.beaconNodeValidatorClient.AggregatedSigAndAggregationBits(ctx, in)
}

func (grpcValidatorClient) GetAggregatedSelections(context.Context, []iface.BeaconCommitteeSelection) ([]iface.BeaconCommitteeSelection, error) {
func (*grpcValidatorClient) GetAggregatedSelections(context.Context, []iface.BeaconCommitteeSelection) ([]iface.BeaconCommitteeSelection, error) {
return nil, iface.ErrNotSupported
}

func (grpcValidatorClient) GetAggregatedSyncSelections(context.Context, []iface.SyncCommitteeSelection) ([]iface.SyncCommitteeSelection, error) {
func (*grpcValidatorClient) GetAggregatedSyncSelections(context.Context, []iface.SyncCommitteeSelection) ([]iface.SyncCommitteeSelection, error) {
return nil, iface.ErrNotSupported
}

Expand Down Expand Up @@ -245,3 +245,12 @@ func (c *grpcValidatorClient) StartEventStream(ctx context.Context, topics []str
func (c *grpcValidatorClient) EventStreamIsRunning() bool {
return c.isEventStreamRunning
}

func (*grpcValidatorClient) RetrieveHost() string {
log.Warn(iface.ErrNotSupported)
return ""
}

func (*grpcValidatorClient) UpdateHost(_ string) {
log.Warn(iface.ErrNotSupported)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be called Host/ChangeHost for consistency?

2 changes: 2 additions & 0 deletions validator/client/iface/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ type Validator interface {
SetGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, graffiti []byte) error
DeleteGraffiti(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) error
HealthTracker() *beacon.NodeHealthTracker
RetrieveHost() string
UpdateHost(host string)
saolyn marked this conversation as resolved.
Show resolved Hide resolved
}

// SigningFunc interface defines a type for the a function that signs a message
Expand Down
2 changes: 2 additions & 0 deletions validator/client/iface/validator_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,6 @@ type ValidatorClient interface {
EventStreamIsRunning() bool
GetAggregatedSelections(ctx context.Context, selections []BeaconCommitteeSelection) ([]BeaconCommitteeSelection, error)
GetAggregatedSyncSelections(ctx context.Context, selections []SyncCommitteeSelection) ([]SyncCommitteeSelection, error)
RetrieveHost() string
UpdateHost(host string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be called Host/ChangeHost for consistency?

}
Loading
Loading