Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 743adc9

Browse files
mergify[bot]p0mvn
andauthored
refactor: snapshot manager is created independently from snapshot-int… (#236) (#255)
(cherry picked from commit 0041954) Co-authored-by: Roman <roman@osmosis.team>
1 parent 2bb9f46 commit 743adc9

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

baseapp/abci.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,12 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 {
691691
}
692692

693693
if app.snapshotManager != nil {
694+
snapshotInterval := int64(app.snapshotManager.GetInterval())
694695
// Define the state pruning offset, i.e. the block offset at which the
695696
// underlying logical database is persisted to disk.
696-
statePruningOffset := int64(app.snapshotManager.GetInterval())
697-
if statePruningOffset > 0 {
698-
if commitHeight > statePruningOffset {
699-
v := commitHeight - (commitHeight % statePruningOffset)
697+
if snapshotInterval > 0 {
698+
if commitHeight > snapshotInterval {
699+
v := commitHeight - (commitHeight % snapshotInterval)
700700
retentionHeight = minNonZero(retentionHeight, v)
701701
} else {
702702
// Hitting this case means we have persisting enabled but have yet to reach
@@ -705,11 +705,10 @@ func (app *BaseApp) GetBlockRetentionHeight(commitHeight int64) int64 {
705705
// any state committed to disk.
706706
return 0
707707
}
708-
}
709-
710-
snapshotRetentionHeights := app.snapshotManager.GetSnapshotBlockRetentionHeights()
711-
if snapshotRetentionHeights > 0 {
712-
retentionHeight = minNonZero(retentionHeight, commitHeight-snapshotRetentionHeights)
708+
snapshotRetentionHeights := app.snapshotManager.GetSnapshotBlockRetentionHeights()
709+
if snapshotRetentionHeights > 0 {
710+
retentionHeight = minNonZero(retentionHeight, commitHeight-snapshotRetentionHeights)
711+
}
713712
}
714713
}
715714

baseapp/baseapp_test.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,10 +2265,11 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
22652265
require.NoError(t, err)
22662266

22672267
testCases := map[string]struct {
2268-
bapp *BaseApp
2269-
expectedPruning pruningtypes.PruningOptions
2270-
expectedSnapshot snapshottypes.SnapshotOptions
2271-
expectedErr error
2268+
bapp *BaseApp
2269+
expectedPruning pruningtypes.PruningOptions
2270+
expectedSnapshot snapshottypes.SnapshotOptions
2271+
expectedErr error
2272+
isSnapshotManagerNil bool
22722273
}{
22732274
"snapshot but no pruning": {
22742275
NewBaseApp(name, logger, db, nil,
@@ -2278,14 +2279,26 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
22782279
snapshottypes.NewSnapshotOptions(1500, 2),
22792280
// if no pruning is set, the default is PruneNothing
22802281
nil,
2282+
false,
2283+
},
2284+
"nil snapshot store": {
2285+
NewBaseApp(name, logger, db, nil,
2286+
SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)),
2287+
SetSnapshot(nil, snapshottypes.NewSnapshotOptions(1500, 2)),
2288+
),
2289+
pruningtypes.NewPruningOptions(pruningtypes.PruningNothing),
2290+
snapshottypes.SnapshotOptions{},
2291+
nil,
2292+
true,
22812293
},
22822294
"pruning everything only": {
22832295
NewBaseApp(name, logger, db, nil,
22842296
SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningEverything)),
22852297
),
22862298
pruningtypes.NewPruningOptions(pruningtypes.PruningEverything),
2287-
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 0),
2299+
snapshottypes.SnapshotOptions{},
22882300
nil,
2301+
true,
22892302
},
22902303
"pruning nothing only": {
22912304
NewBaseApp(name, logger, db, nil,
@@ -2294,6 +2307,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
22942307
pruningtypes.NewPruningOptions(pruningtypes.PruningNothing),
22952308
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 0),
22962309
nil,
2310+
true,
22972311
},
22982312
"pruning default only": {
22992313
NewBaseApp(name, logger, db, nil,
@@ -2302,6 +2316,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23022316
pruningtypes.NewPruningOptions(pruningtypes.PruningDefault),
23032317
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 0),
23042318
nil,
2319+
true,
23052320
},
23062321
"pruning custom only": {
23072322
NewBaseApp(name, logger, db, nil,
@@ -2310,6 +2325,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23102325
pruningtypes.NewCustomPruningOptions(10, 10),
23112326
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 0),
23122327
nil,
2328+
true,
23132329
},
23142330
"pruning everything and snapshots": {
23152331
NewBaseApp(name, logger, db, nil,
@@ -2319,6 +2335,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23192335
pruningtypes.NewPruningOptions(pruningtypes.PruningEverything),
23202336
snapshottypes.NewSnapshotOptions(1500, 2),
23212337
nil,
2338+
false,
23222339
},
23232340
"pruning nothing and snapshots": {
23242341
NewBaseApp(name, logger, db, nil,
@@ -2328,6 +2345,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23282345
pruningtypes.NewPruningOptions(pruningtypes.PruningNothing),
23292346
snapshottypes.NewSnapshotOptions(1500, 2),
23302347
nil,
2348+
false,
23312349
},
23322350
"pruning default and snapshots": {
23332351
NewBaseApp(name, logger, db, nil,
@@ -2337,6 +2355,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23372355
pruningtypes.NewPruningOptions(pruningtypes.PruningDefault),
23382356
snapshottypes.NewSnapshotOptions(1500, 2),
23392357
nil,
2358+
false,
23402359
},
23412360
"pruning custom and snapshots": {
23422361
NewBaseApp(name, logger, db, nil,
@@ -2346,6 +2365,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23462365
pruningtypes.NewCustomPruningOptions(10, 10),
23472366
snapshottypes.NewSnapshotOptions(1500, 2),
23482367
nil,
2368+
false,
23492369
},
23502370
"error custom pruning 0 interval": {
23512371
NewBaseApp(name, logger, db, nil,
@@ -2355,6 +2375,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23552375
pruningtypes.NewCustomPruningOptions(10, 0),
23562376
snapshottypes.NewSnapshotOptions(1500, 2),
23572377
pruningtypes.ErrPruningIntervalZero,
2378+
false,
23582379
},
23592380
"error custom pruning too small interval": {
23602381
NewBaseApp(name, logger, db, nil,
@@ -2364,6 +2385,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23642385
pruningtypes.NewCustomPruningOptions(10, 9),
23652386
snapshottypes.NewSnapshotOptions(1500, 2),
23662387
pruningtypes.ErrPruningIntervalTooSmall,
2388+
false,
23672389
},
23682390
"error custom pruning too small keep recent": {
23692391
NewBaseApp(name, logger, db, nil,
@@ -2373,15 +2395,17 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23732395
pruningtypes.NewCustomPruningOptions(9, 10),
23742396
snapshottypes.NewSnapshotOptions(1500, 2),
23752397
pruningtypes.ErrPruningKeepRecentTooSmall,
2398+
false,
23762399
},
2377-
"snapshot zero interval - manager not set": {
2400+
"snapshot zero interval - manager is set": {
23782401
NewBaseApp(name, logger, db, nil,
23792402
SetPruning(pruningtypes.NewCustomPruningOptions(10, 10)),
23802403
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(0, 2)),
23812404
),
23822405
pruningtypes.NewCustomPruningOptions(10, 10),
2383-
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 0),
2406+
snapshottypes.NewSnapshotOptions(snapshottypes.SnapshotIntervalOff, 2),
23842407
nil,
2408+
false,
23852409
},
23862410
"snapshot zero keep recent - allowed": {
23872411
NewBaseApp(name, logger, db, nil,
@@ -2391,6 +2415,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
23912415
pruningtypes.NewCustomPruningOptions(10, 10),
23922416
snapshottypes.NewSnapshotOptions(1500, 0), // 0 snapshot-keep-recent means keep all
23932417
nil,
2418+
false,
23942419
},
23952420
}
23962421

@@ -2407,7 +2432,7 @@ func TestBaseApp_Init_PruningAndSnapshot(t *testing.T) {
24072432
actualPruning := tc.bapp.cms.GetPruning()
24082433
require.Equal(t, tc.expectedPruning, actualPruning)
24092434

2410-
if tc.expectedSnapshot.Interval == snapshottypes.SnapshotIntervalOff {
2435+
if tc.isSnapshotManagerNil {
24112436
require.Nil(t, tc.bapp.snapshotManager)
24122437
continue
24132438
}

baseapp/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (app *BaseApp) SetSnapshot(snapshotStore *snapshots.Store, opts snapshottyp
234234
if app.sealed {
235235
panic("SetSnapshot() on sealed BaseApp")
236236
}
237-
if snapshotStore == nil || opts.Interval == snapshottypes.SnapshotIntervalOff {
237+
if snapshotStore == nil {
238238
app.snapshotManager = nil
239239
return
240240
}

0 commit comments

Comments
 (0)