mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Copy slice when exiting all keys with --exit-all (#8897)
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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"
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user