Skip to content

Commit

Permalink
Merge branch 'master' into bold-review
Browse files Browse the repository at this point in the history
  • Loading branch information
amsanghi committed Aug 14, 2024
2 parents 8446078 + 3031234 commit 66bc44c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 32 deletions.
27 changes: 25 additions & 2 deletions scripts/split-val-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,36 @@

xxd -l 32 -ps -c 40 /dev/urandom > /tmp/nitro-val.jwt

legacyvalopts=()
latestvalopts=()
while [[ $1 == "--val-options"* ]]; do
setlegacy=true
setlatest=true
if [[ $1 == "--val-options-legacy" ]]; then
setlatest=false
fi
if [[ $1 == "--val-options-latest" ]]; then
setlegacy=false
fi
shift
while [[ "$1" != "--" ]] && [[ $# -gt 0 ]]; do
if $setlegacy; then
legacyvalopts=( "${legacyvalopts[@]}" "$1" )
fi
if $setlatest; then
latestvalopts=( "${latestvalopts[@]}" "$1" )
fi
shift
done
shift
done
echo launching validation servers
# To add validation server:
# > launch them here with a different port and --validation.wasm.root-path
# add their port to wait loop
# edit validation-server-configs-list to include the other nodes
/usr/local/bin/nitro-val --file-logging.enable=false --auth.addr 127.0.0.10 --auth.origins 127.0.0.1 --auth.jwtsecret /tmp/nitro-val.jwt --auth.port 52000 &
/home/user/nitro-legacy/bin/nitro-val --file-logging.enable=false --auth.addr 127.0.0.10 --auth.origins 127.0.0.1 --auth.jwtsecret /tmp/nitro-val.jwt --auth.port 52001 --validation.wasm.root-path /home/user/nitro-legacy/machines &
/usr/local/bin/nitro-val --file-logging.enable=false --auth.addr 127.0.0.10 --auth.origins 127.0.0.1 --auth.jwtsecret /tmp/nitro-val.jwt --auth.port 52000 "${latestvalopts[@]}" &
/home/user/nitro-legacy/bin/nitro-val --file-logging.enable=false --auth.addr 127.0.0.10 --auth.origins 127.0.0.1 --auth.jwtsecret /tmp/nitro-val.jwt --auth.port 52001 --validation.wasm.root-path /home/user/nitro-legacy/machines "${legacyvalopts[@]}" &
for port in 52000 52001; do
while ! nc -w1 -z 127.0.0.10 $port; do
echo waiting for validation port $port
Expand Down
76 changes: 57 additions & 19 deletions staker/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/offchainlabs/nitro/arbnode/dataposter"
"github.com/offchainlabs/nitro/arbutil"
"github.com/offchainlabs/nitro/cmd/genericconf"
"github.com/offchainlabs/nitro/solgen/go/rollupgen"
"github.com/offchainlabs/nitro/staker/txbuilder"
"github.com/offchainlabs/nitro/util"
"github.com/offchainlabs/nitro/util/arbmath"
Expand Down Expand Up @@ -92,9 +93,8 @@ type L1ValidatorConfig struct {
ExtraGas uint64 `koanf:"extra-gas" reload:"hot"`
Dangerous DangerousConfig `koanf:"dangerous"`
ParentChainWallet genericconf.WalletConfig `koanf:"parent-chain-wallet"`
EnableFastConfirmation bool `koanf:"enable-fast-confirmation"`
FastConfirmSafeAddress string `koanf:"fast-confirm-safe-address"`
LogQueryBatchSize uint64 `koanf:"log-query-batch-size" reload:"hot"`
EnableFastConfirmation bool `koanf:"enable-fast-confirmation"`

strategy StakerStrategy
gasRefunder common.Address
Expand Down Expand Up @@ -162,9 +162,8 @@ var DefaultL1ValidatorConfig = L1ValidatorConfig{
ExtraGas: 50000,
Dangerous: DefaultDangerousConfig,
ParentChainWallet: DefaultValidatorL1WalletConfig,
EnableFastConfirmation: false,
FastConfirmSafeAddress: "",
LogQueryBatchSize: 0,
EnableFastConfirmation: true,
}

var TestL1ValidatorConfig = L1ValidatorConfig{
Expand All @@ -186,9 +185,8 @@ var TestL1ValidatorConfig = L1ValidatorConfig{
ExtraGas: 50000,
Dangerous: DefaultDangerousConfig,
ParentChainWallet: DefaultValidatorL1WalletConfig,
EnableFastConfirmation: false,
FastConfirmSafeAddress: "",
LogQueryBatchSize: 0,
EnableFastConfirmation: true,
}

var DefaultValidatorL1WalletConfig = genericconf.WalletConfig{
Expand Down Expand Up @@ -220,7 +218,6 @@ func L1ValidatorConfigAddOptions(prefix string, f *flag.FlagSet) {
DangerousConfigAddOptions(prefix+".dangerous", f)
genericconf.WalletConfigAddOptions(prefix+".parent-chain-wallet", f, DefaultL1ValidatorConfig.ParentChainWallet.Pathname)
f.Bool(prefix+".enable-fast-confirmation", DefaultL1ValidatorConfig.EnableFastConfirmation, "enable fast confirmation")
f.String(prefix+".fast-confirm-safe-address", DefaultL1ValidatorConfig.FastConfirmSafeAddress, "safe address for fast confirmation")
}

type DangerousConfig struct {
Expand Down Expand Up @@ -274,6 +271,7 @@ type Staker struct {
statelessBlockValidator *StatelessBlockValidator
fatalErr chan<- error
fastConfirmSafe *FastConfirmSafe
fastConfirmer common.Address
}

type ValidatorWalletInterface interface {
Expand Down Expand Up @@ -324,17 +322,56 @@ func NewStaker(
stakedNotifiers = append(stakedNotifiers, blockValidator)
}
var fastConfirmSafe *FastConfirmSafe
if config.EnableFastConfirmation && config.FastConfirmSafeAddress != "" {
fastConfirmSafe, err = NewFastConfirmSafe(
callOpts,
common.HexToAddress(config.FastConfirmSafeAddress),
val.builder,
wallet,
config.gasRefunder,
l1Reader,
)
rollup, err := rollupgen.NewRollupUserLogic(wallet.RollupAddress(), l1Reader.Client())
if err != nil {
return nil, err
}
fastConfirmer, err := rollup.AnyTrustFastConfirmer(&bind.CallOpts{})
if err != nil {
return nil, err
}
// Only use gnosis safe fast confirmation, if the safe address is different from the wallet address, else it's not a safe contract.
if fastConfirmer != (common.Address{}) && config.EnableFastConfirmation && wallet.AddressOrZero() != (common.Address{}) && wallet.AddressOrZero() != fastConfirmer {
codeAt, err := client.CodeAt(context.Background(), fastConfirmer, nil)
if err != nil {
return nil, err
return nil, fmt.Errorf("getting code at fast confirmer address: %w", err)
}
if len(codeAt) == 0 {
// The fast confirmer address is an EOA address, but it does not match the wallet address so cannot enable fast confirmation.
fastConfirmer = common.Address{}
log.Info("Fast confirmer address is an EOA address which does not match the wallet address so cannot enable fast confirmation", "fastConfirmer", fastConfirmer, "wallet", wallet.AddressOrZero())
} else {
// The fast confirmer address is a contract address, not sure if it's a safe contract yet.
fastConfirmSafe, err = NewFastConfirmSafe(
callOpts,
fastConfirmer,
val.builder,
wallet,
config.gasRefunder,
l1Reader,
)
if err != nil && headerreader.ExecutionRevertedRegexp.MatchString(err.Error()) {
// If the safe is not a safe contract, we can't use it for fast confirmation
fastConfirmer = common.Address{}
fastConfirmSafe = nil
log.Warn("Fast confirmer address is not a safe contract so cannot enable fast confirmation", "fastConfirmer", fastConfirmer, "wallet", wallet.AddressOrZero())
} else if err != nil {
// Unknown while loading the safe contract.
return nil, fmt.Errorf("loading fast confirm safe: %w", err)
} else {
// Fast confirmer address is a safe contract.
isOwner, err := fastConfirmSafe.safe.IsOwner(&callOpts, wallet.AddressOrZero())
if err != nil {
return nil, fmt.Errorf("checking if wallet is owner of safe: %w", err)
}
if !isOwner {
// If the wallet is not an owner of the safe, we can't use it for fast confirmation
// So disable fast confirmation.
fastConfirmer = common.Address{}
fastConfirmSafe = nil
log.Info("Staker wallet address is not part of owners of safe so cannot use it for fast confirmation", "fastConfirmer", fastConfirmer, "wallet", wallet.AddressOrZero())
}
}
}
}
inactiveValidatedNodes := btree.NewG(2, func(a, b validatedNode) bool {
Expand All @@ -353,6 +390,7 @@ func NewStaker(
statelessBlockValidator: statelessBlockValidator,
fatalErr: fatalErr,
fastConfirmSafe: fastConfirmSafe,
fastConfirmer: fastConfirmer,
inactiveValidatedNodes: inactiveValidatedNodes,
}, nil
}
Expand Down Expand Up @@ -387,7 +425,7 @@ func (s *Staker) Initialize(ctx context.Context) error {
}

func (s *Staker) tryFastConfirmationNodeNumber(ctx context.Context, number uint64, hash common.Hash) error {
if !s.config.EnableFastConfirmation {
if s.fastConfirmer == (common.Address{}) || !s.config.EnableFastConfirmation {
return nil
}
nodeInfo, err := s.rollup.LookupNode(ctx, number)
Expand All @@ -398,7 +436,7 @@ func (s *Staker) tryFastConfirmationNodeNumber(ctx context.Context, number uint6
}

func (s *Staker) tryFastConfirmation(ctx context.Context, blockHash common.Hash, sendRoot common.Hash, nodeHash common.Hash) error {
if !s.config.EnableFastConfirmation {
if s.fastConfirmer == (common.Address{}) || !s.config.EnableFastConfirmation {
return nil
}
if s.fastConfirmSafe != nil {
Expand Down
17 changes: 6 additions & 11 deletions system_tests/fast_confirm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestFastConfirmation(t *testing.T) {
Require(t, err)

valConfig := staker.TestL1ValidatorConfig
valConfig.EnableFastConfirmation = true
parentChainID, err := builder.L1.Client.ChainID(ctx)
if err != nil {
t.Fatalf("Failed to get parent chain id: %v", err)
Expand Down Expand Up @@ -158,6 +157,8 @@ func TestFastConfirmation(t *testing.T) {
Require(t, err)
err = stateless.Start(ctx)
Require(t, err)
err = valWallet.Initialize(ctx)
Require(t, err)
stakerA, err := staker.NewStaker(
l2node.L1Reader,
valWallet,
Expand All @@ -172,10 +173,6 @@ func TestFastConfirmation(t *testing.T) {
)
Require(t, err)
err = stakerA.Initialize(ctx)
if stakerA.Strategy() != staker.WatchtowerStrategy {
err = valWallet.Initialize(ctx)
Require(t, err)
}
Require(t, err)
cfg := arbnode.ConfigDefaultL1NonSequencerTest()
signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL())
Expand Down Expand Up @@ -324,8 +321,6 @@ func TestFastConfirmationWithSafe(t *testing.T) {
Require(t, err)

valConfig := staker.TestL1ValidatorConfig
valConfig.EnableFastConfirmation = true
valConfig.FastConfirmSafeAddress = safeAddress.String()

parentChainID, err := builder.L1.Client.ChainID(ctx)
if err != nil {
Expand Down Expand Up @@ -362,6 +357,8 @@ func TestFastConfirmationWithSafe(t *testing.T) {
Require(t, err)
err = statelessA.Start(ctx)
Require(t, err)
err = valWalletA.Initialize(ctx)
Require(t, err)
stakerA, err := staker.NewStaker(
l2nodeA.L1Reader,
valWalletA,
Expand All @@ -377,8 +374,6 @@ func TestFastConfirmationWithSafe(t *testing.T) {
Require(t, err)
err = stakerA.Initialize(ctx)
Require(t, err)
err = valWalletA.Initialize(ctx)
Require(t, err)
cfg := arbnode.ConfigDefaultL1NonSequencerTest()
signerCfg, err := externalSignerTestCfg(srv.Address, srv.URL())
if err != nil {
Expand Down Expand Up @@ -412,6 +407,8 @@ func TestFastConfirmationWithSafe(t *testing.T) {
Require(t, err)
err = statelessB.Start(ctx)
Require(t, err)
err = valWalletB.Initialize(ctx)
Require(t, err)
stakerB, err := staker.NewStaker(
l2nodeB.L1Reader,
valWalletB,
Expand All @@ -427,8 +424,6 @@ func TestFastConfirmationWithSafe(t *testing.T) {
Require(t, err)
err = stakerB.Initialize(ctx)
Require(t, err)
err = valWalletB.Initialize(ctx)
Require(t, err)

builder.L2Info.GenerateAccount("BackgroundUser")
tx = builder.L2Info.PrepareTx("Faucet", "BackgroundUser", builder.L2Info.TransferGas, balance, nil)
Expand Down

0 comments on commit 66bc44c

Please sign in to comment.