Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: backport snapshot / pruning refactor #206

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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