Skip to content

Commit

Permalink
rename the flag and if escape hatch is not used, not to check the hot…
Browse files Browse the repository at this point in the history
…shot livenesses
  • Loading branch information
ImJeremyHe committed Dec 19, 2024
1 parent 84e60ac commit 93bf394
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
4 changes: 2 additions & 2 deletions arbnode/batch_poster.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (b *BatchPoster) checkEspressoValidation() error {
return nil
}

if b.streamer.UseEscapeHatch && b.streamer.EnableEscapeHatch {
if b.streamer.UseEscapeHatch {
skip, err := b.streamer.getSkipVerificationPos()
if err != nil {
log.Error("failed call to get skip verification pos", "err", err)
Expand All @@ -599,7 +599,7 @@ func (b *BatchPoster) checkEspressoValidation() error {
}
}

if b.streamer.UseEscapeHatch && b.streamer.HotshotDown && b.streamer.EnableEscapeHatch {
if b.streamer.EnableEscapeHatch {
log.Warn("skipped espresso verification due to hotshot failure", "pos", b.building.msgCount)
return nil
}
Expand Down
58 changes: 26 additions & 32 deletions arbnode/transaction_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type TransactionStreamer struct {
espressoSwitchDelayThreshold uint64
espressoMaxTransactionSize uint64
// Public these fields for testing
HotshotDown bool
EnableEscapeHatch bool
UseEscapeHatch bool

Expand Down Expand Up @@ -1347,7 +1346,7 @@ func (s *TransactionStreamer) pollSubmittedTransactionForFinality(ctx context.Co

batch := s.db.NewBatch()
if err := s.cleanEspressoSubmittedData(batch); err != nil {
return nil
return err
}
lastConfirmedPos := submittedTxnPos[len(submittedTxnPos)-1]
if err := s.setEspressoLastConfirmedPos(batch, &lastConfirmedPos); err != nil {
Expand Down Expand Up @@ -1709,30 +1708,28 @@ func (s *TransactionStreamer) submitEspressoTransactions(ctx context.Context) ti
return s.espressoTxnsPollingInterval
}

// Make sure useEscapeHatch is true
func (s *TransactionStreamer) checkEspressoLiveness(ctx context.Context) error {
live, err := s.lightClientReader.IsHotShotLive(s.espressoSwitchDelayThreshold)
if err != nil {
return err
}
// If hotshot is down, escape hatch is activated, the only thing is to check if hotshot is live again
if s.HotshotDown {
// If escape hatch is acitivated, the only thing is to check if hotshot is live again
if s.EnableEscapeHatch {
if live {
log.Info("HotShot is up, disabling the escape hatch")
s.HotshotDown = false
s.EnableEscapeHatch = false
}
return nil
}

// If hotshot was previously up, now it is down
if !live {
log.Warn("enabling the escape hatch, hotshot is down")
s.HotshotDown = true
}

if s.UseEscapeHatch && !s.EnableEscapeHatch {
return nil
s.EnableEscapeHatch = true
}

// Check if the submitted transaction should skip the espresso verification
submittedHash, err := s.getEspressoSubmittedHash()
if err != nil {
return err
Expand Down Expand Up @@ -1810,9 +1807,8 @@ func getLogLevel(err error) func(string, ...interface{}) {

func (s *TransactionStreamer) espressoSwitch(ctx context.Context, ignored struct{}) time.Duration {
retryRate := s.espressoTxnsPollingInterval * 50
enabledEspresso := s.espressoTEEVerifierAddress != common.Address{}
if enabledEspresso {
var err error
var err error
if s.UseEscapeHatch {
err = s.checkEspressoLiveness(ctx)
if err != nil {
if ctx.Err() != nil {
Expand All @@ -1822,31 +1818,29 @@ func (s *TransactionStreamer) espressoSwitch(ctx context.Context, ignored struct
logLevel("error checking escape hatch, will retry", "err", err)
return retryRate
}
err = s.pollSubmittedTransactionForFinality(ctx)
if err != nil {
if ctx.Err() != nil {
return 0
}
logLevel := getLogLevel(err)
logLevel("error polling finality, will retry", "err", err)
return retryRate
} else {
espressoMerkleProofEphemeralErrorHandler.Reset()
}

shouldSubmit := s.shouldSubmitEspressoTransaction()
if shouldSubmit {
return s.submitEspressoTransactions(ctx)
espressoTransactionEphemeralErrorHandler.Reset()
}
err = s.pollSubmittedTransactionForFinality(ctx)
if err != nil {
if ctx.Err() != nil {
return 0
}

return s.espressoTxnsPollingInterval
} else {
logLevel := getLogLevel(err)
logLevel("error polling finality, will retry", "err", err)
return retryRate
}
espressoMerkleProofEphemeralErrorHandler.Reset()

shouldSubmit := s.shouldSubmitEspressoTransaction()
if shouldSubmit {
return s.submitEspressoTransactions(ctx)
}

return s.espressoTxnsPollingInterval
}

func (s *TransactionStreamer) shouldSubmitEspressoTransaction() bool {
return !s.HotshotDown
return !(s.UseEscapeHatch && s.EnableEscapeHatch)
}

func (s *TransactionStreamer) Start(ctxIn context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions system_tests/espresso_escape_hatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestEspressoEscapeHatch(t *testing.T) {
log.Info("waiting for light client to report hotshot is down")
err = waitForWith(ctx, 10*time.Minute, 10*time.Second, func() bool {
log.Info("waiting for hotshot down")
return builder.L2.ConsensusNode.TxStreamer.HotshotDown
return builder.L2.ConsensusNode.TxStreamer.EnableEscapeHatch
})
Require(t, err)

Expand Down Expand Up @@ -122,7 +122,7 @@ func TestEspressoEscapeHatch(t *testing.T) {

err = waitForWith(ctx, 10*time.Minute, 10*time.Second, func() bool {
log.Info("waiting for hotshot down")
return builder.L2.ConsensusNode.TxStreamer.HotshotDown
return builder.L2.ConsensusNode.TxStreamer.EnableEscapeHatch
})
Require(t, err)

Expand Down

0 comments on commit 93bf394

Please sign in to comment.