Skip to content

Commit 495c621

Browse files
authored
feat(pkg/sequencers): add queue limit in solo sequencer (#3312)
* feat(pkg/sequencers): add queue limit in solo sequencer * use option * cl * move test files
1 parent 264314f commit 495c621

9 files changed

Lines changed: 215 additions & 46 deletions

File tree

.mockery.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ packages:
9797
interfaces:
9898
ForcedInclusionRetriever:
9999
config:
100-
dir: ./pkg/sequencers/common
101-
pkgname: common
100+
dir: ./pkg/sequencers/based
101+
pkgname: based
102102
filename: forced_inclusion_retriever_mock.go

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changes
1313

14+
- Add max bytes contraints in simple solo sequnecer [#3312](https://github.com/evstack/ev-node/pull/3312)
1415
- Add support for otlp in execution/grpc. [#3300](https://github.com/evstack/ev-node/pull/3300)
1516
- Optimization of mutex usage in cache for reaper [#3286](https://github.com/evstack/ev-node/pull/3286)
1617
- Add Unix domain socket support for gRPC execution endpoints via `unix:///path/to/socket` [#3297](https://github.com/evstack/ev-node/pull/3297)

pkg/sequencers/common/forced_inclusion_retriever_mock.go renamed to pkg/sequencers/based/forced_inclusion_retriever_mock.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/sequencers/based/sequencer_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/evstack/ev-node/pkg/config"
1919
datypes "github.com/evstack/ev-node/pkg/da/types"
2020
"github.com/evstack/ev-node/pkg/genesis"
21-
"github.com/evstack/ev-node/pkg/sequencers/common"
2221
"github.com/evstack/ev-node/test/mocks"
2322
)
2423

@@ -62,7 +61,7 @@ type testData struct {
6261
cancel context.CancelFunc
6362
}
6463

65-
func createTestSequencer(t *testing.T, mockRetriever *common.MockForcedInclusionRetriever, gen genesis.Genesis) (*BasedSequencer, testData) {
64+
func createTestSequencer(t *testing.T, mockRetriever *MockForcedInclusionRetriever, gen genesis.Genesis) (*BasedSequencer, testData) {
6665
t.Helper()
6766

6867
// Create in-memory datastore
@@ -95,7 +94,7 @@ func createTestSequencer(t *testing.T, mockRetriever *common.MockForcedInclusion
9594
}
9695

9796
func TestBasedSequencer_SubmitBatchTxs(t *testing.T) {
98-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
97+
mockRetriever := NewMockForcedInclusionRetriever(t)
9998
gen := genesis.Genesis{
10099
ChainID: "test-chain",
101100
DAEpochForcedInclusion: 10,
@@ -122,7 +121,7 @@ func TestBasedSequencer_SubmitBatchTxs(t *testing.T) {
122121
func TestBasedSequencer_GetNextBatch_WithForcedTxs(t *testing.T) {
123122
testBlobs := [][]byte{[]byte("tx1"), []byte("tx2")}
124123

125-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
124+
mockRetriever := NewMockForcedInclusionRetriever(t)
126125
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
127126
Txs: testBlobs,
128127
StartDaHeight: 100,
@@ -158,7 +157,7 @@ func TestBasedSequencer_GetNextBatch_WithForcedTxs(t *testing.T) {
158157
}
159158

160159
func TestBasedSequencer_GetNextBatch_EmptyDA(t *testing.T) {
161-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
160+
mockRetriever := NewMockForcedInclusionRetriever(t)
162161
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
163162
Txs: [][]byte{},
164163
StartDaHeight: 100,
@@ -189,7 +188,7 @@ func TestBasedSequencer_GetNextBatch_EmptyDA(t *testing.T) {
189188
}
190189

191190
func TestBasedSequencer_GetNextBatch_NotConfigured(t *testing.T) {
192-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
191+
mockRetriever := NewMockForcedInclusionRetriever(t)
193192
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(nil, block.ErrForceInclusionNotConfigured)
194193

195194
gen := genesis.Genesis{
@@ -219,7 +218,7 @@ func TestBasedSequencer_GetNextBatch_WithMaxBytes(t *testing.T) {
219218
tx3 := make([]byte, 200)
220219
testBlobs := [][]byte{tx1, tx2, tx3}
221220

222-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
221+
mockRetriever := NewMockForcedInclusionRetriever(t)
223222
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
224223
Txs: testBlobs,
225224
StartDaHeight: 100,
@@ -274,7 +273,7 @@ func TestBasedSequencer_GetNextBatch_MultipleDABlocks(t *testing.T) {
274273
testBlobs1 := [][]byte{[]byte("tx1"), []byte("tx2")}
275274
testBlobs2 := [][]byte{[]byte("tx3"), []byte("tx4")}
276275

277-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
276+
mockRetriever := NewMockForcedInclusionRetriever(t)
278277
// First DA block
279278
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
280279
Txs: testBlobs1,
@@ -327,7 +326,7 @@ func TestBasedSequencer_GetNextBatch_ForcedInclusionExceedsMaxBytes(t *testing.T
327326
largeTx := make([]byte, 2000)
328327
testBlobs := [][]byte{largeTx}
329328

330-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
329+
mockRetriever := NewMockForcedInclusionRetriever(t)
331330
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
332331
Txs: testBlobs,
333332
StartDaHeight: 100,
@@ -358,7 +357,7 @@ func TestBasedSequencer_GetNextBatch_ForcedInclusionExceedsMaxBytes(t *testing.T
358357
}
359358

360359
func TestBasedSequencer_VerifyBatch(t *testing.T) {
361-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
360+
mockRetriever := NewMockForcedInclusionRetriever(t)
362361
gen := genesis.Genesis{
363362
ChainID: "test-chain",
364363
DAEpochForcedInclusion: 10,
@@ -379,7 +378,7 @@ func TestBasedSequencer_VerifyBatch(t *testing.T) {
379378
}
380379

381380
func TestBasedSequencer_SetDAHeight(t *testing.T) {
382-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
381+
mockRetriever := NewMockForcedInclusionRetriever(t)
383382
gen := genesis.Genesis{
384383
ChainID: "test-chain",
385384
DAStartHeight: 100,
@@ -397,7 +396,7 @@ func TestBasedSequencer_SetDAHeight(t *testing.T) {
397396
}
398397

399398
func TestBasedSequencer_GetNextBatch_ErrorHandling(t *testing.T) {
400-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
399+
mockRetriever := NewMockForcedInclusionRetriever(t)
401400
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(nil, block.ErrForceInclusionNotConfigured)
402401

403402
gen := genesis.Genesis{
@@ -421,7 +420,7 @@ func TestBasedSequencer_GetNextBatch_ErrorHandling(t *testing.T) {
421420
}
422421

423422
func TestBasedSequencer_GetNextBatch_HeightFromFuture(t *testing.T) {
424-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
423+
mockRetriever := NewMockForcedInclusionRetriever(t)
425424
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(nil, datypes.ErrHeightFromFuture)
426425

427426
gen := genesis.Genesis{
@@ -450,7 +449,7 @@ func TestBasedSequencer_GetNextBatch_HeightFromFuture(t *testing.T) {
450449
func TestBasedSequencer_CheckpointPersistence(t *testing.T) {
451450
testBlobs := [][]byte{[]byte("tx1"), []byte("tx2")}
452451

453-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
452+
mockRetriever := NewMockForcedInclusionRetriever(t)
454453
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
455454
Txs: testBlobs,
456455
StartDaHeight: 100,
@@ -525,7 +524,7 @@ func TestBasedSequencer_CrashRecoveryMidEpoch(t *testing.T) {
525524

526525
testBlobs := [][]byte{[]byte("tx0"), []byte("tx1"), []byte("tx2"), []byte("tx3"), []byte("tx4")}
527526

528-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
527+
mockRetriever := NewMockForcedInclusionRetriever(t)
529528
// The epoch will be fetched twice: once before crash, once after restart
530529
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
531530
Txs: testBlobs,
@@ -650,7 +649,7 @@ func TestBasedSequencer_CrashRecoveryMidEpoch(t *testing.T) {
650649
}
651650

652651
func TestBasedSequencer_GetNextBatch_EmptyDABatch_IncreasesDAHeight(t *testing.T) {
653-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
652+
mockRetriever := NewMockForcedInclusionRetriever(t)
654653

655654
// First DA block returns empty transactions
656655
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
@@ -715,7 +714,7 @@ func TestBasedSequencer_GetNextBatch_TimestampAdjustment(t *testing.T) {
715714
testBlobs := [][]byte{[]byte("tx1"), []byte("tx2"), []byte("tx3")}
716715
daEndTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
717716

718-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
717+
mockRetriever := NewMockForcedInclusionRetriever(t)
719718
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
720719
Txs: testBlobs,
721720
StartDaHeight: 100,
@@ -759,7 +758,7 @@ func TestBasedSequencer_GetNextBatch_TimestampAdjustment_PartialBatch(t *testing
759758
testBlobs := [][]byte{tx1, tx2, tx3}
760759
daEndTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
761760

762-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
761+
mockRetriever := NewMockForcedInclusionRetriever(t)
763762
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
764763
Txs: testBlobs,
765764
StartDaHeight: 100,
@@ -817,7 +816,7 @@ func TestBasedSequencer_GetNextBatch_TimestampAdjustment_EmptyBatch(t *testing.T
817816
// The checkpoint must still advance past the empty epoch.
818817
daEndTime := time.Date(2024, 1, 1, 12, 0, 0, 0, time.UTC)
819818

820-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
819+
mockRetriever := NewMockForcedInclusionRetriever(t)
821820
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
822821
Txs: [][]byte{},
823822
StartDaHeight: 100,
@@ -869,7 +868,7 @@ func TestBasedSequencer_GetNextBatch_GasFilteringPreservesUnprocessedTxs(t *test
869868

870869
testBlobs := [][]byte{tx0, tx1, tx2, tx3, tx4}
871870

872-
mockRetriever := common.NewMockForcedInclusionRetriever(t)
871+
mockRetriever := NewMockForcedInclusionRetriever(t)
873872
// Only expect one call to retrieve - all txs come from one DA epoch
874873
mockRetriever.On("RetrieveForcedIncludedTxs", mock.Anything, uint64(100)).Return(&block.ForcedInclusionEvent{
875874
Txs: testBlobs,
@@ -988,7 +987,7 @@ func TestBasedSequencer_GetNextBatch_GasFilteringPreservesUnprocessedTxs(t *test
988987
assert.GreaterOrEqual(t, totalTxsProcessed, 3, "should process at least 3 valid transactions from the cache")
989988
}
990989

991-
func replaceWithMockRetriever(seq *BasedSequencer, mockRetriever *common.MockForcedInclusionRetriever) {
990+
func replaceWithMockRetriever(seq *BasedSequencer, mockRetriever *MockForcedInclusionRetriever) {
992991
if seq.fiRetriever != nil {
993992
seq.fiRetriever.Stop()
994993
}

pkg/sequencers/common/errors.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package common
2+
3+
import "errors"
4+
5+
var (
6+
// ErrInvalidId is returned when the chain id is invalid
7+
ErrInvalidID = errors.New("invalid chain id")
8+
// ErrQueueFull is returned when the batch queue has reached its maximum size
9+
ErrQueueFull = errors.New("sequencer queue full")
10+
)

pkg/sequencers/single/queue.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/binary"
66
"encoding/hex"
7-
"errors"
87
"fmt"
98
"strconv"
109
"sync"
@@ -14,12 +13,12 @@ import (
1413
"google.golang.org/protobuf/proto"
1514

1615
coresequencer "github.com/evstack/ev-node/core/sequencer"
16+
"github.com/evstack/ev-node/pkg/sequencers/common"
1717
"github.com/evstack/ev-node/pkg/store"
1818
pb "github.com/evstack/ev-node/types/pb/evnode/v1"
1919
)
2020

21-
// ErrQueueFull is returned when the batch queue has reached its maximum size
22-
var ErrQueueFull = errors.New("batch queue is full")
21+
var ErrQueueFull = common.ErrQueueFull
2322

2423
// initialSeqNum is the starting sequence number for new queues.
2524
// It is set to the middle of the uint64 range to allow for both

pkg/sequencers/single/sequencer.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import (
2424
"github.com/evstack/ev-node/types"
2525
)
2626

27-
// ErrInvalidId is returned when the chain id is invalid
28-
var ErrInvalidId = errors.New("invalid chain id")
27+
var ErrInvalidId = seqcommon.ErrInvalidID
2928

3029
// Catch-up state machine states
3130
const (

0 commit comments

Comments
 (0)