Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: cli stringSlice bug #11166

Merged
merged 36 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
19463df
fixing stringslice issue and adding one more filter
james-prysm Aug 3, 2022
0aa5a21
Merge branch 'develop' into cli-stringslice-bug
james-prysm Aug 3, 2022
b8d98b7
fixing linting and improving function based on feedback
james-prysm Aug 3, 2022
f463cce
Merge branch 'develop' into cli-stringslice-bug
james-prysm Aug 3, 2022
8b10be2
rolling back generic function to check ci
james-prysm Aug 3, 2022
d38c91d
adding function back in
james-prysm Aug 3, 2022
8c54f5d
Merge branch 'develop' into cli-stringslice-bug
james-prysm Aug 5, 2022
f399104
testing printing error
james-prysm Aug 5, 2022
a2ee626
reverting change
james-prysm Aug 5, 2022
8e1b098
Added gofmt detail flag
Taranpreet26311 Aug 5, 2022
d864664
temporary change
Taranpreet26311 Aug 5, 2022
9b66ed4
Another flag added
Taranpreet26311 Aug 5, 2022
41d3120
Revert changes
Taranpreet26311 Aug 5, 2022
d68d266
Modifed entrypoint
Taranpreet26311 Aug 5, 2022
4f20d92
Another change
Taranpreet26311 Aug 5, 2022
c453272
Revert
Taranpreet26311 Aug 5, 2022
dfb3693
Change go image
Taranpreet26311 Aug 5, 2022
c9acbda
Added -e flag
Taranpreet26311 Aug 5, 2022
e03e160
Switched to alpine image
Taranpreet26311 Aug 5, 2022
7f05515
Switched go to strech
Taranpreet26311 Aug 5, 2022
62de713
Fix typo
Taranpreet26311 Aug 5, 2022
ca00c40
Yet another image added
Taranpreet26311 Aug 5, 2022
4defee7
Added go alpine
Taranpreet26311 Aug 5, 2022
11dc73b
rolling back generic
james-prysm Aug 5, 2022
4c24be4
Merge branch 'develop' into cli-stringslice-bug
james-prysm Aug 5, 2022
c7758db
reverting version
james-prysm Aug 5, 2022
91ee706
Update go.sum
james-prysm Aug 5, 2022
40c0b5c
Update go.mod
james-prysm Aug 5, 2022
59892d3
Update Dockerfile
james-prysm Aug 5, 2022
a125cc6
Update entrypoint.sh
james-prysm Aug 5, 2022
437f1df
Update go.yml
james-prysm Aug 5, 2022
3ea1de4
fixing flag for config
james-prysm Aug 5, 2022
cc34bc1
reverting changes and moving change to another PR
james-prysm Aug 8, 2022
208d00a
Update validator/node/node.go
james-prysm Aug 8, 2022
9030e08
updating based on review
james-prysm Aug 8, 2022
ff15d7b
Update container/slice/slice.go
rauljordan Aug 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 38 additions & 0 deletions beacon-chain/node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package node
import (
"flag"
"fmt"
"os"
"strconv"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions cmd/validator/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions container/slice/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ go_test(
deps = [
":go_default_library",
"//consensus-types/primitives:go_default_library",
"//testing/require:go_default_library",
],
)
18 changes: 18 additions & 0 deletions container/slice/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
8 changes: 8 additions & 0 deletions container/slice/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
})
}
1 change: 1 addition & 0 deletions validator/node/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions validator/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
Expand All @@ -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)
Expand Down