Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 9292b34

Browse files
avaloncheRuteri
andcommitted
Fix duplicate relay registrations in cache (#15)
* Fix duplicate relay registrations in cache * Remove Timestamp from builder validation data as it should be ignored * Adjust cfg.SecondaryRemoteRelayEndpoints for empty list Co-authored-by: Mateusz Morusiewicz <[email protected]>
1 parent b359394 commit 9292b34

File tree

9 files changed

+28
-24
lines changed

9 files changed

+28
-24
lines changed

builder/builder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ type PubkeyHex string
2525

2626
type ValidatorData struct {
2727
Pubkey PubkeyHex
28-
FeeRecipient boostTypes.Address `json:"feeRecipient"`
29-
GasLimit uint64 `json:"gasLimit"`
30-
Timestamp uint64 `json:"timestamp"`
28+
FeeRecipient boostTypes.Address
29+
GasLimit uint64
3130
}
3231

3332
type IBeaconClient interface {
@@ -137,7 +136,7 @@ func (b *Builder) onSealedBlock(block *types.Block, ordersClosedAt time.Time, se
137136
}
138137

139138
if b.dryRun {
140-
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{blockSubmitReq, vd.GasLimit})
139+
err = b.validator.ValidateBuilderSubmissionV1(&blockvalidation.BuilderBlockValidationRequest{BuilderSubmitBlockRequest: blockSubmitReq, RegisteredGasLimit: vd.GasLimit})
141140
if err != nil {
142141
log.Error("could not validate block", "err", err)
143142
}

builder/builder_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ func TestOnPayloadAttributes(t *testing.T) {
3434
Pubkey: PubkeyHex(testBeacon.validator.Pk.String()),
3535
FeeRecipient: feeRecipient,
3636
GasLimit: 10,
37-
Timestamp: 15,
3837
},
3938
}
4039

builder/local_relay.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ type ForkData struct {
2525
GenesisValidatorsRoot string
2626
}
2727

28+
type FullValidatorData struct {
29+
ValidatorData
30+
Timestamp uint64
31+
}
32+
2833
type LocalRelay struct {
2934
beaconClient IBeaconClient
3035

@@ -36,7 +41,7 @@ type LocalRelay struct {
3641
proposerSigningDomain boostTypes.Domain
3742

3843
validatorsLock sync.RWMutex
39-
validators map[PubkeyHex]ValidatorData
44+
validators map[PubkeyHex]FullValidatorData
4045

4146
enableBeaconChecks bool
4247

@@ -70,7 +75,7 @@ func NewLocalRelay(sk *bls.SecretKey, beaconClient IBeaconClient, builderSigning
7075
proposerSigningDomain: proposerSigningDomain,
7176
serializedRelayPubkey: pkBytes,
7277

73-
validators: make(map[PubkeyHex]ValidatorData),
78+
validators: make(map[PubkeyHex]FullValidatorData),
7479

7580
enableBeaconChecks: enableBeaconChecks,
7681

@@ -161,11 +166,13 @@ func (r *LocalRelay) handleRegisterValidator(w http.ResponseWriter, req *http.Re
161166

162167
for _, registerRequest := range payload {
163168
pubkeyHex := PubkeyHex(strings.ToLower(registerRequest.Message.Pubkey.String()))
164-
r.validators[pubkeyHex] = ValidatorData{
165-
Pubkey: pubkeyHex,
166-
FeeRecipient: registerRequest.Message.FeeRecipient,
167-
GasLimit: registerRequest.Message.GasLimit,
168-
Timestamp: registerRequest.Message.Timestamp,
169+
r.validators[pubkeyHex] = FullValidatorData{
170+
ValidatorData: ValidatorData{
171+
Pubkey: pubkeyHex,
172+
FeeRecipient: registerRequest.Message.FeeRecipient,
173+
GasLimit: registerRequest.Message.GasLimit,
174+
},
175+
Timestamp: registerRequest.Message.Timestamp,
169176
}
170177

171178
log.Info("registered validator", "pubkey", pubkeyHex, "data", r.validators[pubkeyHex])
@@ -183,7 +190,7 @@ func (r *LocalRelay) GetValidatorForSlot(nextSlot uint64) (ValidatorData, error)
183190
r.validatorsLock.RLock()
184191
if vd, ok := r.validators[pubkeyHex]; ok {
185192
r.validatorsLock.RUnlock()
186-
return vd, nil
193+
return vd.ValidatorData, nil
187194
}
188195
r.validatorsLock.RUnlock()
189196
log.Info("no local entry for validator", "validator", pubkeyHex)

builder/local_relay_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestValidatorRegistration(t *testing.T) {
6969
rr := testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload)
7070
require.Equal(t, http.StatusOK, rr.Code)
7171
require.Contains(t, relay.validators, PubkeyHex(v.Pk.String()))
72-
require.Equal(t, ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())])
72+
require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())])
7373

7474
rr = testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload)
7575
require.Equal(t, http.StatusOK, rr.Code)
@@ -113,7 +113,7 @@ func registerValidator(t *testing.T, v *ValidatorPrivateData, relay *LocalRelay)
113113
rr := testRequest(t, relay, "POST", "/eth/v1/builder/validators", payload)
114114
require.Equal(t, http.StatusOK, rr.Code)
115115
require.Contains(t, relay.validators, PubkeyHex(v.Pk.String()))
116-
require.Equal(t, ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())])
116+
require.Equal(t, FullValidatorData{ValidatorData: ValidatorData{Pubkey: PubkeyHex(v.Pk.String()), FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit}, Timestamp: payload[0].Message.Timestamp}, relay.validators[PubkeyHex(v.Pk.String())])
117117
}
118118

