Skip to content

Commit

Permalink
Merge branch 'master' into das-fix-l1SyncService
Browse files Browse the repository at this point in the history
  • Loading branch information
tsahee authored Jun 14, 2024
2 parents b8ab8a2 + 52cbd28 commit ead80cf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 81 deletions.
15 changes: 8 additions & 7 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ func createNodeImpl(

var stakerObj *staker.Staker
var messagePruner *MessagePruner
var stakerAddr common.Address

if config.Staker.Enable {
dp, err := StakerDataposter(
Expand Down Expand Up @@ -665,17 +666,12 @@ func createNodeImpl(
if err := wallet.Initialize(ctx); err != nil {
return nil, err
}
var validatorAddr string
if txOptsValidator != nil {
validatorAddr = txOptsValidator.From.String()
} else {
validatorAddr = config.Staker.DataPoster.ExternalSigner.Address
}
stakerAddr = dp.Sender()
whitelisted, err := stakerObj.IsWhitelisted(ctx)
if err != nil {
return nil, err
}
log.Info("running as validator", "txSender", validatorAddr, "actingAsWallet", wallet.Address(), "whitelisted", whitelisted, "strategy", config.Staker.Strategy)
log.Info("running as validator", "txSender", stakerAddr, "actingAsWallet", wallet.Address(), "whitelisted", whitelisted, "strategy", config.Staker.Strategy)
}

var batchPoster *BatchPoster
Expand Down Expand Up @@ -704,6 +700,11 @@ func createNodeImpl(
if err != nil {
return nil, err
}

// Check if staker and batch poster are using the same address
if stakerAddr != (common.Address{}) && !strings.EqualFold(config.Staker.Strategy, "watchtower") && stakerAddr == batchPoster.dataPoster.Sender() {
return nil, fmt.Errorf("staker and batch poster are using the same address which is not allowed: %v", stakerAddr)
}
}

// always create DelayedSequencer, it won't do anything if it is disabled
Expand Down
7 changes: 0 additions & 7 deletions cmd/conf/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
type ParentChainConfig struct {
ID uint64 `koanf:"id"`
Connection rpcclient.ClientConfig `koanf:"connection" reload:"hot"`
Wallet genericconf.WalletConfig `koanf:"wallet"`
BlobClient headerreader.BlobClientConfig `koanf:"blob-client"`
}

Expand All @@ -31,7 +30,6 @@ var L1ConnectionConfigDefault = rpcclient.ClientConfig{
var L1ConfigDefault = ParentChainConfig{
ID: 0,
Connection: L1ConnectionConfigDefault,
Wallet: DefaultL1WalletConfig,
BlobClient: headerreader.DefaultBlobClientConfig,
}

Expand All @@ -46,14 +44,9 @@ var DefaultL1WalletConfig = genericconf.WalletConfig{
func L1ConfigAddOptions(prefix string, f *flag.FlagSet) {
f.Uint64(prefix+".id", L1ConfigDefault.ID, "if set other than 0, will be used to validate database and L1 connection")
rpcclient.RPCClientAddOptions(prefix+".connection", f, &L1ConfigDefault.Connection)
genericconf.WalletConfigAddOptions(prefix+".wallet", f, L1ConfigDefault.Wallet.Pathname)
headerreader.BlobClientAddOptions(prefix+".blob-client", f)
}

func (c *ParentChainConfig) ResolveDirectoryNames(chain string) {
c.Wallet.ResolveDirectoryNames(chain)
}

func (c *ParentChainConfig) Validate() error {
return c.Connection.Validate()
}
Expand Down
28 changes: 14 additions & 14 deletions cmd/nitro/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ func TestEmptyCliConfig(t *testing.T) {
}

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 --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
_, _, _, err := ParseNode(context.Background(), args)
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.batch-poster.parent-chain-wallet.pathname /l1keystore --node.batch-poster.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
_, _, err := ParseNode(context.Background(), args)
Require(t, err)
}

func TestUnsafeStakerConfig(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.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null --node.staker.dangerous.without-block-validator", " ")
_, _, _, err := ParseNode(context.Background(), args)
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null --node.staker.dangerous.without-block-validator", " ")
_, _, err := ParseNode(context.Background(), args)
Require(t, err)
}

func TestValidatorConfig(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.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null", " ")
_, _, _, err := ParseNode(context.Background(), args)
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.staker.parent-chain-wallet.pathname /l1keystore --node.staker.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.staker.enable --node.staker.strategy MakeNodes --node.staker.staker-interval 10s --execution.forwarding-target null", " ")
_, _, err := ParseNode(context.Background(), args)
Require(t, err)
}

func TestAggregatorConfig(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 --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642 --node.data-availability.enable --node.data-availability.rpc-aggregator.backends {[\"url\":\"http://localhost:8547\",\"pubkey\":\"abc==\",\"signerMask\":0x1]}", " ")
_, _, _, err := ParseNode(context.Background(), args)
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.batch-poster.parent-chain-wallet.pathname /l1keystore --node.batch-poster.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642 --node.data-availability.enable --node.data-availability.rpc-aggregator.backends {[\"url\":\"http://localhost:8547\",\"pubkey\":\"abc==\",\"signerMask\":0x1]}", " ")
_, _, err := ParseNode(context.Background(), args)
Require(t, err)
}

Expand Down Expand Up @@ -120,13 +120,13 @@ func TestLiveNodeConfig(t *testing.T) {
jsonConfig := "{\"chain\":{\"id\":421613}}"
Require(t, WriteToConfigFile(configFile, jsonConfig))

args := strings.Split("--file-logging.enable=false --persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --parent-chain.wallet.pathname /l1keystore --parent-chain.wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
args := strings.Split("--file-logging.enable=false --persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --node.batch-poster.parent-chain-wallet.pathname /l1keystore --node.batch-poster.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
args = append(args, []string{"--conf.file", configFile}...)
config, _, _, err := ParseNode(context.Background(), args)
config, _, err := ParseNode(context.Background(), args)
Require(t, err)

liveConfig := genericconf.NewLiveConfig[*NodeConfig](args, config, func(ctx context.Context, args []string) (*NodeConfig, error) {
nodeConfig, _, _, err := ParseNode(ctx, args)
nodeConfig, _, err := ParseNode(ctx, args)
return nodeConfig, err
})

Expand Down Expand Up @@ -201,13 +201,13 @@ func TestPeriodicReloadOfLiveNodeConfig(t *testing.T) {
jsonConfig := "{\"conf\":{\"reload-interval\":\"20ms\"}}"
Require(t, WriteToConfigFile(configFile, jsonConfig))

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 --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
args := strings.Split("--persistent.chain /tmp/data --init.dev-init --node.parent-chain-reader.enable=false --parent-chain.id 5 --chain.id 421613 --node.batch-poster.parent-chain-wallet.pathname /l1keystore --node.batch-poster.parent-chain-wallet.password passphrase --http.addr 0.0.0.0 --ws.addr 0.0.0.0 --node.sequencer --execution.sequencer.enable --node.feed.output.enable --node.feed.output.port 9642", " ")
args = append(args, []string{"--conf.file", configFile}...)
config, _, _, err := ParseNode(context.Background(), args)
config, _, err := ParseNode(context.Background(), args)
Require(t, err)

liveConfig := genericconf.NewLiveConfig[*NodeConfig](args, config, func(ctx context.Context, args []string) (*NodeConfig, error) {
nodeConfig, _, _, err := ParseNode(ctx, args)
nodeConfig, _, err := ParseNode(ctx, args)
return nodeConfig, err
})
liveConfig.Start(ctx)
Expand Down
77 changes: 27 additions & 50 deletions cmd/nitro/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func mainImpl() int {
defer cancelFunc()

args := os.Args[1:]
nodeConfig, l1Wallet, l2DevWallet, err := ParseNode(ctx, args)
nodeConfig, l2DevWallet, err := ParseNode(ctx, args)
if err != nil {
confighelpers.PrintErrorAndExit(err, printSampleUsage)
}
Expand Down Expand Up @@ -232,7 +232,6 @@ func mainImpl() int {
log.Error("consensus and execution must agree if sequencing is enabled or not", "Execution.Sequencer.Enable", nodeConfig.Execution.Sequencer.Enable, "Node.Sequencer", nodeConfig.Node.Sequencer)
}

var l1TransactionOpts *bind.TransactOpts
var dataSigner signature.DataSignerFunc
var l1TransactionOptsValidator *bind.TransactOpts
var l1TransactionOptsBatchPoster *bind.TransactOpts
Expand All @@ -243,7 +242,6 @@ func mainImpl() int {
validatorNeedsKey := nodeConfig.Node.Staker.OnlyCreateWalletContract ||
(nodeConfig.Node.Staker.Enable && !strings.EqualFold(nodeConfig.Node.Staker.Strategy, "watchtower") && nodeConfig.Node.Staker.DataPoster.ExternalSigner.URL == "")

l1Wallet.ResolveDirectoryNames(nodeConfig.Persistent.Chain)
defaultL1WalletConfig := conf.DefaultL1WalletConfig
defaultL1WalletConfig.ResolveDirectoryNames(nodeConfig.Persistent.Chain)

Expand All @@ -255,42 +253,24 @@ func mainImpl() int {
defaultBatchPosterL1WalletConfig := arbnode.DefaultBatchPosterL1WalletConfig
defaultBatchPosterL1WalletConfig.ResolveDirectoryNames(nodeConfig.Persistent.Chain)

if nodeConfig.Node.Staker.ParentChainWallet == defaultValidatorL1WalletConfig && nodeConfig.Node.BatchPoster.ParentChainWallet == defaultBatchPosterL1WalletConfig {
if sequencerNeedsKey || validatorNeedsKey || l1Wallet.OnlyCreateKey {
l1TransactionOpts, dataSigner, err = util.OpenWallet("l1", l1Wallet, new(big.Int).SetUint64(nodeConfig.ParentChain.ID))
if err != nil {
flag.Usage()
log.Crit("error opening parent chain wallet", "path", l1Wallet.Pathname, "account", l1Wallet.Account, "err", err)
}
if l1Wallet.OnlyCreateKey {
return 0
}
l1TransactionOptsBatchPoster = l1TransactionOpts
l1TransactionOptsValidator = l1TransactionOpts
if sequencerNeedsKey || nodeConfig.Node.BatchPoster.ParentChainWallet.OnlyCreateKey {
l1TransactionOptsBatchPoster, dataSigner, err = util.OpenWallet("l1-batch-poster", &nodeConfig.Node.BatchPoster.ParentChainWallet, new(big.Int).SetUint64(nodeConfig.ParentChain.ID))
if err != nil {
flag.Usage()
log.Crit("error opening Batch poster parent chain wallet", "path", nodeConfig.Node.BatchPoster.ParentChainWallet.Pathname, "account", nodeConfig.Node.BatchPoster.ParentChainWallet.Account, "err", err)
}
} else {
if *l1Wallet != defaultL1WalletConfig {
log.Crit("--parent-chain.wallet cannot be set if either --node.staker.l1-wallet or --node.batch-poster.l1-wallet are set")
if nodeConfig.Node.BatchPoster.ParentChainWallet.OnlyCreateKey {
return 0
}
if sequencerNeedsKey || nodeConfig.Node.BatchPoster.ParentChainWallet.OnlyCreateKey {
l1TransactionOptsBatchPoster, dataSigner, err = util.OpenWallet("l1-batch-poster", &nodeConfig.Node.BatchPoster.ParentChainWallet, new(big.Int).SetUint64(nodeConfig.ParentChain.ID))
if err != nil {
flag.Usage()
log.Crit("error opening Batch poster parent chain wallet", "path", nodeConfig.Node.BatchPoster.ParentChainWallet.Pathname, "account", nodeConfig.Node.BatchPoster.ParentChainWallet.Account, "err", err)
}
if nodeConfig.Node.BatchPoster.ParentChainWallet.OnlyCreateKey {
return 0
}
}
if validatorNeedsKey || nodeConfig.Node.Staker.ParentChainWallet.OnlyCreateKey {
l1TransactionOptsValidator, _, err = util.OpenWallet("l1-validator", &nodeConfig.Node.Staker.ParentChainWallet, new(big.Int).SetUint64(nodeConfig.ParentChain.ID))
if err != nil {
flag.Usage()
log.Crit("error opening Validator parent chain wallet", "path", nodeConfig.Node.Staker.ParentChainWallet.Pathname, "account", nodeConfig.Node.Staker.ParentChainWallet.Account, "err", err)
}
if validatorNeedsKey || nodeConfig.Node.Staker.ParentChainWallet.OnlyCreateKey {
l1TransactionOptsValidator, _, err = util.OpenWallet("l1-validator", &nodeConfig.Node.Staker.ParentChainWallet, new(big.Int).SetUint64(nodeConfig.ParentChain.ID))
if err != nil {
flag.Usage()
log.Crit("error opening Validator parent chain wallet", "path", nodeConfig.Node.Staker.ParentChainWallet.Pathname, "account", nodeConfig.Node.Staker.ParentChainWallet.Account, "err", err)
}
if nodeConfig.Node.Staker.ParentChainWallet.OnlyCreateKey {
return 0
}
if nodeConfig.Node.Staker.ParentChainWallet.OnlyCreateKey {
return 0
}
}

Expand Down Expand Up @@ -318,7 +298,7 @@ func mainImpl() int {
}
}
liveNodeConfig := genericconf.NewLiveConfig[*NodeConfig](args, nodeConfig, func(ctx context.Context, args []string) (*NodeConfig, error) {
nodeConfig, _, _, err := ParseNode(ctx, args)
nodeConfig, _, err := ParseNode(ctx, args)
return nodeConfig, err
})

Expand Down Expand Up @@ -798,7 +778,6 @@ func (c *NodeConfig) ResolveDirectoryNames() error {
if err != nil {
return err
}
c.ParentChain.ResolveDirectoryNames(c.Persistent.Chain)
c.Chain.ResolveDirectoryNames(c.Persistent.Chain)

return nil
Expand Down Expand Up @@ -868,14 +847,14 @@ func (c *NodeConfig) GetReloadInterval() time.Duration {
return c.Conf.ReloadInterval
}

func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.WalletConfig, *genericconf.WalletConfig, error) {
func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.WalletConfig, error) {
f := flag.NewFlagSet("", flag.ContinueOnError)

NodeConfigAddOptions(f)

k, err := confighelpers.BeginCommonParse(f, args)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}

l2ChainId := k.Int64("chain.id")
Expand All @@ -886,17 +865,17 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa
l2ChainInfoJson := k.String("chain.info-json")
err = applyChainParameters(ctx, k, uint64(l2ChainId), l2ChainName, l2ChainInfoFiles, l2ChainInfoJson, l2ChainInfoIpfsUrl, l2ChainInfoIpfsDownloadPath)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}

err = confighelpers.ApplyOverrides(f, k)
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}

var nodeConfig NodeConfig
if err := confighelpers.EndCommonParse(k, &nodeConfig); err != nil {
return nil, nil, nil, err
return nil, nil, err
}

// Don't print wallet passwords
Expand All @@ -908,33 +887,31 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa
"chain.dev-wallet.private-key": "",
})
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
}

if nodeConfig.Persistent.Chain == "" {
return nil, nil, nil, errors.New("--persistent.chain not specified")
return nil, nil, errors.New("--persistent.chain not specified")
}

err = nodeConfig.ResolveDirectoryNames()
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}

// Don't pass around wallet contents with normal configuration
l1Wallet := nodeConfig.ParentChain.Wallet
l2DevWallet := nodeConfig.Chain.DevWallet
nodeConfig.ParentChain.Wallet = genericconf.WalletConfigDefault
nodeConfig.Chain.DevWallet = genericconf.WalletConfigDefault

if nodeConfig.Execution.Caching.Archive {
nodeConfig.Node.MessagePruner.Enable = false
}
err = nodeConfig.Validate()
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
return &nodeConfig, &l1Wallet, &l2DevWallet, nil
return &nodeConfig, &l2DevWallet, nil
}

func aggregateL2ChainInfoFiles(ctx context.Context, l2ChainInfoFiles []string, l2ChainInfoIpfsUrl string, l2ChainInfoIpfsDownloadPath string) []string {
Expand Down
Loading

0 comments on commit ead80cf

Please sign in to comment.