-
Notifications
You must be signed in to change notification settings - Fork 245
refactor(sequencers): persist prepended batch #2907
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
Changes from 1 commit
2e769b5
98309ec
724c8d8
91518df
b6895e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -720,4 +720,53 @@ func TestBatchQueue_Prepend(t *testing.T) { | |
| require.NoError(t, err) | ||
| assert.Equal(t, []byte("tx1"), nextBatch.Transactions[0]) | ||
| }) | ||
|
|
||
| t.Run("prepend persistence across restarts", func(t *testing.T) { | ||
| prefix := "test-prepend-persistence" | ||
| queue := NewBatchQueue(db, prefix, 0) | ||
| err := queue.Load(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Add some batches | ||
| batch1 := coresequencer.Batch{Transactions: [][]byte{[]byte("tx1")}} | ||
| batch2 := coresequencer.Batch{Transactions: [][]byte{[]byte("tx2")}} | ||
| err = queue.AddBatch(ctx, batch1) | ||
| require.NoError(t, err) | ||
| err = queue.AddBatch(ctx, batch2) | ||
| require.NoError(t, err) | ||
|
|
||
| // Consume first batch | ||
| _, err = queue.Next(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Prepend a batch (simulating transactions that couldn't fit) | ||
| prependedBatch := coresequencer.Batch{Transactions: [][]byte{[]byte("prepended")}} | ||
| err = queue.Prepend(ctx, prependedBatch) | ||
| require.NoError(t, err) | ||
|
|
||
| assert.Equal(t, 2, queue.Size()) | ||
|
|
||
| // Simulate restart by creating a new queue with same prefix | ||
| queue2 := NewBatchQueue(db, prefix, 0) | ||
| err = queue2.Load(ctx) | ||
| require.NoError(t, err) | ||
|
|
||
| // Should have both the prepended batch and tx2 | ||
| assert.Equal(t, 2, queue2.Size()) | ||
|
|
||
| // First should be prepended batch | ||
| nextBatch, err := queue2.Next(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 1, len(nextBatch.Transactions)) | ||
| assert.Equal(t, []byte("prepended"), nextBatch.Transactions[0]) | ||
|
|
||
| // Then tx2 | ||
| nextBatch, err = queue2.Next(ctx) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, 1, len(nextBatch.Transactions)) | ||
| assert.Equal(t, []byte("tx2"), nextBatch.Transactions[0]) | ||
|
||
|
|
||
| // Queue should be empty now | ||
| assert.Equal(t, 0, queue2.Size()) | ||
| }) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prepend does not check for max queue size. It makes sense for me to grow beyond the limit to get the high priority TX included. Nevertheless, some doc would be good to manage expectations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
91518df