119119
func TestGetHeader(t *testing.T) {

builder/relay.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ func (r *RemoteRelay) getSlotValidatorMapFromRelay() (map[uint64]ValidatorData,
169169
Pubkey: pubkeyHex,
170170
FeeRecipient: feeRecipient,
171171
GasLimit: data.Entry.Message.GasLimit,
172-
Timestamp: data.Entry.Message.Timestamp,
173172
}
174173
}
175174

builder/relay_aggregator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (r *RemoteRelayAggregator) updateRelayRegistrations(nextSlot uint64, regist
112112
topRegistrationCh <- registrations[bestRelayRegistrationIndex].vd
113113
}
114114

115+
if nextSlot == r.registrationsCacheSlot {
116+
return
117+
}
118+
115119
if nextSlot > r.registrationsCacheSlot {
116120
// clear the cache
117121
r.registrationsCache = make(map[ValidatorData][]IRelay)

builder/relay_aggregator_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ type testRelay struct {
2020
gvsVd ValidatorData
2121
gvsErr error
2222

23-
requestedSlot uint64
24-
submittedMsg *boostTypes.BuilderSubmitBlockRequest
25-
submittedMsgCh chan *boostTypes.BuilderSubmitBlockRequest
26-
submittedRegistration ValidatorData
23+
requestedSlot uint64
24+
submittedMsg *boostTypes.BuilderSubmitBlockRequest
25+
submittedMsgCh chan *boostTypes.BuilderSubmitBlockRequest
2726
}
2827

2928
type testRelayAggBackend struct {

builder/relay_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func TestRemoteRelay(t *testing.T) {
5252
Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a",
5353
FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x9},
5454
GasLimit: uint64(1),
55-
Timestamp: uint64(1),
5655
}
5756
require.Equal(t, expectedValidator_123, vd)
5857

@@ -98,14 +97,12 @@ func TestRemoteRelay(t *testing.T) {
9897
Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a",
9998
FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x10},
10099
GasLimit: uint64(1),
101-
Timestamp: uint64(1),
102100
}
103101

104102
expectedValidator_156 := ValidatorData{
105103
Pubkey: "0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a",
106104
FeeRecipient: boostTypes.Address{0xab, 0xcf, 0x8e, 0xd, 0x4e, 0x95, 0x87, 0x36, 0x9b, 0x23, 0x1, 0xd0, 0x79, 0x3, 0x47, 0x32, 0x3, 0x2, 0xcc, 0x11},
107105
GasLimit: uint64(1),
108-
Timestamp: uint64(1),
109106
}
110107

111108
vd, err = relay.GetValidatorForSlot(155)

builder/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func Register(stack *node.Node, backend *eth.Ethereum, cfg *Config) error {
160160
return errors.New("neither local nor remote relay specified")
161161
}
162162

163-
if len(cfg.SecondaryRemoteRelayEndpoints) > 0 {
163+
if len(cfg.SecondaryRemoteRelayEndpoints) > 0 && !(len(cfg.SecondaryRemoteRelayEndpoints) == 1 && cfg.SecondaryRemoteRelayEndpoints[0] == "") {
164164
secondaryRelays := make([]IRelay, len(cfg.SecondaryRemoteRelayEndpoints))
165165
for i, endpoint := range cfg.SecondaryRemoteRelayEndpoints {
166166
secondaryRelays[i] = NewRemoteRelay(endpoint, nil)

0 commit comments

Comments
 (0)