Skip to content

Commit

Permalink
Handle wrong withdrawal credentials (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
alrevuelta authored Oct 31, 2023
1 parent 09f446d commit fa2426b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
24 changes: 24 additions & 0 deletions oracle/onchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package oracle

import (
"context"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -83,6 +84,29 @@ func Test_FetchFromExecution(t *testing.T) {
//require.Equal(t, expectedValue, balance)
}

func Test_GetValidator(t *testing.T) {
if skip {
t.Skip("Skipping test")
}

var cfgOnchain = &config.CliConfig{
ConsensusEndpoint: "http://127.0.0.1:3500",
ExecutionEndpoint: "http://127.0.0.1:8545",
}
onChain, err := NewOnchain(cfgOnchain, nil)
require.NoError(t, err)

vals, err := onChain.GetFinalizedValidators()
require.NoError(t, err)

for _, valEl := range vals {
fmt.Println(valEl.Index)
fmt.Println("raw: ", hex.EncodeToString(valEl.Validator.WithdrawalCredentials[:]))
a, b := GetWithdrawalAndType(valEl)
fmt.Println(valEl.Index, " ", hex.EncodeToString(valEl.Validator.WithdrawalCredentials[:]), " ", a, " ", b)
}
}

func Test_IsAddressWhitelisted(t *testing.T) {
if skip {
t.Skip("Skipping test")
Expand Down
8 changes: 7 additions & 1 deletion oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,13 @@ func GetWithdrawalAndType(validator *v1.Validator) (string, WithdrawalType) {
} else if utils.IsEth1Type(withdrawalCred) {
return "0x" + withdrawalCred[24:], Eth1Withdrawal
}
log.Fatal("withdrawal credentials are not a valid type: ", withdrawalCred)
// can happen if a validator sets wrong withdrawal credentials (not very likely)
// aka not respecting the 0x00 or 0x000000000000000000000000 prefixes
// only concerning if the validator is subscribed to the pool
log.WithFields(log.Fields{
"WithdrawalCredentials": withdrawalCred,
"ValidatorIndex": validator.Index,
}).Warn("withdrawal credentials are not valid, leaving empty")
return "", 0
}

Expand Down

0 comments on commit fa2426b

Please sign in to comment.