Skip to content

Commit

Permalink
[Sequencer] Check if enough time passed to close a sequence (#1509)
Browse files Browse the repository at this point in the history
Closes #1508.

This PR adds a new MinTimeToCloseBatch value in the sequencer configuration. This value is then checked inside shouldCloseDueToNewDeposits against the open sequence timestamp to determine if the sequence can be closed.
  • Loading branch information
kind84 authored Jan 12, 2023
1 parent f79e344 commit 3260e1e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
WaitBlocksToConsiderGerFinal = 10
ElapsedTimeToCloseBatchWithoutTxsDueToNewGER = "60s"
MinTimeToCloseBatch = "60s"
MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
Expand Down
1 change: 1 addition & 0 deletions config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
WaitBlocksToConsiderGerFinal = 10
ElapsedTimeToCloseBatchWithoutTxsDueToNewGER = "60s"
MinTimeToCloseBatch = "60s"
MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
Expand Down
13 changes: 9 additions & 4 deletions sequencer/closingchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ func (s *Sequencer) shouldCloseSequenceInProgress(ctx context.Context) bool {
return false
}

// shouldCloseDueToNewDeposits return true if there has been new deposits on L1 for more than WaitBlocksToUpdateGER
// and the sequence is profitable (if profitability check is enabled)
// shouldCloseDueToNewDeposits return true if there has been new deposits on L1
// for more than WaitBlocksToUpdateGER, enough time has passed since the
// sequence was opened and the sequence is profitable (if profitability check
// is enabled).
func (s *Sequencer) shouldCloseDueToNewDeposits(ctx context.Context) (bool, error) {
lastGer, gerReceivedAt, err := s.getLatestGer(ctx, nil)
if err != nil && err != state.ErrNotFound {
Expand All @@ -56,9 +58,12 @@ func (s *Sequencer) shouldCloseDueToNewDeposits(ctx context.Context) (bool, erro
return false, err
}

sequenceInProgressTimestamp := time.Unix(s.sequenceInProgress.Timestamp, 0)

if latestBlockNumber-blockNum > s.cfg.WaitBlocksToUpdateGER &&
gerReceivedAt.Before(time.Now().Add(-s.cfg.ElapsedTimeToCloseBatchWithoutTxsDueToNewGER.Duration)) {
log.Info("current sequence should be closed because blocks have been mined since last GER")
gerReceivedAt.Before(time.Now().Add(-s.cfg.ElapsedTimeToCloseBatchWithoutTxsDueToNewGER.Duration)) &&
sequenceInProgressTimestamp.Before(time.Now().Add(-s.cfg.MinTimeToCloseBatch.Duration)) {
log.Info("current sequence should be closed because blocks have been mined since last GER and enough time has passed")
return true, nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions sequencer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ type Config struct {
// ElapsedTimeToCloseBatchWithoutTxsDueToNewGER it's time to close a batch bcs new GER appeared
ElapsedTimeToCloseBatchWithoutTxsDueToNewGER types.Duration `mapstructure:"ElapsedTimeToCloseBatchWithoutTxsDueToNewGER"`

// MinTimeToCloseBatch enough time passed to close a batch.
MinTimeToCloseBatch types.Duration `mapstructure:"MinTimeToCloseBatch"`

// MaxTimeForBatchToBeOpen is time after which new batch should be closed
MaxTimeForBatchToBeOpen types.Duration `mapstructure:"MaxTimeForBatchToBeOpen"`

Expand Down
1 change: 1 addition & 0 deletions test/config/debug.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ LastBatchVirtualizationTimeMaxWaitPeriod = "300s"
WaitBlocksToUpdateGER = 10
WaitBlocksToConsiderGerFinal = 10
ElapsedTimeToCloseBatchWithoutTxsDueToNewGER = "60s"
MinTimeToCloseBatch = "60s"
MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
Expand Down
1 change: 1 addition & 0 deletions test/config/test.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ LastBatchVirtualizationTimeMaxWaitPeriod = "10s"
WaitBlocksToUpdateGER = 10
WaitBlocksToConsiderGerFinal = 10
ElapsedTimeToCloseBatchWithoutTxsDueToNewGER = "60s"
MinTimeToCloseBatch = "60s"
MaxTimeForBatchToBeOpen = "15s"
BlocksAmountForTxsToBeDeleted = 100
FrequencyToCheckTxsForDelete = "12h"
Expand Down

0 comments on commit 3260e1e

Please sign in to comment.