Skip to content

Commit 2bc0278

Browse files
committed
fix(core): storeEDS respects window param
1 parent f42e238 commit 2bc0278

File tree

6 files changed

+42
-25
lines changed

6 files changed

+42
-25
lines changed

core/eds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func storeEDS(
7676

7777
var err error
7878
// archival nodes should not store Q4 outside the availability window.
79-
if availability.IsWithinWindow(eh.Time(), availability.StorageWindow) {
79+
if availability.IsWithinWindow(eh.Time(), window) {
8080
err = store.PutODSQ4(ctx, eh.DAH, eh.Height(), eds)
8181
} else {
8282
err = store.PutODS(ctx, eh.DAH, eh.Height(), eds)

core/exchange_test.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
2424

2525
cfg := DefaultTestConfig()
2626
fetcher, cctx := createCoreFetcher(t, cfg)
27-
generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
27+
nonEmptyBlocks := generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
2828

2929
store, err := store.NewStore(store.DefaultParameters(), t.TempDir())
3030
require.NoError(t, err)
@@ -39,15 +39,15 @@ func TestCoreExchange_RequestHeaders(t *testing.T) {
3939
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
4040
require.NoError(t, err)
4141

42-
to := uint64(30)
42+
to := nonEmptyBlocks[len(nonEmptyBlocks)-1].height
4343
expectedFirstHeightInRange := genHeader.Height() + 1
4444
expectedLastHeightInRange := to - 1
4545
expectedLenHeaders := to - expectedFirstHeightInRange
4646

47-
_, err = cctx.WaitForHeightWithTimeout(30, 10*time.Second)
47+
_, err = cctx.WaitForHeightWithTimeout(int64(to), 10*time.Second)
4848
require.NoError(t, err)
4949

50-
// request headers from height 1 to 20 [2:30)
50+
// request headers from height 1 to last non-empty block height [2:to)
5151
headers, err := ce.GetRangeByHeight(context.Background(), genHeader, to)
5252
require.NoError(t, err)
5353

@@ -74,7 +74,7 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
7474

7575
cfg := DefaultTestConfig()
7676
fetcher, cctx := createCoreFetcher(t, cfg)
77-
generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
77+
nonEmptyBlocks := generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
7878

7979
store, err := store.NewStore(store.DefaultParameters(), t.TempDir())
8080
require.NoError(t, err)
@@ -94,10 +94,12 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
9494
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
9595
require.NoError(t, err)
9696

97-
err = cctx.WaitForBlocks(30)
97+
to := nonEmptyBlocks[len(nonEmptyBlocks)-1].height
98+
99+
err = cctx.WaitForBlocks(int64(to))
98100
require.NoError(t, err)
99101

100-
headers, err := ce.GetRangeByHeight(ctx, genHeader, 30)
102+
headers, err := ce.GetRangeByHeight(ctx, genHeader, to)
101103
require.NoError(t, err)
102104

103105
// ensure none of the "historic" EDSs were stored
@@ -121,11 +123,10 @@ func TestExchange_DoNotStoreHistoric(t *testing.T) {
121123
func TestExchange_StoreHistoricIfArchival(t *testing.T) {
122124
ctx, cancel := context.WithCancel(context.Background())
123125
t.Cleanup(cancel)
124-
t.Setenv("CELESTIA_OVERRIDE_AVAILABILITY_WINDOW", "1ns") // all blocks will be "historic"
125126

126127
cfg := DefaultTestConfig()
127128
fetcher, cctx := createCoreFetcher(t, cfg)
128-
generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
129+
nonEmptyBlocks := generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
129130

130131
store, err := store.NewStore(store.DefaultParameters(), t.TempDir())
131132
require.NoError(t, err)
@@ -134,7 +135,8 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
134135
fetcher,
135136
store,
136137
header.MakeExtendedHeader,
137-
WithArchivalMode(), // make sure to store them anyway
138+
WithAvailabilityWindow(time.Nanosecond), // all blocks will be historic
139+
WithArchivalMode(), // make sure to store them anyway
138140
)
139141
require.NoError(t, err)
140142

@@ -145,10 +147,12 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
145147
genHeader, err := ce.Get(ctx, genBlock.Header.Hash().Bytes())
146148
require.NoError(t, err)
147149

148-
_, err = cctx.WaitForHeight(30)
150+
to := nonEmptyBlocks[len(nonEmptyBlocks)-1].height
151+
152+
_, err = cctx.WaitForHeight(int64(to))
149153
require.NoError(t, err)
150154

151-
headers, err := ce.GetRangeByHeight(ctx, genHeader, 30)
155+
headers, err := ce.GetRangeByHeight(ctx, genHeader, to)
152156
require.NoError(t, err)
153157

154158
// ensure all "historic" EDSs were stored but not the .q4 files
@@ -205,14 +209,19 @@ func fillBlocks(
205209
}
206210
}
207211

212+
type testBlocks struct {
213+
height uint64
214+
datahash share.DataHash
215+
}
216+
208217
// generateNonEmptyBlocks generates at least 20 non-empty blocks
209218
func generateNonEmptyBlocks(
210219
t *testing.T,
211220
ctx context.Context,
212221
fetcher *BlockFetcher,
213222
cfg *testnode.Config,
214223
cctx testnode.Context,
215-
) []share.DataHash {
224+
) []testBlocks {
216225
// generate several non-empty blocks
217226
generateCtx, generateCtxCancel := context.WithCancel(context.Background())
218227

@@ -221,7 +230,7 @@ func generateNonEmptyBlocks(
221230

222231
go fillBlocks(t, generateCtx, cfg, cctx)
223232

224-
hashes := make([]share.DataHash, 0, 20)
233+
filledBlocks := make([]testBlocks, 0, 20)
225234

226235
i := 0
227236
for i < 20 {
@@ -232,13 +241,16 @@ func generateNonEmptyBlocks(
232241
if bytes.Equal(share.EmptyEDSDataHash(), b.Data.Hash()) {
233242
continue
234243
}
235-
hashes = append(hashes, share.DataHash(b.Data.Hash()))
244+
filledBlocks = append(filledBlocks, testBlocks{
245+
height: uint64(b.Header.Height),
246+
datahash: share.DataHash(b.Data.Hash()),
247+
})
236248
i++
237249
case <-ctx.Done():
238250
t.Fatal("failed to fill blocks within timeout")
239251
}
240252
}
241253
generateCtxCancel()
242254

243-
return hashes
255+
return filledBlocks
244256
}

core/listener_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ func TestListener_DoesNotStoreHistoric(t *testing.T) {
118118
opt := WithAvailabilityWindow(time.Nanosecond)
119119
cl := createListener(ctx, t, fetcher, ps0, eds, store, testChainID, opt)
120120

121-
dataRoots := generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
121+
nonEmptyBlocks := generateNonEmptyBlocks(t, ctx, fetcher, cfg, cctx)
122122

123123
err = cl.Start(ctx)
124124
require.NoError(t, err)
125125

126126
// ensure none of the EDSes were stored
127-
for _, hash := range dataRoots {
128-
has, err := store.HasByHash(ctx, hash)
127+
for _, block := range nonEmptyBlocks {
128+
has, err := store.HasByHash(ctx, block.datahash)
129129
require.NoError(t, err)
130130
assert.False(t, has)
131131

132132
// ensure .q4 file was not stored
133-
has, err = store.HasQ4ByHash(ctx, hash)
133+
has, err = store.HasQ4ByHash(ctx, block.datahash)
134134
require.NoError(t, err)
135135
assert.False(t, has)
136136
}

core/option.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
"github.com/celestiaorg/celestia-node/nodebuilder/p2p"
7+
"github.com/celestiaorg/celestia-node/share/availability"
78
)
89

910
type Option func(*params)
@@ -17,7 +18,7 @@ type params struct {
1718

1819
func defaultParams() params {
1920
return params{
20-
availabilityWindow: time.Duration(0),
21+
availabilityWindow: availability.StorageWindow,
2122
archival: false,
2223
}
2324
}

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,12 +386,16 @@ require (
386386
)
387387

388388
replace (
389-
cosmossdk.io/x/upgrade => github.com/celestiaorg/cosmos-sdk/x/upgrade v0.0.0-20250320145042-6d8b2a52fbb2
389+
// x/upgrade: v0.1.0
390+
cosmossdk.io/x/upgrade => github.com/celestiaorg/cosmos-sdk/x/upgrade v0.1.0
391+
// celestia-core: v1.53.0-tm-v0.38.17
390392
github.com/cometbft/cometbft => github.com/celestiaorg/celestia-core v1.53.0-tm-v0.38.17
391393
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.29.0-sdk-v0.50.12
392394
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
393395
// broken goleveldb needs to be replaced for the cosmos-sdk and celestia-app
394396
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
397+
// celestia-core(v0.34.x): used for multiplexing abci v1 requests
398+
github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.45.0-tm-v0.34.35
395399
)
396400

397401
replace github.com/ipfs/boxo => github.com/celestiaorg/boxo v0.29.0-fork

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,8 @@ github.com/celestiaorg/celestia-core v1.53.0-tm-v0.38.17 h1:AHjnWwPoOFH5zr+aPqdW
393393
github.com/celestiaorg/celestia-core v1.53.0-tm-v0.38.17/go.mod h1:PiU80T/t0z8FPlz7DRZgvrBux0jJiqxFi9lNBFdGUps=
394394
github.com/celestiaorg/cosmos-sdk v1.29.0-sdk-v0.50.12 h1:I5Wvy9BDSzPlr7RKtDofVhRH1rp6Wk/48Ah4FElMvjY=
395395
github.com/celestiaorg/cosmos-sdk v1.29.0-sdk-v0.50.12/go.mod h1:clLEg7hWK0iJfiO1Vp71tcQ0vGbFzVsEcLxxnRobIZM=
396-
github.com/celestiaorg/cosmos-sdk/x/upgrade v0.0.0-20250320145042-6d8b2a52fbb2 h1:o+cQNLd5GQJdtlD8k7YofVIOJB9wkPX9cIEJz0E3FFg=
397-
github.com/celestiaorg/cosmos-sdk/x/upgrade v0.0.0-20250320145042-6d8b2a52fbb2/go.mod h1:GdR2F3YQhICk8j5cEHOoSBdsIkKBDUcznPfjgnDHg5U=
396+
github.com/celestiaorg/cosmos-sdk/x/upgrade v0.1.0 h1:+i3G5mP/kPgFEn83EEXGly29QDin2Gvdt0kgpmw/vTg=
397+
github.com/celestiaorg/cosmos-sdk/x/upgrade v0.1.0/go.mod h1:T4K9O18zQNKNpt4YvTL3lcUt4aKOEU05ZIFWVdQi3Ak=
398398
github.com/celestiaorg/go-fraud v0.2.1 h1:oYhxI0gM/EpGRgbVQdRI/LSlqyT65g/WhQGSVGfx09w=
399399
github.com/celestiaorg/go-fraud v0.2.1/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc=
400400
github.com/celestiaorg/go-header v0.6.4 h1:3kXi7N3qBc4SCmT+tNVWhLi0Ilw5e/7qq2cxVGbs0ss=

0 commit comments

Comments
 (0)