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

Remove fast confirmer config #2547

Merged
merged 11 commits into from
Aug 13, 2024
41 changes: 30 additions & 11 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 @@ -91,9 +92,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 @@ -160,9 +160,8 @@ var DefaultL1ValidatorConfig = L1ValidatorConfig{
ExtraGas: 50000,
Dangerous: DefaultDangerousConfig,
ParentChainWallet: DefaultValidatorL1WalletConfig,
EnableFastConfirmation: false,
FastConfirmSafeAddress: "",
LogQueryBatchSize: 0,
EnableFastConfirmation: true,
}

var TestL1ValidatorConfig = L1ValidatorConfig{
Expand All @@ -183,9 +182,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 @@ -216,7 +214,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 @@ -270,6 +267,7 @@ type Staker struct {
statelessBlockValidator *StatelessBlockValidator
fatalErr chan<- error
fastConfirmSafe *FastConfirmSafe
fastConfirmer common.Address
}

type ValidatorWalletInterface interface {
Expand Down Expand Up @@ -320,10 +318,19 @@ func NewStaker(
stakedNotifiers = append(stakedNotifiers, blockValidator)
}
var fastConfirmSafe *FastConfirmSafe
if config.EnableFastConfirmation && config.FastConfirmSafeAddress != "" {
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 {
fastConfirmSafe, err = NewFastConfirmSafe(
callOpts,
common.HexToAddress(config.FastConfirmSafeAddress),
fastConfirmer,
val.builder,
wallet,
config.gasRefunder,
Expand All @@ -332,6 +339,17 @@ func NewStaker(
if err != nil {
return nil, err
amsanghi marked this conversation as resolved.
Show resolved Hide resolved
}
isOwner, err := fastConfirmSafe.safe.IsOwner(&callOpts, wallet.AddressOrZero())
if err != nil {
return nil, 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 {
return a.number < b.number || (a.number == b.number && a.hash.Cmp(b.hash) < 0)
Expand All @@ -349,6 +367,7 @@ func NewStaker(
statelessBlockValidator: statelessBlockValidator,
fatalErr: fatalErr,
fastConfirmSafe: fastConfirmSafe,
fastConfirmer: fastConfirmer,
inactiveValidatedNodes: inactiveValidatedNodes,
}, nil
}
Expand Down Expand Up @@ -383,7 +402,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 @@ -394,7 +413,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
Loading