mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-07 20:43:57 -05:00
BugFix: cli stringSlice bug (#11166)
* fixing stringslice issue and adding one more filter * fixing linting and improving function based on feedback * rolling back generic function to check ci * adding function back in * testing printing error * reverting change * Added gofmt detail flag * temporary change * Another flag added * Revert changes * Modifed entrypoint * Another change * Revert * Change go image * Added -e flag * Switched to alpine image * Switched go to strech * Fix typo * Yet another image added * Added go alpine * rolling back generic * reverting version * Update go.sum reverting * Update go.mod reverting * Update Dockerfile rolling back * Update entrypoint.sh rolling back * Update go.yml reverting changes * fixing flag for config * reverting changes and moving change to another PR * Update validator/node/node.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * updating based on review * Update container/slice/slice.go Co-authored-by: Taranpreet26311 <taran@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
This commit is contained in:
@@ -100,7 +100,7 @@ func configureEth1Config(cliCtx *cli.Context) error {
|
||||
}
|
||||
|
||||
func configureNetwork(cliCtx *cli.Context) {
|
||||
if cliCtx.IsSet(cmd.BootstrapNode.Name) {
|
||||
if len(cliCtx.StringSlice(cmd.BootstrapNode.Name)) > 0 {
|
||||
c := params.BeaconNetworkConfig()
|
||||
c.BootstrapNodes = cliCtx.StringSlice(cmd.BootstrapNode.Name)
|
||||
params.OverrideBeaconNetworkConfig(c)
|
||||
|
||||
@@ -3,7 +3,9 @@ package node
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
@@ -144,6 +146,42 @@ func TestConfigureNetwork(t *testing.T) {
|
||||
assert.Equal(t, uint64(100), params.BeaconNetworkConfig().ContractDeploymentBlock)
|
||||
}
|
||||
|
||||
func TestConfigureNetwork_ConfigFile(t *testing.T) {
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
|
||||
require.NoError(t, os.WriteFile("flags_test.yaml", []byte(fmt.Sprintf("%s:\n - %s\n - %s\n", cmd.BootstrapNode.Name,
|
||||
"node1",
|
||||
"node2")), 0666))
|
||||
|
||||
require.NoError(t, set.Parse([]string{"test-command", "--" + cmd.ConfigFileFlag.Name, "flags_test.yaml"}))
|
||||
command := &cli.Command{
|
||||
Name: "test-command",
|
||||
Flags: cmd.WrapFlags([]cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: cmd.ConfigFileFlag.Name,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: cmd.BootstrapNode.Name,
|
||||
},
|
||||
}),
|
||||
Before: func(cliCtx *cli.Context) error {
|
||||
return cmd.LoadFlagsFromConfig(cliCtx, cliCtx.Command.Flags)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
//TODO: https://github.com/urfave/cli/issues/1197 right now does not set flag
|
||||
require.Equal(t, false, cliCtx.IsSet(cmd.BootstrapNode.Name))
|
||||
|
||||
require.Equal(t, strings.Join([]string{"node1", "node2"}, ","),
|
||||
strings.Join(cliCtx.StringSlice(cmd.BootstrapNode.Name), ","))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
require.NoError(t, command.Run(context))
|
||||
require.NoError(t, os.Remove("flags_test.yaml"))
|
||||
}
|
||||
|
||||
func TestConfigureInterop(t *testing.T) {
|
||||
params.SetupTestConfigCleanup(t)
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ func TestLoadFlagsFromConfig_PreProcessing_Web3signer(t *testing.T) {
|
||||
return cmd.LoadFlagsFromConfig(cliCtx, cliCtx.Command.Flags)
|
||||
},
|
||||
Action: func(cliCtx *cli.Context) error {
|
||||
//TODO: https://github.com/urfave/cli/issues/1197 right now does not set flag
|
||||
require.Equal(t, false, cliCtx.IsSet(Web3SignerPublicValidatorKeysFlag.Name))
|
||||
|
||||
require.Equal(t, strings.Join([]string{pubkey1, pubkey2}, ","),
|
||||
strings.Join(cliCtx.StringSlice(Web3SignerPublicValidatorKeysFlag.Name), ","))
|
||||
return nil
|
||||
|
||||
@@ -18,5 +18,6 @@ go_test(
|
||||
deps = [
|
||||
":go_default_library",
|
||||
"//consensus-types/primitives:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -363,3 +363,21 @@ func IsInSlots(a types.Slot, b []types.Slot) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Unique returns an array with duplicates filtered based on the type given
|
||||
func Unique(a []string) []string {
|
||||
if a == nil || len(a) <= 1 {
|
||||
return a
|
||||
}
|
||||
found := map[string]bool{}
|
||||
result := make([]string, len(a))
|
||||
end := 0
|
||||
for i := 0; i < len(a); i++ {
|
||||
if !found[a[i]] {
|
||||
found[a[i]] = true
|
||||
result[end] = a[i]
|
||||
end += 1
|
||||
}
|
||||
}
|
||||
return result[:end]
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/container/slice"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestSubsetUint64(t *testing.T) {
|
||||
@@ -587,3 +588,10 @@ func TestIsInSlots(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnique(t *testing.T) {
|
||||
t.Run("string", func(t *testing.T) {
|
||||
result := slice.Unique([]string{"a", "b", "a"})
|
||||
require.DeepEqual(t, []string{"a", "b"}, result)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ go_library(
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//config/validator/service:go_default_library",
|
||||
"//container/slice:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//io/file:go_default_library",
|
||||
"//monitoring/backup:go_default_library",
|
||||
|
||||
@@ -31,6 +31,7 @@ import (
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
validatorServiceConfig "github.com/prysmaticlabs/prysm/config/validator/service"
|
||||
"github.com/prysmaticlabs/prysm/container/slice"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/io/file"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/backup"
|
||||
@@ -456,8 +457,8 @@ func web3SignerConfig(cliCtx *cli.Context) (*remoteweb3signer.SetupConfig, error
|
||||
if cliCtx.IsSet(flags.WalletPasswordFileFlag.Name) {
|
||||
log.Warnf("%s was provided while using web3signer and will be ignored", flags.WalletPasswordFileFlag.Name)
|
||||
}
|
||||
if cliCtx.IsSet(flags.Web3SignerPublicValidatorKeysFlag.Name) {
|
||||
publicKeysSlice := cliCtx.StringSlice(flags.Web3SignerPublicValidatorKeysFlag.Name)
|
||||
|
||||
if publicKeysSlice := cliCtx.StringSlice(flags.Web3SignerPublicValidatorKeysFlag.Name); len(publicKeysSlice) > 0 {
|
||||
pks := make([]string, 0)
|
||||
if len(publicKeysSlice) == 1 {
|
||||
pURL, err := url.ParseRequestURI(publicKeysSlice[0])
|
||||
@@ -470,6 +471,7 @@ func web3SignerConfig(cliCtx *cli.Context) (*remoteweb3signer.SetupConfig, error
|
||||
pks = publicKeysSlice
|
||||
}
|
||||
if len(pks) > 0 {
|
||||
pks = slice.Unique(pks)
|
||||
var validatorKeys [][48]byte
|
||||
for _, key := range pks {
|
||||
decodedKey, decodeErr := hexutil.Decode(key)
|
||||
|
||||
Reference in New Issue
Block a user