Skip to content

Commit ecc55ce

Browse files
committed
fixes
1 parent 09f55ef commit ecc55ce

File tree

7 files changed

+96
-49
lines changed

7 files changed

+96
-49
lines changed

block/components_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func TestExecutor_RealExecutionClientFailure_StopsNode(t *testing.T) {
203203
mockExec.On("InitChain", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
204204
Return([]byte("state-root"), uint64(1024), nil).Once()
205205

206+
// Mock SetDAHeight to be called during initialization
207+
mockSeq.On("SetDAHeight", uint64(0)).Return().Once()
208+
206209
// Mock GetNextBatch to return empty batch
207210
mockSeq.On("GetNextBatch", mock.Anything, mock.Anything).
208211
Return(&coresequencer.GetNextBatchResponse{

block/internal/executing/executor_lazy_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestLazyMode_ProduceBlockLogic(t *testing.T) {
7373
initStateRoot := []byte("init_root")
7474
mockExec.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
7575
Return(initStateRoot, uint64(1024), nil).Once()
76+
mockSeq.EXPECT().SetDAHeight(uint64(0)).Return().Once()
7677
require.NoError(t, exec.initializeState())
7778

7879
// Set up context for the executor (normally done in Start method)
@@ -91,6 +92,8 @@ func TestLazyMode_ProduceBlockLogic(t *testing.T) {
9192
mockExec.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), initStateRoot).
9293
Return([]byte("new_root_1"), uint64(1024), nil).Once()
9394

95+
mockSeq.EXPECT().GetDAHeight().Return(uint64(0)).Once()
96+
9497
// Direct call to produceBlock should work (this is what lazy timer does)
9598
err = exec.produceBlock()
9699
require.NoError(t, err)
@@ -113,6 +116,8 @@ func TestLazyMode_ProduceBlockLogic(t *testing.T) {
113116
mockExec.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(2), mock.AnythingOfType("time.Time"), []byte("new_root_1")).
114117
Return([]byte("new_root_2"), uint64(1024), nil).Once()
115118

119+
mockSeq.EXPECT().GetDAHeight().Return(uint64(0)).Once()
120+
116121
err = exec.produceBlock()
117122
require.NoError(t, err)
118123

@@ -183,6 +188,7 @@ func TestRegularMode_ProduceBlockLogic(t *testing.T) {
183188
initStateRoot := []byte("init_root")
184189
mockExec.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
185190
Return(initStateRoot, uint64(1024), nil).Once()
191+
mockSeq.EXPECT().SetDAHeight(uint64(0)).Return().Once()
186192
require.NoError(t, exec.initializeState())
187193

188194
// Set up context for the executor (normally done in Start method)
@@ -201,6 +207,8 @@ func TestRegularMode_ProduceBlockLogic(t *testing.T) {
201207
mockExec.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), initStateRoot).
202208
Return([]byte("new_root_1"), uint64(1024), nil).Once()
203209

210+
mockSeq.EXPECT().GetDAHeight().Return(uint64(0)).Once()
211+
204212
err = exec.produceBlock()
205213
require.NoError(t, err)
206214

block/internal/executing/executor_logic_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func TestProduceBlock_EmptyBatch_SetsEmptyDataHash(t *testing.T) {
9595
initStateRoot := []byte("init_root")
9696
mockExec.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
9797
Return(initStateRoot, uint64(1024), nil).Once()
98+
mockSeq.EXPECT().SetDAHeight(uint64(0)).Return().Once()
9899

99100
// initialize state (creates genesis block in store and sets state)
100101
require.NoError(t, exec.initializeState())
@@ -113,6 +114,8 @@ func TestProduceBlock_EmptyBatch_SetsEmptyDataHash(t *testing.T) {
113114
mockExec.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), initStateRoot).
114115
Return([]byte("new_root"), uint64(1024), nil).Once()
115116

117+
mockSeq.EXPECT().GetDAHeight().Return(uint64(0)).Once()
118+
116119
// produce one block
117120
err = exec.produceBlock()
118121
require.NoError(t, err)
@@ -180,6 +183,7 @@ func TestPendingLimit_SkipsProduction(t *testing.T) {
180183

181184
mockExec.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
182185
Return([]byte("i0"), uint64(1024), nil).Once()
186+
mockSeq.EXPECT().SetDAHeight(uint64(0)).Return().Once()
183187
require.NoError(t, exec.initializeState())
184188

185189
// Set up context for the executor (normally done in Start method)
@@ -196,6 +200,8 @@ func TestPendingLimit_SkipsProduction(t *testing.T) {
196200
mockExec.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), []byte("i0")).
197201
Return([]byte("i1"), uint64(1024), nil).Once()
198202

203+
mockSeq.EXPECT().GetDAHeight().Return(uint64(0)).Once()
204+
199205
require.NoError(t, exec.produceBlock())
200206
h1, err := memStore.Height(context.Background())
201207
require.NoError(t, err)

block/internal/executing/executor_restart_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func TestExecutor_RestartUsesPendingHeader(t *testing.T) {
7373
initStateRoot := []byte("init_root")
7474
mockExec1.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
7575
Return(initStateRoot, uint64(1024), nil).Once()
76+
mockSeq1.EXPECT().SetDAHeight(uint64(0)).Return().Once()
7677
require.NoError(t, exec1.initializeState())
7778

7879
// Set up context for first executor
@@ -92,6 +93,8 @@ func TestExecutor_RestartUsesPendingHeader(t *testing.T) {
9293
mockExec1.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), initStateRoot).
9394
Return([]byte("new_root_1"), uint64(1024), nil).Once()
9495

96+
mockSeq1.EXPECT().GetDAHeight().Return(uint64(0)).Once()
97+
9598
err = exec1.produceBlock()
9699
require.NoError(t, err)
97100

@@ -189,6 +192,7 @@ func TestExecutor_RestartUsesPendingHeader(t *testing.T) {
189192
require.NoError(t, err)
190193

191194
// Initialize state for second executor (should load existing state)
195+
mockSeq2.EXPECT().SetDAHeight(uint64(0)).Return().Once()
192196
require.NoError(t, exec2.initializeState())
193197

194198
// Set up context for second executor
@@ -206,7 +210,9 @@ func TestExecutor_RestartUsesPendingHeader(t *testing.T) {
206210
mockExec2.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(2), mock.AnythingOfType("time.Time"), currentState2.AppHash).
207211
Return([]byte("new_root_2"), uint64(1024), nil).Once()
208212

209-
// Note: mockSeq2 should NOT receive any calls because pending block should be used
213+
mockSeq2.EXPECT().GetDAHeight().Return(uint64(0)).Once()
214+
215+
// Note: mockSeq2 should NOT receive GetNextBatch calls because pending block should be used
210216

211217
err = exec2.produceBlock()
212218
require.NoError(t, err)
@@ -289,6 +295,7 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
289295
initStateRoot := []byte("init_root")
290296
mockExec1.EXPECT().InitChain(mock.Anything, mock.AnythingOfType("time.Time"), gen.InitialHeight, gen.ChainID).
291297
Return(initStateRoot, uint64(1024), nil).Once()
298+
mockSeq1.EXPECT().SetDAHeight(uint64(0)).Return().Once()
292299
require.NoError(t, exec1.initializeState())
293300

294301
exec1.ctx, exec1.cancel = context.WithCancel(context.Background())
@@ -307,6 +314,8 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
307314
mockExec1.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(1), mock.AnythingOfType("time.Time"), initStateRoot).
308315
Return([]byte("new_root_1"), uint64(1024), nil).Once()
309316

317+
mockSeq1.EXPECT().GetDAHeight().Return(uint64(0)).Once()
318+
310319
err = exec1.produceBlock()
311320
require.NoError(t, err)
312321

@@ -338,6 +347,7 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
338347
)
339348
require.NoError(t, err)
340349

350+
mockSeq2.EXPECT().SetDAHeight(uint64(0)).Return().Once()
341351
require.NoError(t, exec2.initializeState())
342352
exec2.ctx, exec2.cancel = context.WithCancel(context.Background())
343353
defer exec2.cancel()
@@ -360,6 +370,8 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
360370
mockExec2.EXPECT().ExecuteTxs(mock.Anything, mock.Anything, uint64(2), mock.AnythingOfType("time.Time"), []byte("new_root_1")).
361371
Return([]byte("new_root_2"), uint64(1024), nil).Once()
362372

373+
mockSeq2.EXPECT().GetDAHeight().Return(uint64(0)).Once()
374+
363375
err = exec2.produceBlock()
364376
require.NoError(t, err)
365377

block/internal/syncing/da_retriever_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ import (
2929

3030
// makeSignedDataBytes builds SignedData containing the provided Data and returns its binary encoding
3131
func makeSignedDataBytes(t *testing.T, chainID string, height uint64, proposer []byte, pub crypto.PubKey, signer signerpkg.Signer, txs int) ([]byte, *types.SignedData) {
32-
d := &types.Data{Metadata: &types.Metadata{ChainID: chainID, Height: height, Time: uint64(time.Now().UnixNano())}}
32+
return makeSignedDataBytesWithTime(t, chainID, height, proposer, pub, signer, txs, uint64(time.Now().UnixNano()))
33+
}
34+
35+
func makeSignedDataBytesWithTime(t *testing.T, chainID string, height uint64, proposer []byte, pub crypto.PubKey, signer signerpkg.Signer, txs int, timestamp uint64) ([]byte, *types.SignedData) {
36+
d := &types.Data{Metadata: &types.Metadata{ChainID: chainID, Height: height, Time: timestamp}}
3337
if txs > 0 {
3438
d.Txs = make(types.Txs, txs)
3539
for i := 0; i < txs; i++ {
@@ -522,11 +526,14 @@ func TestDARetriever_RetrieveForcedIncludedTxsFromDA_ExceedsMaxBlobSize(t *testi
522526

523527
namespaceForcedInclusionBz := coreda.NamespaceFromString(cfg.DA.GetForcedInclusionNamespace()).Bytes()
524528

529+
// Use fixed timestamp for deterministic test data
530+
fixedTime := uint64(1234567890)
531+
525532
// Create signed data blobs that will exceed DefaultMaxBlobSize when accumulated
526533
// DefaultMaxBlobSize is 1.5MB = 1,572,864 bytes
527534
// Each 700KB tx becomes ~719KB blob, so 2 blobs = ~1.44MB (fits), 3 blobs = ~2.16MB (exceeds)
528535
d1 := &types.Data{
529-
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 10, Time: uint64(time.Now().UnixNano())},
536+
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 10, Time: fixedTime},
530537
Txs: make(types.Txs, 1),
531538
}
532539
d1.Txs[0] = make([]byte, 700*1024) // 700KB transaction
@@ -540,7 +547,7 @@ func TestDARetriever_RetrieveForcedIncludedTxsFromDA_ExceedsMaxBlobSize(t *testi
540547
require.NoError(t, err)
541548

542549
d2 := &types.Data{
543-
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 11, Time: uint64(time.Now().UnixNano())},
550+
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 11, Time: fixedTime},
544551
Txs: make(types.Txs, 1),
545552
}
546553
d2.Txs[0] = make([]byte, 700*1024) // 700KB transaction
@@ -554,7 +561,7 @@ func TestDARetriever_RetrieveForcedIncludedTxsFromDA_ExceedsMaxBlobSize(t *testi
554561
require.NoError(t, err)
555562

556563
d3 := &types.Data{
557-
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 12, Time: uint64(time.Now().UnixNano())},
564+
Metadata: &types.Metadata{ChainID: gen.ChainID, Height: 12, Time: fixedTime},
558565
Txs: make(types.Txs, 1),
559566
}
560567
d3.Txs[0] = make([]byte, 700*1024) // 700KB transaction
@@ -720,10 +727,11 @@ func TestDARetriever_RetrieveForcedIncludedTxsFromDA_CompleteEpoch(t *testing.T)
720727
addr, pub, signer := buildSyncTestSigner(t)
721728
gen := genesis.Genesis{ChainID: "tchain", InitialHeight: 1, StartTime: time.Now().Add(-time.Second), ProposerAddress: addr, DAStartHeight: 2000, DAEpochForcedInclusion: 3}
722729

723-
// Prepare forced inclusion transaction data
724-
dataBin1, _ := makeSignedDataBytes(t, gen.ChainID, 10, addr, pub, signer, 2)
725-
dataBin2, _ := makeSignedDataBytes(t, gen.ChainID, 11, addr, pub, signer, 1)
726-
dataBin3, _ := makeSignedDataBytes(t, gen.ChainID, 12, addr, pub, signer, 1)
730+
// Prepare forced inclusion transaction data with fixed timestamp
731+
fixedTime := uint64(1234567890)
732+
dataBin1, _ := makeSignedDataBytesWithTime(t, gen.ChainID, 10, addr, pub, signer, 2, fixedTime)
733+
dataBin2, _ := makeSignedDataBytesWithTime(t, gen.ChainID, 11, addr, pub, signer, 1, fixedTime)
734+
dataBin3, _ := makeSignedDataBytesWithTime(t, gen.ChainID, 12, addr, pub, signer, 1, fixedTime)
727735

728736
cfg := config.DefaultConfig()
729737
cfg.DA.ForcedInclusionNamespace = "nsForcedInclusion"

pkg/genesis/genesis_test.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,50 +72,55 @@ func TestGenesis_Validate(t *testing.T) {
7272
{
7373
name: "valid genesis - chain ID can contain any character",
7474
genesis: Genesis{
75-
ChainID: "test@chain#123!",
76-
StartTime: validTime,
77-
InitialHeight: 1,
78-
ProposerAddress: []byte("proposer"),
75+
ChainID: "test@chain#123!",
76+
StartTime: validTime,
77+
InitialHeight: 1,
78+
ProposerAddress: []byte("proposer"),
79+
DAEpochForcedInclusion: 1,
7980
},
8081
wantErr: false,
8182
},
8283
{
8384
name: "invalid - empty chain_id",
8485
genesis: Genesis{
85-
ChainID: "",
86-
StartTime: validTime,
87-
InitialHeight: 1,
88-
ProposerAddress: []byte("proposer"),
86+
ChainID: "",
87+
StartTime: validTime,
88+
InitialHeight: 1,
89+
ProposerAddress: []byte("proposer"),
90+
DAEpochForcedInclusion: 1,
8991
},
9092
wantErr: true,
9193
},
9294
{
9395
name: "invalid - zero initial height",
9496
genesis: Genesis{
95-
ChainID: "test-chain",
96-
StartTime: validTime,
97-
InitialHeight: 0,
98-
ProposerAddress: []byte("proposer"),
97+
ChainID: "test-chain",
98+
StartTime: validTime,
99+
InitialHeight: 0,
100+
ProposerAddress: []byte("proposer"),
101+
DAEpochForcedInclusion: 1,
99102
},
100103
wantErr: true,
101104
},
102105
{
103106
name: "invalid - zero time DA start height",
104107
genesis: Genesis{
105-
ChainID: "test-chain",
106-
StartTime: time.Time{},
107-
InitialHeight: 1,
108-
ProposerAddress: []byte("proposer"),
108+
ChainID: "test-chain",
109+
StartTime: time.Time{},
110+
InitialHeight: 1,
111+
ProposerAddress: []byte("proposer"),
112+
DAEpochForcedInclusion: 1,
109113
},
110114
wantErr: true,
111115
},
112116
{
113117
name: "invalid - nil proposer address",
114118
genesis: Genesis{
115-
ChainID: "test-chain",
116-
StartTime: validTime,
117-
InitialHeight: 1,
118-
ProposerAddress: nil,
119+
ChainID: "test-chain",
120+
StartTime: validTime,
121+
InitialHeight: 1,
122+
ProposerAddress: nil,
123+
DAEpochForcedInclusion: 1,
119124
},
120125
wantErr: true,
121126
},

pkg/genesis/io_test.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,40 +30,44 @@ func TestLoadAndSaveGenesis(t *testing.T) {
3030
{
3131
name: "valid genesis",
3232
genesis: Genesis{
33-
ChainID: "test-chain-1",
34-
InitialHeight: 1,
35-
StartTime: validTime,
36-
ProposerAddress: []byte("proposer-address"),
33+
ChainID: "test-chain-1",
34+
InitialHeight: 1,
35+
StartTime: validTime,
36+
ProposerAddress: []byte("proposer-address"),
37+
DAEpochForcedInclusion: 1,
3738
},
3839
wantErr: false,
3940
},
4041
{
4142
name: "valid genesis - minimal",
4243
genesis: Genesis{
43-
ChainID: "test-chain-2",
44-
InitialHeight: 1,
45-
StartTime: validTime,
46-
ProposerAddress: []byte("proposer-address"),
44+
ChainID: "test-chain-2",
45+
InitialHeight: 1,
46+
StartTime: validTime,
47+
ProposerAddress: []byte("proposer-address"),
48+
DAEpochForcedInclusion: 1,
4749
},
4850
wantErr: false,
4951
},
5052
{
5153
name: "invalid genesis - empty chain ID",
5254
genesis: Genesis{
53-
ChainID: "",
54-
InitialHeight: 1,
55-
StartTime: validTime,
56-
ProposerAddress: []byte("proposer-address"),
55+
ChainID: "",
56+
InitialHeight: 1,
57+
StartTime: validTime,
58+
ProposerAddress: []byte("proposer-address"),
59+
DAEpochForcedInclusion: 1,
5760
},
5861
wantErr: true,
5962
},
6063
{
6164
name: "invalid genesis - zero initial height",
6265
genesis: Genesis{
63-
ChainID: "test-chain",
64-
InitialHeight: 0,
65-
StartTime: validTime,
66-
ProposerAddress: []byte("proposer-address"),
66+
ChainID: "test-chain",
67+
InitialHeight: 0,
68+
StartTime: validTime,
69+
ProposerAddress: []byte("proposer-address"),
70+
DAEpochForcedInclusion: 1,
6771
},
6872
wantErr: true,
6973
},
@@ -177,10 +181,11 @@ func TestSaveGenesis_InvalidPath(t *testing.T) {
177181
}
178182

179183
genesis := Genesis{
180-
ChainID: "test-chain",
181-
InitialHeight: 1,
182-
StartTime: time.Now().UTC(),
183-
ProposerAddress: []byte("proposer-address"),
184+
ChainID: "test-chain",
185+
InitialHeight: 1,
186+
StartTime: time.Now().UTC(),
187+
ProposerAddress: []byte("proposer-address"),
188+
DAEpochForcedInclusion: 1,
184189
}
185190

186191
err := genesis.Save(tc.path)

0 commit comments

Comments
 (0)