Skip to content

Commit

Permalink
Merge pull request #1869 from OffchainLabs/noop-validator-wallet
Browse files Browse the repository at this point in the history
Implement noop validator wallet and use it for watchtower staker strategy
  • Loading branch information
anodar authored Sep 27, 2023
2 parents a70b6ad + 19f7b89 commit efba003
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 24 deletions.
52 changes: 28 additions & 24 deletions arbnode/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"math/big"
"strings"
"time"

flag "github.com/spf13/pflag"
Expand Down Expand Up @@ -817,28 +818,32 @@ func createNodeImpl(
return nil, err
}
getExtraGas := func() uint64 { return configFetcher.Get().Staker.ExtraGas }
var wallet staker.ValidatorWalletInterface
if config.Staker.UseSmartContractWallet || txOptsValidator == nil {
var existingWalletAddress *common.Address
if len(config.Staker.ContractWalletAddress) > 0 {
if !common.IsHexAddress(config.Staker.ContractWalletAddress) {
log.Error("invalid validator smart contract wallet", "addr", config.Staker.ContractWalletAddress)
return nil, errors.New("invalid validator smart contract wallet address")
// TODO: factor this out into separate helper, and split rest of node
// creation into multiple helpers.
var wallet staker.ValidatorWalletInterface = validatorwallet.NewNoOp(l1client)
if !strings.EqualFold(config.Staker.Strategy, "watchtower") {
if config.Staker.UseSmartContractWallet || txOptsValidator == nil {
var existingWalletAddress *common.Address
if len(config.Staker.ContractWalletAddress) > 0 {
if !common.IsHexAddress(config.Staker.ContractWalletAddress) {
log.Error("invalid validator smart contract wallet", "addr", config.Staker.ContractWalletAddress)
return nil, errors.New("invalid validator smart contract wallet address")
}
tmpAddress := common.HexToAddress(config.Staker.ContractWalletAddress)
existingWalletAddress = &tmpAddress
}
wallet, err = validatorwallet.NewContract(dp, existingWalletAddress, deployInfo.ValidatorWalletCreator, deployInfo.Rollup, l1Reader, txOptsValidator, int64(deployInfo.DeployedAt), func(common.Address) {}, getExtraGas)
if err != nil {
return nil, err
}
} else {
if len(config.Staker.ContractWalletAddress) > 0 {
return nil, errors.New("validator contract wallet specified but flag to use a smart contract wallet was not specified")
}
wallet, err = validatorwallet.NewEOA(dp, deployInfo.Rollup, l1client, txOptsValidator, getExtraGas)
if err != nil {
return nil, err
}
tmpAddress := common.HexToAddress(config.Staker.ContractWalletAddress)
existingWalletAddress = &tmpAddress
}
wallet, err = validatorwallet.NewContract(dp, existingWalletAddress, deployInfo.ValidatorWalletCreator, deployInfo.Rollup, l1Reader, txOptsValidator, int64(deployInfo.DeployedAt), func(common.Address) {}, getExtraGas)
if err != nil {
return nil, err
}
} else {
if len(config.Staker.ContractWalletAddress) > 0 {
return nil, errors.New("validator contract wallet specified but flag to use a smart contract wallet was not specified")
}
wallet, err = validatorwallet.NewEOA(dp, deployInfo.Rollup, l1client, txOptsValidator, getExtraGas)
if err != nil {
return nil, err
}
}

Expand All @@ -852,9 +857,8 @@ func createNodeImpl(
if err != nil {
return nil, err
}
if stakerObj.Strategy() != staker.WatchtowerStrategy {
err := wallet.Initialize(ctx)
if err != nil {
if stakerObj.Strategy() == staker.WatchtowerStrategy {
if err := wallet.Initialize(ctx); err != nil {
return nil, err
}
}
Expand Down
63 changes: 63 additions & 0 deletions staker/validatorwallet/noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE

package validatorwallet

import (
"context"
"errors"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/staker/txbuilder"
)

// NoOp validator wallet is used for watchtower mode.
type NoOp struct {
l1Client arbutil.L1Interface
}

func NewNoOp(l1Client arbutil.L1Interface) *NoOp {
return &NoOp{l1Client: l1Client}
}

func (*NoOp) Initialize(context.Context) error { return nil }

func (*NoOp) Address() *common.Address { return nil }

func (*NoOp) AddressOrZero() common.Address { return common.Address{} }

func (*NoOp) TxSenderAddress() *common.Address { return nil }

func (*NoOp) From() common.Address { return common.Address{} }

func (*NoOp) ExecuteTransactions(context.Context, *txbuilder.Builder, common.Address) (*types.Transaction, error) {
return nil, errors.New("no op validator wallet cannot execute transactions")
}

func (*NoOp) TimeoutChallenges(ctx context.Context, challenges []uint64) (*types.Transaction, error) {
return nil, errors.New("no op validator wallet cannot timeout challenges")
}

func (n *NoOp) L1Client() arbutil.L1Interface { return n.l1Client }

func (*NoOp) RollupAddress() common.Address { return common.Address{} }

func (*NoOp) ChallengeManagerAddress() common.Address { return common.Address{} }

func (*NoOp) TestTransactions(ctx context.Context, txs []*types.Transaction) error {
return nil
}

func (*NoOp) CanBatchTxs() bool { return false }

func (*NoOp) AuthIfEoa() *bind.TransactOpts { return nil }

func (w *NoOp) Start(ctx context.Context) {}

func (b *NoOp) StopAndWait() {}

func (b *NoOp) DataPoster() *dataposter.DataPoster { return nil }

0 comments on commit efba003

Please sign in to comment.