Skip to content

Commit

Permalink
Copy slice when exiting all keys with --exit-all (#8897)
Browse files Browse the repository at this point in the history
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
rkapka and prylabs-bulldozer[bot] authored May 18, 2021
1 parent f68e084 commit fe440bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 12 additions & 6 deletions validator/accounts/accounts_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,7 @@ func interact(
}
}
} else {
rawPubKeys = make([][]byte, len(validatingPublicKeys))
formattedPubKeys = make([]string, len(validatingPublicKeys))
for i, pk := range validatingPublicKeys {
rawPubKeys[i] = pk[:]
formattedPubKeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(pk[:]))
}
rawPubKeys, formattedPubKeys = prepareAllKeys(validatingPublicKeys)
fmt.Printf("About to perform a voluntary exit of %d accounts\n", len(rawPubKeys))
}

Expand All @@ -221,6 +216,17 @@ func interact(
return rawPubKeys, formattedPubKeys, nil
}

func prepareAllKeys(validatingKeys [][48]byte) (raw [][]byte, formatted []string) {
raw = make([][]byte, len(validatingKeys))
formatted = make([]string, len(validatingKeys))
for i, pk := range validatingKeys {
raw[i] = make([]byte, len(pk))
copy(raw[i], pk[:])
formatted[i] = fmt.Sprintf("%#x", bytesutil.Trunc(pk[:]))
}
return
}

func prepareClients(cliCtx *cli.Context) (*ethpb.BeaconNodeValidatorClient, *ethpb.NodeClient, error) {
dialOpts := client.ConstructDialOptions(
cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name),
Expand Down
13 changes: 13 additions & 0 deletions validator/accounts/accounts_exit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/golang/mock/gomock"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/mock"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
Expand Down Expand Up @@ -266,3 +267,15 @@ func TestDisplayExitInfo_NoKeys(t *testing.T) {
displayExitInfo([][]byte{}, []string{})
assert.LogsContain(t, logHook, "No successful voluntary exits")
}

func TestPrepareAllKeys(t *testing.T) {
key1 := bytesutil.ToBytes48([]byte("key1"))
key2 := bytesutil.ToBytes48([]byte("key2"))
raw, formatted := prepareAllKeys([][48]byte{key1, key2})
require.Equal(t, 2, len(raw))
require.Equal(t, 2, len(formatted))
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 49}), bytesutil.ToBytes48(raw[0]))
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 50}), bytesutil.ToBytes48(raw[1]))
assert.Equal(t, "0x6b6579310000", formatted[0])
assert.Equal(t, "0x6b6579320000", formatted[1])
}

0 comments on commit fe440bc

Please sign in to comment.