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

Test that parsing an empty CLI option set results in a default config #1661

Merged
merged 23 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[submodule "go-ethereum"]
path = go-ethereum
url = https://github.com/OffchainLabs/go-ethereum.git
branch = missing_bloom_confirm
[submodule "fastcache"]
path = fastcache
url = https://github.com/OffchainLabs/fastcache.git
Expand Down
1 change: 1 addition & 0 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ var DefaultBatchPosterConfig = BatchPosterConfig{
ExtraBatchGas: 50_000,
DataPoster: dataposter.DefaultDataPosterConfig,
L1Wallet: DefaultBatchPosterL1WalletConfig,
RedisLock: DefaultRedisLockConfig,
}

var DefaultBatchPosterL1WalletConfig = genericconf.WalletConfig{
Expand Down
1 change: 1 addition & 0 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ var ConfigDefault = Config{
DelayedSequencer: DefaultDelayedSequencerConfig,
BatchPoster: DefaultBatchPosterConfig,
ForwardingTargetImpl: "",
Forwarder: execution.DefaultNodeForwarderConfig,
TxPreChecker: execution.DefaultTxPreCheckerConfig,
BlockValidator: staker.DefaultBlockValidatorConfig,
Feed: broadcastclient.FeedConfigDefault,
Expand Down
2 changes: 1 addition & 1 deletion arbnode/simple_redis_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RedisLockConfigAddOptions(prefix string, f *flag.FlagSet) {
f.String(prefix+".my-id", "", "this node's id prefix when acquiring the lock (optional)")
f.Duration(prefix+".lockout-duration", DefaultRedisLockConfig.LockoutDuration, "how long lock is held")
f.Duration(prefix+".refresh-duration", DefaultRedisLockConfig.RefreshDuration, "how long between consecutive calls to redis")
f.String(prefix+".key", prefix+".simple-lock-key", "key for lock")
f.String(prefix+".key", DefaultRedisLockConfig.Key, "key for lock")
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
f.Bool(prefix+".background-lock", DefaultRedisLockConfig.BackgroundLock, "should node always try grabing lock in background")
}

Expand Down
2 changes: 1 addition & 1 deletion broadcastclient/broadcastclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ var DefaultConfig = Config{
RequireChainId: false,
RequireFeedVersion: false,
Verifier: signature.DefultFeedVerifierConfig,
URLs: []string{""},
URLs: []string{},
Timeout: 20 * time.Second,
EnableCompression: true,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/genericconf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ConfConfigAddOptions(prefix string, f *flag.FlagSet) {
var ConfConfigDefault = ConfConfig{
Dump: false,
EnvPrefix: "",
File: nil,
File: []string{},
S3: DefaultS3Config,
String: "",
ReloadInterval: 0,
Expand Down
6 changes: 3 additions & 3 deletions cmd/genericconf/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var HTTPConfigDefault = HTTPConfig{
Port: 8547,
API: append(node.DefaultConfig.HTTPModules, "eth", "arb"),
RPCPrefix: node.DefaultConfig.HTTPPathPrefix,
CORSDomain: node.DefaultConfig.HTTPCors,
CORSDomain: []string{},
VHosts: node.DefaultConfig.HTTPVirtualHosts,
ServerTimeouts: HTTPServerTimeoutConfigDefault,
}
Expand Down Expand Up @@ -91,7 +91,7 @@ var WSConfigDefault = WSConfig{
Port: 8548,
API: append(node.DefaultConfig.WSModules, "eth", "arb"),
RPCPrefix: node.DefaultConfig.WSPathPrefix,
Origins: node.DefaultConfig.WSOrigins,
Origins: []string{},
ExposeAll: node.DefaultConfig.WSExposeAll,
}

Expand Down Expand Up @@ -137,7 +137,7 @@ type GraphQLConfig struct {

var GraphQLConfigDefault = GraphQLConfig{
Enable: false,
CORSDomain: node.DefaultConfig.GraphQLCors,
CORSDomain: []string{},
VHosts: node.DefaultConfig.GraphQLVirtualHosts,
}

Expand Down
19 changes: 19 additions & 0 deletions cmd/nitro/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ import (
"testing"
"time"

"github.com/offchainlabs/nitro/cmd/util/confighelpers"
"github.com/offchainlabs/nitro/util/colors"
"github.com/offchainlabs/nitro/util/testhelpers"

"github.com/r3labs/diff/v3"
flag "github.com/spf13/pflag"
)

func TestEmptyCliConfig(t *testing.T) {
f := flag.NewFlagSet("", flag.ContinueOnError)
NodeConfigAddOptions(f)
k, err := confighelpers.BeginCommonParse(f, []string{})
Require(t, err)
var emptyCliNodeConfig NodeConfig
err = confighelpers.EndCommonParse(k, &emptyCliNodeConfig)
Require(t, err)
if !reflect.DeepEqual(emptyCliNodeConfig, NodeConfigDefault) {
changelog, err := diff.Diff(emptyCliNodeConfig, NodeConfigDefault)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we use cmp.Diff elsewhere, which could also replace the reflect.DeepEqual call I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah actually initially i was using cmp.Diff only but i am running into this issue with it

cannot handle unexported field at {main.NodeConfig}.Node.BatchPoster.gasRefunder: "github.com/offchainlabs/nitro/arbnode".BatchPosterConfig consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported [recovered] panic: cannot handle unexported field at {main.NodeConfig}.Node.BatchPoster.gasRefunder: "github.com/offchainlabs/nitro/arbnode".BatchPosterConfig consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported

Wasn't sure how solve it in a generic manner so that it does not happen when add a new struct, hence moved to reflect.DeepEqual, let me know you have ideas on how to solve it. Thanks.

Require(t, err)
Fail(t, "empty cli config differs from expected default", changelog)
}
}

func TestSeqConfig(t *testing.T) {
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --parent-chain.wallet.pathname /l1keystore --parent-chain.wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
_, _, _, err := ParseNode(context.Background(), args)
Expand Down
6 changes: 6 additions & 0 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,22 @@ type NodeConfig struct {
var NodeConfigDefault = NodeConfig{
Conf: genericconf.ConfConfigDefault,
Node: arbnode.ConfigDefault,
Validation: valnode.DefaultValidationConfig,
L1: conf.L1ConfigDefault,
L2: conf.L2ConfigDefault,
LogLevel: int(log.LvlInfo),
LogType: "plaintext",
FileLogging: genericconf.DefaultFileLoggingConfig,
Persistent: conf.PersistentConfigDefault,
HTTP: genericconf.HTTPConfigDefault,
WS: genericconf.WSConfigDefault,
IPC: genericconf.IPCConfigDefault,
AuthRPC: genericconf.AuthRPCConfigDefault,
GraphQL: genericconf.GraphQLConfigDefault,
Metrics: false,
MetricsServer: genericconf.MetricsServerConfigDefault,
Init: InitConfigDefault,
Rpc: genericconf.DefaultRpcConfig,
}

func NodeConfigAddOptions(f *flag.FlagSet) {
Expand Down
1 change: 1 addition & 0 deletions das/das.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var DefaultDataAvailabilityConfig = DataAvailabilityConfig{
RestfulClientAggregatorConfig: DefaultRestfulClientAggregatorConfig,
L1ConnectionAttempts: 15,
PanicOnError: false,
IpfsStorageServiceConfig: DefaultIpfsStorageServiceConfig,
}

func OptionalAddressFromString(s string) (*common.Address, error) {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/multiformats/go-multiaddr v0.8.0
github.com/multiformats/go-multihash v0.2.1
github.com/pkg/errors v0.9.1
github.com/r3labs/diff/v3 v3.0.1
github.com/spf13/pflag v1.0.5
github.com/wealdtech/go-merkletree v1.0.0
golang.org/x/term v0.5.0
Expand Down Expand Up @@ -228,6 +229,8 @@ require (
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
github.com/whyrusleeping/cbor-gen v0.0.0-20230126041949-52956bd4c9aa // indirect
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,8 @@ github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y
github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA=
github.com/quic-go/webtransport-go v0.5.2 h1:GA6Bl6oZY+g/flt00Pnu0XtivSD8vukOu3lYhJjnGEk=
github.com/quic-go/webtransport-go v0.5.2/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU=
github.com/r3labs/diff/v3 v3.0.1 h1:CBKqf3XmNRHXKmdU7mZP1w7TV0pDyVCis1AUHtA4Xtg=
github.com/r3labs/diff/v3 v3.0.1/go.mod h1:f1S9bourRbiM66NskseyUdo0fTmEE0qKrikYJX63dgo=
github.com/rabbitmq/amqp091-go v1.1.0/go.mod h1:ogQDLSOACsLPsIq0NpbtiifNZi2YOz0VTJ0kHRghqbM=
github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk=
github.com/raulk/go-watchdog v1.3.0/go.mod h1:fIvOnLbF0b0ZwkB9YU4mOW9Did//4vPZtDqv66NfsMU=
Expand Down Expand Up @@ -1586,6 +1588,10 @@ github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/wangjia184/sortedset v0.0.0-20160527075905-f5d03557ba30/go.mod h1:YkocrP2K2tcw938x9gCOmT5G5eCD6jsTz0SZuyAqwIE=
github.com/warpfork/go-testmark v0.3.0/go.mod h1:jhEf8FVxd+F17juRubpmut64NEG6I2rgkUhlcqqXwE0=
github.com/warpfork/go-testmark v0.9.0/go.mod h1:jhEf8FVxd+F17juRubpmut64NEG6I2rgkUhlcqqXwE0=
Expand Down
1 change: 1 addition & 0 deletions util/headerreader/header_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func AddOptions(prefix string, f *flag.FlagSet) {
f.Bool(prefix+".poll-only", DefaultConfig.PollOnly, "do not attempt to subscribe to header events")
f.Bool(prefix+".use-finality-data", DefaultConfig.UseFinalityData, "use l1 data about finalized/safe blocks")
f.Duration(prefix+".poll-interval", DefaultConfig.PollInterval, "interval when polling endpoint")
f.Duration(prefix+".subscribe-err-interval", DefaultConfig.SubscribeErrInterval, "interval for subscribe error")
f.Duration(prefix+".tx-timeout", DefaultConfig.TxTimeout, "timeout when waiting for a transaction")
f.Duration(prefix+".old-header-timeout", DefaultConfig.OldHeaderTimeout, "warns if the latest l1 block is at least this old")
}
Expand Down
6 changes: 2 additions & 4 deletions util/signature/sign_verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ func SignVerifyConfigAddOptions(prefix string, f *flag.FlagSet) {
}

var DefaultSignVerifyConfig = SignVerifyConfig{
ECDSA: VerifierConfig{
AcceptSequencer: true,
},
ECDSA: DefultFeedVerifierConfig,
SymmetricFallback: false,
SymmetricSign: false,
Symmetric: TestSimpleHmacConfig,
Symmetric: EmptySimpleHmacConfig,
}

func NewSignVerify(config *SignVerifyConfig, signerFunc DataSignerFunc, bpValidator contracts.BatchPosterVerifierInterface) (*SignVerify, error) {
Expand Down
2 changes: 1 addition & 1 deletion util/signature/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var ErrMissingSignature = fmt.Errorf("%w: signature not found", ErrSignatureNotV
var ErrSignerNotApproved = fmt.Errorf("%w: signer not approved", ErrSignatureNotVerified)

func FeedVerifierConfigAddOptions(prefix string, f *flag.FlagSet) {
f.StringArray(prefix+".allowed-addresses", DefultFeedVerifierConfig.AllowedAddresses, "a list of allowed addresses")
f.StringSlice(prefix+".allowed-addresses", DefultFeedVerifierConfig.AllowedAddresses, "a list of allowed addresses")
f.Bool(prefix+".accept-sequencer", DefultFeedVerifierConfig.AcceptSequencer, "accept verified message from sequencer")
DangerousFeedVerifierConfigAddOptions(prefix+".dangerous", f)
}
Expand Down