Skip to content

Commit

Permalink
Allow resending of the same validator registration (ethereum#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruteri committed Jul 29, 2022
1 parent 132019d commit 76ffdb0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 6 additions & 1 deletion builder/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ func (b *Backend) handleRegisterValidator(w http.ResponseWriter, req *http.Reque
for _, registerRequest := range payload {
pubkeyHex := PubkeyHex(registerRequest.Message.Pubkey.String())
if previousValidatorData, ok := b.validators[pubkeyHex]; ok {
if registerRequest.Message.Timestamp <= previousValidatorData.Timestamp {
if registerRequest.Message.Timestamp < previousValidatorData.Timestamp {
respondError(w, http.StatusBadRequest, "invalid timestamp")
return
}

if registerRequest.Message.Timestamp == previousValidatorData.Timestamp && (registerRequest.Message.FeeRecipient != previousValidatorData.FeeRecipient || registerRequest.Message.GasLimit != previousValidatorData.GasLimit) {
respondError(w, http.StatusBadRequest, "invalid timestamp")
return
}
Expand Down
3 changes: 1 addition & 2 deletions builder/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func TestValidatorRegistration(t *testing.T) {
require.Equal(t, ValidatorData{FeeRecipient: payload[0].Message.FeeRecipient, GasLimit: payload[0].Message.GasLimit, Timestamp: payload[0].Message.Timestamp}, backend.validators[PubkeyHex(v.Pk.String())])

rr = testRequest(t, backend, "POST", "/eth/v1/builder/validators", payload)
require.Equal(t, http.StatusBadRequest, rr.Code)
require.Equal(t, `{"code":400,"message":"invalid timestamp"}`+"\n", rr.Body.String())
require.Equal(t, http.StatusOK, rr.Code)

payload[0].Message.Timestamp += 1
// Invalid signature
Expand Down

0 comments on commit 76ffdb0

Please sign in to comment.