Skip to content

Commit

Permalink
refactor: address snapshot/pruning refactor comments upstream (#184) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
p0mvn authored Apr 26, 2022
1 parent 0fb8ffc commit f1a3f95
Show file tree
Hide file tree
Showing 37 changed files with 1,441 additions and 604 deletions.
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) {
app.halt()
}

app.snapshotManager.SnapshotIfApplicable(header.Height)
go app.snapshotManager.SnapshotIfApplicable(header.Height)

app.logger.Info("committed ABCI", "height", commitID.Version, "commit_hash", fmt.Sprintf("%X", commitID.Hash), "retain_height", retainHeight)
return abci.ResponseCommit{
Expand Down
30 changes: 16 additions & 14 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/snapshots"
snaphotsTestUtil "github.com/cosmos/cosmos-sdk/testutil/snapshots"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmprototypes "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
"github.com/cosmos/cosmos-sdk/snapshots"
snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types"
snaphotstestutil "github.com/cosmos/cosmos-sdk/testutil/snapshots"
sdk "github.com/cosmos/cosmos-sdk/types"
)

func TestGetBlockRentionHeight(t *testing.T) {
logger := defaultLogger()
db := dbm.NewMemDB()
name := t.Name()

snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snaphotsTestUtil.GetTempDir(t))
snapshotStore, err := snapshots.NewStore(dbm.NewMemDB(), snaphotstestutil.GetTempDir(t))
require.NoError(t, err)

testCases := map[string]struct {
Expand All @@ -43,9 +45,9 @@ func TestGetBlockRentionHeight(t *testing.T) {
"pruning iavl snapshot only": {
bapp: NewBaseApp(
name, logger, db, nil,
SetPruning(sdk.NewPruningOptions(sdk.Nothing)),
SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing)),
SetMinRetainBlocks(1),
SetSnapshot(snapshotStore, sdk.NewSnapshotOptions(10000, 1)),
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(10000, 1)),
),
maxAgeBlocks: 0,
commitHeight: 499000,
Expand All @@ -54,7 +56,7 @@ func TestGetBlockRentionHeight(t *testing.T) {
"pruning state sync snapshot only": {
bapp: NewBaseApp(
name, logger, db, nil,
SetSnapshot(snapshotStore, sdk.NewSnapshotOptions(50000, 3)),
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(50000, 3)),
SetMinRetainBlocks(1),
),
maxAgeBlocks: 0,
Expand All @@ -73,9 +75,9 @@ func TestGetBlockRentionHeight(t *testing.T) {
"pruning all conditions": {
bapp: NewBaseApp(
name, logger, db, nil,
SetPruning(sdk.NewCustomPruningOptions(0, 0)),
SetPruning(pruningtypes.NewCustomPruningOptions(0, 0)),
SetMinRetainBlocks(400000),
SetSnapshot(snapshotStore, sdk.NewSnapshotOptions(50000, 3)),
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(50000, 3)),
),
maxAgeBlocks: 362880,
commitHeight: 499000,
Expand All @@ -84,9 +86,9 @@ func TestGetBlockRentionHeight(t *testing.T) {
"no pruning due to no persisted state": {
bapp: NewBaseApp(
name, logger, db, nil,
SetPruning(sdk.NewCustomPruningOptions(0, 0)),
SetPruning(pruningtypes.NewCustomPruningOptions(0, 0)),
SetMinRetainBlocks(400000),
SetSnapshot(snapshotStore, sdk.NewSnapshotOptions(50000, 3)),
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(50000, 3)),
),
maxAgeBlocks: 362880,
commitHeight: 10000,
Expand All @@ -95,9 +97,9 @@ func TestGetBlockRentionHeight(t *testing.T) {
"disable pruning": {
bapp: NewBaseApp(
name, logger, db, nil,
SetPruning(sdk.NewCustomPruningOptions(0, 0)),
SetPruning(pruningtypes.NewCustomPruningOptions(0, 0)),
SetMinRetainBlocks(0),
SetSnapshot(snapshotStore, sdk.NewSnapshotOptions(50000, 3)),
SetSnapshot(snapshotStore, snapshottypes.NewSnapshotOptions(50000, 3)),
),
maxAgeBlocks: 362880,
commitHeight: 499000,
Expand Down
10 changes: 3 additions & 7 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package baseapp

import (
"errors"
"fmt"
"reflect"
"strings"
Expand Down Expand Up @@ -302,13 +301,10 @@ func (app *BaseApp) init() error {
app.Seal()

rms, ok := app.cms.(*rootmulti.Store)
if !ok && app.snapshotManager != nil {
return errors.New("state sync snapshots require a rootmulti store")
if !ok {
return fmt.Errorf("invalid commit multi-store; expected %T, got: %T", &rootmulti.Store{}, app.cms)
}
if err := rms.GetPruning().Validate(); err != nil {
return err
}
return nil
return rms.GetPruning().Validate()
}

func (app *BaseApp) setMinGasPrices(gasPrices sdk.DecCoins) {
Expand Down
Loading

0 comments on commit f1a3f95

Please sign in to comment.