Skip to content

Commit fe440bc

Browse files
Copy slice when exiting all keys with --exit-all (#8897)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
1 parent f68e084 commit fe440bc

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

validator/accounts/accounts_exit.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,7 @@ func interact(
191191
}
192192
}
193193
} else {
194-
rawPubKeys = make([][]byte, len(validatingPublicKeys))
195-
formattedPubKeys = make([]string, len(validatingPublicKeys))
196-
for i, pk := range validatingPublicKeys {
197-
rawPubKeys[i] = pk[:]
198-
formattedPubKeys[i] = fmt.Sprintf("%#x", bytesutil.Trunc(pk[:]))
199-
}
194+
rawPubKeys, formattedPubKeys = prepareAllKeys(validatingPublicKeys)
200195
fmt.Printf("About to perform a voluntary exit of %d accounts\n", len(rawPubKeys))
201196
}
202197

@@ -221,6 +216,17 @@ func interact(
221216
return rawPubKeys, formattedPubKeys, nil
222217
}
223218

219+
func prepareAllKeys(validatingKeys [][48]byte) (raw [][]byte, formatted []string) {
220+
raw = make([][]byte, len(validatingKeys))
221+
formatted = make([]string, len(validatingKeys))
222+
for i, pk := range validatingKeys {
223+
raw[i] = make([]byte, len(pk))
224+
copy(raw[i], pk[:])
225+
formatted[i] = fmt.Sprintf("%#x", bytesutil.Trunc(pk[:]))
226+
}
227+
return
228+
}
229+
224230
func prepareClients(cliCtx *cli.Context) (*ethpb.BeaconNodeValidatorClient, *ethpb.NodeClient, error) {
225231
dialOpts := client.ConstructDialOptions(
226232
cliCtx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name),

validator/accounts/accounts_exit_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/golang/mock/gomock"
1212
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
13+
"github.com/prysmaticlabs/prysm/shared/bytesutil"
1314
"github.com/prysmaticlabs/prysm/shared/mock"
1415
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
1516
"github.com/prysmaticlabs/prysm/shared/testutil/require"
@@ -266,3 +267,15 @@ func TestDisplayExitInfo_NoKeys(t *testing.T) {
266267
displayExitInfo([][]byte{}, []string{})
267268
assert.LogsContain(t, logHook, "No successful voluntary exits")
268269
}
270+
271+
func TestPrepareAllKeys(t *testing.T) {
272+
key1 := bytesutil.ToBytes48([]byte("key1"))
273+
key2 := bytesutil.ToBytes48([]byte("key2"))
274+
raw, formatted := prepareAllKeys([][48]byte{key1, key2})
275+
require.Equal(t, 2, len(raw))
276+
require.Equal(t, 2, len(formatted))
277+
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 49}), bytesutil.ToBytes48(raw[0]))
278+
assert.DeepEqual(t, bytesutil.ToBytes48([]byte{107, 101, 121, 50}), bytesutil.ToBytes48(raw[1]))
279+
assert.Equal(t, "0x6b6579310000", formatted[0])
280+
assert.Equal(t, "0x6b6579320000", formatted[1])
281+
}

0 commit comments

Comments
 (0)