Skip to content

Commit

Permalink
fix: snapshotter's failure is not propogated (backport cosmos#16588) (c…
Browse files Browse the repository at this point in the history
…osmos#16604)

Co-authored-by: yihuang <huang@crypto.com>
  • Loading branch information
2 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent c92388a commit e7b445a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (x/auth) [#16554](https://github.com/cosmos/cosmos-sdk/pull/16554) `ModuleAccount.Validate` now reports a nil `.BaseAccount` instead of panicking.
* [#16588](https://github.com/cosmos/cosmos-sdk/pull/16588) Propogate the Snapshotter's failure to the caller, (it will create a empty snapshot silently before).

## [v0.46.13](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.13) - 2023-06-08

Expand Down
32 changes: 32 additions & 0 deletions store/snapshots/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,38 @@ func (m *mockSnapshotter) SupportedFormats() []uint32 {
return []uint32{2}
}

type mockErrorSnapshotter struct{}

var _ snapshottypes.Snapshotter = (*mockErrorSnapshotter)(nil)

func (m *mockErrorSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) error {
return errors.New("mock snapshot error")
}

func (m *mockErrorSnapshotter) Restore(
height uint64, format uint32, protoReader protoio.Reader,
) (snapshottypes.SnapshotItem, error) {
return snapshottypes.SnapshotItem{}, errors.New("mock restore error")
}

func (m *mockErrorSnapshotter) SnapshotFormat() uint32 {
return snapshottypes.CurrentFormat
}

func (m *mockErrorSnapshotter) SupportedFormats() []uint32 {
return []uint32{snapshottypes.CurrentFormat}
}

func (m *mockErrorSnapshotter) PruneSnapshotHeight(height int64) {
}

func (m *mockErrorSnapshotter) GetSnapshotInterval() uint64 {
return 0
}

func (m *mockErrorSnapshotter) SetSnapshotInterval(snapshotInterval uint64) {
}

// setupBusyManager creates a manager with an empty store that is busy creating a snapshot at height 1.
// The snapshot will complete when the returned closer is called.
func setupBusyManager(t *testing.T) *snapshots.Manager {
Expand Down
19 changes: 15 additions & 4 deletions store/snapshots/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

coretesting "cosmossdk.io/core/testing"
"cosmossdk.io/log"
"cosmossdk.io/store/snapshots"
"cosmossdk.io/store/snapshots/types"
"github.com/cosmos/cosmos-sdk/snapshots"
"github.com/cosmos/cosmos-sdk/snapshots/types"
"github.com/cosmos/cosmos-sdk/testutil"
)

var opts = types.NewSnapshotOptions(1500, 2)
Expand Down Expand Up @@ -330,3 +331,13 @@ func TestManager_CannotRestoreTooLargeItem(t *testing.T) {
require.Error(t, err)
require.True(t, errors.Is(err, io.ErrShortBuffer))
}

func TestManager_TakeError(t *testing.T) {
snapshotter := &mockErrorSnapshotter{}
store, err := snapshots.NewStore(dbm.NewMemDB(), testutil.GetTempDir(t))
require.NoError(t, err)
manager := snapshots.NewManager(store, opts, snapshotter, nil, log.NewNopLogger())

_, err = manager.Create(1)
require.Error(t, err)
}

0 comments on commit e7b445a

Please sign in to comment.