Skip to content

Commit

Permalink
Merge pull request #2668 from OffchainLabs/fix-setup-fast-confs-not-c…
Browse files Browse the repository at this point in the history
…alled

Fix setupFastConfirmation not getting called
  • Loading branch information
PlasmaPower authored Sep 13, 2024
2 parents 53d46ef + a68d3b8 commit bf1fe94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions staker/fast_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ func (f *FastConfirmSafe) tryFastConfirmation(ctx context.Context, blockHash com
return err
}
if alreadyApproved.Cmp(common.Big1) == 0 {
log.Info("Already approved Safe tx hash for fast confirmation, checking if we can execute the Safe tx", "safeHash", safeTxHash, "nodeHash", nodeHash)
_, err = f.checkApprovedHashAndExecTransaction(ctx, fastConfirmCallData, safeTxHash)
return err
}

log.Info("Approving Safe tx hash to fast confirm", "safeHash", safeTxHash, "nodeHash", nodeHash)
auth, err := f.builder.Auth(ctx)
if err != nil {
return err
Expand Down Expand Up @@ -231,6 +233,7 @@ func (f *FastConfirmSafe) checkApprovedHashAndExecTransaction(ctx context.Contex
if err != nil {
return false, err
}
log.Info("Executing Safe tx to fast confirm", "safeHash", safeTxHash)
_, err = f.safe.ExecTransaction(
auth,
f.wallet.RollupAddress(),
Expand All @@ -249,5 +252,6 @@ func (f *FastConfirmSafe) checkApprovedHashAndExecTransaction(ctx context.Contex
}
return true, nil
}
log.Info("Not enough Safe tx approvals yet to fast confirm", "safeHash", safeTxHash)
return false, nil
}
16 changes: 9 additions & 7 deletions staker/staker.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ type Staker struct {
inboxReader InboxReaderInterface
statelessBlockValidator *StatelessBlockValidator
fatalErr chan<- error
enableFastConfirmation bool
fastConfirmSafe *FastConfirmSafe
}

Expand Down Expand Up @@ -363,7 +362,10 @@ func (s *Staker) Initialize(ctx context.Context) error {
return err
}

return s.blockValidator.InitAssumeValid(stakedInfo.AfterState().GlobalState)
err = s.blockValidator.InitAssumeValid(stakedInfo.AfterState().GlobalState)
if err != nil {
return err
}
}
return s.setupFastConfirmation(ctx)
}
Expand All @@ -390,9 +392,9 @@ func (s *Staker) setupFastConfirmation(ctx context.Context) error {
if err != nil {
return fmt.Errorf("getting rollup fast confirmer address: %w", err)
}
log.Info("Setting up fast confirmation", "wallet", walletAddress, "fastConfirmer", fastConfirmer)
if fastConfirmer == walletAddress {
// We can directly fast confirm nodes
s.enableFastConfirmation = true
return nil
} else if fastConfirmer == (common.Address{}) {
// No fast confirmer enabled
Expand All @@ -419,13 +421,12 @@ func (s *Staker) setupFastConfirmation(ctx context.Context) error {
if !isOwner {
return fmt.Errorf("staker wallet address %v is not an owner of the fast confirm safe %v", walletAddress, fastConfirmer)
}
s.enableFastConfirmation = true
s.fastConfirmSafe = fastConfirmSafe
return nil
}

func (s *Staker) tryFastConfirmationNodeNumber(ctx context.Context, number uint64, hash common.Hash) error {
if !s.enableFastConfirmation {
if !s.config().EnableFastConfirmation {
return nil
}
nodeInfo, err := s.rollup.LookupNode(ctx, number)
Expand All @@ -436,7 +437,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.enableFastConfirmation {
if !s.config().EnableFastConfirmation {
return nil
}
if s.fastConfirmSafe != nil {
Expand All @@ -446,6 +447,7 @@ func (s *Staker) tryFastConfirmation(ctx context.Context, blockHash common.Hash,
if err != nil {
return err
}
log.Info("Fast confirming node with wallet", "wallet", auth.From, "nodeHash", nodeHash)
_, err = s.rollup.FastConfirmNextNode(auth, blockHash, sendRoot, nodeHash)
return err
}
Expand Down Expand Up @@ -802,13 +804,13 @@ func (s *Staker) Act(ctx context.Context) (*types.Transaction, error) {
confirmedCorrect = stakedOnNode
}
if confirmedCorrect {
log.Info("trying to fast confirm previous node", "node", firstUnresolvedNode, "nodeHash", nodeInfo.NodeHash)
err = s.tryFastConfirmationNodeNumber(ctx, firstUnresolvedNode, nodeInfo.NodeHash)
if err != nil {
return nil, err
}
if s.builder.BuildingTransactionCount() > 0 {
// Try to fast confirm previous nodes before working on new ones
log.Info("fast confirming previous node", "node", firstUnresolvedNode)
return s.wallet.ExecuteTransactions(ctx, s.builder, cfg.gasRefunder)
}
}
Expand Down

0 comments on commit bf1fe94

Please sign in to comment.