diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fd33d3d9777..e220eb440016 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,7 +57,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (baseapp) [#18499](https://github.com/cosmos/cosmos-sdk/pull/18499) Add `MsgRouter` response type from message name function. * (types) [#18768](https://github.com/cosmos/cosmos-sdk/pull/18768) Add MustValAddressFromBech32 function. * (gRPC) [#19049](https://github.com/cosmos/cosmos-sdk/pull/19049) Add debug log prints for each gRPC request. -* (x/consensus) [#19483](https://github.com/cosmos/cosmos-sdk/pull/19483) Add consensus messages registration to consensus module. * (types) [#19759](https://github.com/cosmos/cosmos-sdk/pull/19759) Align SignerExtractionAdapter in PriorityNonceMempool Remove. * (client) [#19870](https://github.com/cosmos/cosmos-sdk/pull/19870) Add new query command `wait-tx`. Alias `event-query-tx-for` to `wait-tx` for backward compatibility. * (crypto/keyring) [#20212](https://github.com/cosmos/cosmos-sdk/pull/20212) Expose the db keyring used in the keystore. @@ -145,7 +144,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * The module manager now can do everything that the basic manager was doing. * When using runtime, just inject the module manager when needed using your app config. * All `AppModuleBasic` structs have been removed. -* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services. * (server) [#18303](https://github.com/cosmos/cosmos-sdk/pull/18303) `x/genutil` now handles the application export. `server.AddCommands` does not take an `AppExporter` but instead `genutilcli.Commands` does. * (x/gov/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/18036) `MsgDeposit` has been removed because of AutoCLI migration. * (x/staking/testutil) [#17986](https://github.com/cosmos/cosmos-sdk/pull/17986) `MsgRedelegateExec`, `MsgUnbondExec` has been removed because of AutoCLI migration. @@ -175,7 +173,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (x/staking) [#18257](https://github.com/cosmos/cosmos-sdk/pull/18257) Staking module was moved to its own go.mod `cosmossdk.io/x/staking` * (x/authz) [#18265](https://github.com/cosmos/cosmos-sdk/pull/18265) Authz module was moved to its own go.mod `cosmossdk.io/x/authz` * (x/mint) [#18283](https://github.com/cosmos/cosmos-sdk/pull/18283) Mint module was moved to its own go.mod `cosmossdk.io/x/mint` -* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error * (x/slashing) [#18115](https://github.com/cosmos/cosmos-sdk/pull/18115) `NewValidatorSigningInfo` takes strings instead of `sdk.AccAddress` * (types) [#18268](https://github.com/cosmos/cosmos-sdk/pull/18268) Remove global setting of basedenom. Use the staking module parameter instead * (x/auth) [#18351](https://github.com/cosmos/cosmos-sdk/pull/18351) Auth module was moved to its own go.mod `cosmossdk.io/x/auth` diff --git a/api/cosmos/consensus/v1/tx.pulsar.go b/api/cosmos/consensus/v1/tx.pulsar.go index c0328eeffb62..6a6a85835bc5 100644 --- a/api/cosmos/consensus/v1/tx.pulsar.go +++ b/api/cosmos/consensus/v1/tx.pulsar.go @@ -1298,8 +1298,6 @@ type MsgUpdateParams struct { Block *v1.BlockParams `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"` Evidence *v1.EvidenceParams `protobuf:"bytes,3,opt,name=evidence,proto3" json:"evidence,omitempty"` Validator *v1.ValidatorParams `protobuf:"bytes,4,opt,name=validator,proto3" json:"validator,omitempty"` - // Since: cosmos-sdk 0.51 - // // Deprecated: Do not use. Abci *v1.ABCIParams `protobuf:"bytes,5,opt,name=abci,proto3" json:"abci,omitempty"` Synchrony *v1.SynchronyParams `protobuf:"bytes,6,opt,name=synchrony,proto3" json:"synchrony,omitempty"` @@ -1444,7 +1442,7 @@ var file_cosmos_consensus_v1_tx_proto_rawDesc = []byte{ 0x62, 0x66, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x79, 0x6e, 0x63, 0x68, 0x72, 0x6f, 0x6e, 0x79, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, 0x13, 0xda, 0xb4, 0x2d, 0x0f, 0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73, 0x2d, 0x73, 0x64, 0x6b, 0x20, 0x30, 0x2e, 0x35, - 0x31, 0x52, 0x09, 0x73, 0x79, 0x6e, 0x63, 0x68, 0x72, 0x6f, 0x6e, 0x79, 0x12, 0x4f, 0x0a, 0x07, + 0x32, 0x52, 0x09, 0x73, 0x79, 0x6e, 0x63, 0x68, 0x72, 0x6f, 0x6e, 0x79, 0x12, 0x4f, 0x0a, 0x07, 0x66, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x63, 0x6f, 0x6d, 0x65, 0x74, 0x62, 0x66, 0x74, 0x2e, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x76, 0x31, 0x2e, 0x46, 0x65, 0x61, 0x74, 0x75, 0x72, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x42, diff --git a/store/v2/commitment/store_test_suite.go b/store/v2/commitment/store_test_suite.go index edbce27116c9..18b4ef4e2cc0 100644 --- a/store/v2/commitment/store_test_suite.go +++ b/store/v2/commitment/store_test_suite.go @@ -221,6 +221,83 @@ func (s *CommitStoreTestSuite) TestStore_Pruning() { } } +func (s *CommitStoreTestSuite) TestStore_GetProof() { + storeKeys := []string{storeKey1, storeKey2} + commitStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, nil, coretesting.NewNopLogger()) + s.Require().NoError(err) + + toVersion := uint64(10) + keyCount := 5 + + // commit some changes + for version := uint64(1); version <= toVersion; version++ { + cs := corestore.NewChangeset() + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", version, i)), []byte(fmt.Sprintf("value-%d-%d", version, i)), false) + } + } + err := commitStore.WriteChangeset(cs) + s.Require().NoError(err) + _, err = commitStore.Commit(version) + s.Require().NoError(err) + } + + // get proof + for version := uint64(1); version <= toVersion; version++ { + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + _, err := commitStore.GetProof([]byte(storeKey), version, []byte(fmt.Sprintf("key-%d-%d", version, i))) + s.Require().NoError(err) + } + } + } + + // prune version 1 + s.Require().NoError(commitStore.Prune(1)) + + // check if proof for version 1 is pruned + _, err = commitStore.GetProof([]byte(storeKeys[0]), 1, []byte(fmt.Sprintf("key-%d-%d", 1, 0))) + s.Require().Error(err) + // check the commit info + commit, _ := commitStore.GetCommitInfo(1) + s.Require().Nil(commit) +} + +func (s *CommitStoreTestSuite) TestStore_Get() { + storeKeys := []string{storeKey1, storeKey2} + commitStore, err := s.NewStore(dbm.NewMemDB(), storeKeys, nil, coretesting.NewNopLogger()) + s.Require().NoError(err) + + toVersion := uint64(10) + keyCount := 5 + + // commit some changes + for version := uint64(1); version <= toVersion; version++ { + cs := corestore.NewChangeset() + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", version, i)), []byte(fmt.Sprintf("value-%d-%d", version, i)), false) + } + } + err := commitStore.WriteChangeset(cs) + s.Require().NoError(err) + _, err = commitStore.Commit(version) + s.Require().NoError(err) + } + + // get proof + for version := uint64(1); version <= toVersion; version++ { + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + val, err := commitStore.Get([]byte(storeKey), version, []byte(fmt.Sprintf("key-%d-%d", version, i))) + s.Require().NoError(err) + s.Require().Equal([]byte(fmt.Sprintf("value-%d-%d", version, i)), val) + } + } + } +} + func (s *CommitStoreTestSuite) TestStore_Upgrades() { storeKeys := []string{storeKey1, storeKey2, storeKey3} commitDB := dbm.NewMemDB() diff --git a/store/v2/migration/manager_test.go b/store/v2/migration/manager_test.go index ae00d5c08bbb..4e04f6c40514 100644 --- a/store/v2/migration/manager_test.go +++ b/store/v2/migration/manager_test.go @@ -1,6 +1,7 @@ package migration import ( + "encoding/binary" "fmt" "testing" @@ -117,3 +118,103 @@ func TestMigrateState(t *testing.T) { }) } } + +func TestStartMigrateState(t *testing.T) { + for _, noCommitStore := range []bool{false, true} { + t.Run(fmt.Sprintf("Migrate noCommitStore=%v", noCommitStore), func(t *testing.T) { + m, orgCommitStore := setupMigrationManager(t, noCommitStore) + + chDone := make(chan struct{}) + chChangeset := make(chan *VersionedChangeset, 1) + + // apply changeset + toVersion := uint64(10) + keyCount := 5 + changesets := []corestore.Changeset{} + + for version := uint64(1); version <= toVersion; version++ { + cs := corestore.NewChangeset() + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", version, i)), []byte(fmt.Sprintf("value-%d-%d", version, i)), false) + } + } + changesets = append(changesets, *cs) + require.NoError(t, orgCommitStore.WriteChangeset(cs)) + _, err := orgCommitStore.Commit(version) + require.NoError(t, err) + } + + // feed changesets to channel + go func() { + for version := uint64(1); version <= toVersion; version++ { + chChangeset <- &VersionedChangeset{ + Version: version, + Changeset: &changesets[version-1], + } + } + }() + + // check if migrate process complete + go func() { + for { + migrateVersion := m.GetMigratedVersion() + if migrateVersion == toVersion-1 { + break + } + } + + chDone <- struct{}{} + }() + + err := m.Start(toVersion-1, chChangeset, chDone) + require.NoError(t, err) + + // expecting error for conflicting process, since Migrate trigger snapshotter create migration, + // which start a snapshot process already. + _, err = m.snapshotsManager.Create(toVersion - 1) + require.Error(t, err) + + if m.stateCommitment != nil { + // check the migrated state + for version := uint64(1); version < toVersion; version++ { + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + val, err := m.stateCommitment.Get([]byte(storeKey), toVersion-1, []byte(fmt.Sprintf("key-%d-%d", version, i))) + require.NoError(t, err) + require.Equal(t, []byte(fmt.Sprintf("value-%d-%d", version, i)), val) + } + } + } + // check the latest state + val, err := m.stateCommitment.Get([]byte("store1"), toVersion-1, []byte("key-100-1")) + require.NoError(t, err) + require.Nil(t, val) + val, err = m.stateCommitment.Get([]byte("store2"), toVersion-1, []byte("key-100-0")) + require.NoError(t, err) + require.Nil(t, val) + } + + // check the storage + for version := uint64(1); version < toVersion; version++ { + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + val, err := m.stateStorage.Get([]byte(storeKey), toVersion-1, []byte(fmt.Sprintf("key-%d-%d", version, i))) + require.NoError(t, err) + require.Equal(t, []byte(fmt.Sprintf("value-%d-%d", version, i)), val) + } + } + } + + // check if migration db write change set to storage + for version := uint64(1); version < toVersion; version++ { + buf := make([]byte, 8) + binary.BigEndian.PutUint64(buf, version) + csKey := []byte(fmt.Sprintf(migrateChangesetKeyFmt, buf)) + csVal, err := m.db.Get(csKey) + require.NoError(t, err) + require.NotEmpty(t, csVal) + } + }) + } +} diff --git a/store/v2/pruning/manager_test.go b/store/v2/pruning/manager_test.go index 9f96b2a48360..c5d137f1d09e 100644 --- a/store/v2/pruning/manager_test.go +++ b/store/v2/pruning/manager_test.go @@ -152,3 +152,107 @@ func TestPruningOption(t *testing.T) { }) } } + +func (s *PruningManagerTestSuite) TestSignalCommit() { + // commit version 1 + cs := corestore.NewChangeset() + for _, storeKey := range storeKeys { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", 1, 0)), []byte(fmt.Sprintf("value-%d-%d", 1, 0)), false) + } + + s.Require().NoError(s.sc.WriteChangeset(cs)) + _, err := s.sc.Commit(1) + s.Require().NoError(err) + + s.Require().NoError(s.ss.ApplyChangeset(1, cs)) + + // commit version 2 + for _, storeKey := range storeKeys { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", 2, 0)), []byte(fmt.Sprintf("value-%d-%d", 2, 0)), false) + } + + // signaling commit has started + s.Require().NoError(s.manager.SignalCommit(true, 2)) + + s.Require().NoError(s.sc.WriteChangeset(cs)) + _, err = s.sc.Commit(2) + s.Require().NoError(err) + + s.Require().NoError(s.ss.ApplyChangeset(2, cs)) + + // try prune before signaling commit has finished + s.Require().NoError(s.manager.Prune(2)) + + // proof is removed no matter SignalCommit has not yet inform that commit process has finish + // since commitInfo is remove async with tree data + checkSCPrune := func() bool { + count := 0 + for _, storeKey := range storeKeys { + _, err := s.sc.GetProof([]byte(storeKey), 1, []byte(fmt.Sprintf("key-%d-%d", 1, 0))) + if err != nil { + count++ + } + } + + return count == len(storeKeys) + } + s.Require().Eventually(checkSCPrune, 10*time.Second, 1*time.Second) + + // data from state commitment should not be pruned since we haven't signal the commit process has finished + val, err := s.sc.Get([]byte(storeKeys[0]), 1, []byte(fmt.Sprintf("key-%d-%d", 1, 0))) + s.Require().NoError(err) + s.Require().Equal(val, []byte(fmt.Sprintf("value-%d-%d", 1, 0))) + + // signaling commit has finished, version 1 should be pruned + s.Require().NoError(s.manager.SignalCommit(false, 2)) + + checkSCPrune = func() bool { + count := 0 + for _, storeKey := range storeKeys { + _, err := s.sc.GetProof([]byte(storeKey), 1, []byte(fmt.Sprintf("key-%d-%d", 1, 0))) + if err != nil { + count++ + } + } + + return count == len(storeKeys) + } + s.Require().Eventually(checkSCPrune, 10*time.Second, 1*time.Second) + + // try with signal commit start and finish accordingly + // commit changesets with pruning + toVersion := uint64(100) + keyCount := 10 + for version := uint64(3); version <= toVersion; version++ { + cs := corestore.NewChangeset() + for _, storeKey := range storeKeys { + for i := 0; i < keyCount; i++ { + cs.Add([]byte(storeKey), []byte(fmt.Sprintf("key-%d-%d", version, i)), []byte(fmt.Sprintf("value-%d-%d", version, i)), false) + } + } + s.Require().NoError(s.manager.SignalCommit(true, version)) + + s.Require().NoError(s.sc.WriteChangeset(cs)) + _, err := s.sc.Commit(version) + s.Require().NoError(err) + + s.Require().NoError(s.ss.ApplyChangeset(version, cs)) + + s.Require().NoError(s.manager.SignalCommit(false, version)) + + } + + // wait for the pruning to finish in the commitment store + checkSCPrune = func() bool { + count := 0 + for _, storeKey := range storeKeys { + _, err := s.sc.GetProof([]byte(storeKey), toVersion-1, []byte(fmt.Sprintf("key-%d-%d", toVersion-1, 0))) + if err != nil { + count++ + } + } + + return count == len(storeKeys) + } + s.Require().Eventually(checkSCPrune, 10*time.Second, 1*time.Second) +} diff --git a/store/v2/root/store_test.go b/store/v2/root/store_test.go index fa4d25648a2a..eddaea730652 100644 --- a/store/v2/root/store_test.go +++ b/store/v2/root/store_test.go @@ -643,7 +643,7 @@ func (s *RootStoreTestSuite) TestMultiStore_PruningRestart() { return false } // wait for async pruning process to finish - s.Require().Eventually(checkErr, 5*time.Second, 100*time.Millisecond, "expected error when loading height: %d", v) + s.Require().Eventually(checkErr, 10*time.Second, 1*time.Second, "expected error when loading height: %d", v) } } diff --git a/store/v2/snapshots/helpers_test.go b/store/v2/snapshots/helpers_test.go index 129704325c6a..657fd5c6f1ba 100644 --- a/store/v2/snapshots/helpers_test.go +++ b/store/v2/snapshots/helpers_test.go @@ -120,6 +120,7 @@ func (m *mockCommitSnapshotter) Restore( var item snapshotstypes.SnapshotItem m.items = [][]byte{} + keyCount := 0 for { item.Reset() err := protoReader.ReadMsg(&item) @@ -133,6 +134,19 @@ func (m *mockCommitSnapshotter) Restore( break } m.items = append(m.items, payload.Payload) + // mock feeding chStorage to check if the loop closed properly + // + // ref: https://github.com/cosmos/cosmos-sdk/pull/21106 + chStorage <- &corestore.StateChanges{ + Actor: []byte("actor"), + StateChanges: []corestore.KVPair{ + { + Key: []byte(fmt.Sprintf("key-%d", keyCount)), + Value: payload.Payload, + }, + }, + } + keyCount++ } return item, nil @@ -155,9 +169,19 @@ func (m *mockCommitSnapshotter) SupportedFormats() []uint32 { return []uint32{snapshotstypes.CurrentFormat} } -type mockStorageSnapshotter struct{} +type mockStorageSnapshotter struct { + items map[string][]byte +} func (m *mockStorageSnapshotter) Restore(version uint64, chStorage <-chan *corestore.StateChanges) error { + // mock consuming chStorage to check if the loop closed properly + // + // ref: https://github.com/cosmos/cosmos-sdk/pull/21106 + for change := range chStorage { + for _, kv := range change.StateChanges { + m.items[string(kv.Key)] = kv.Value + } + } return nil } diff --git a/store/v2/snapshots/manager_test.go b/store/v2/snapshots/manager_test.go index 4fd33e1b36fa..2ecec5660066 100644 --- a/store/v2/snapshots/manager_test.go +++ b/store/v2/snapshots/manager_test.go @@ -2,7 +2,9 @@ package snapshots_test import ( "errors" + "fmt" "testing" + "time" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -129,8 +131,9 @@ func TestManager_Prune(t *testing.T) { func TestManager_Restore(t *testing.T) { store := setupStore(t) target := &mockCommitSnapshotter{} + storageSnapshotter := &mockStorageSnapshotter{items: map[string][]byte{}} extSnapshotter := newExtSnapshotter(0) - manager := snapshots.NewManager(store, opts, target, &mockStorageSnapshotter{}, nil, coretesting.NewNopLogger()) + manager := snapshots.NewManager(store, opts, target, storageSnapshotter, nil, coretesting.NewNopLogger()) err := manager.RegisterExtensions(extSnapshotter) require.NoError(t, err) @@ -203,6 +206,14 @@ func TestManager_Restore(t *testing.T) { assert.Equal(t, expectItems, target.items) assert.Equal(t, 10, len(extSnapshotter.state)) + // make sure storageSnapshotter items are properly stored + for i, item := range target.items { + key := fmt.Sprintf("key-%d", i) + chunk := storageSnapshotter.items[key] + require.NotNil(t, chunk) + require.Equal(t, item, chunk) + } + // The snapshot is saved in local snapshot store snapshots, err := store.List() require.NoError(t, err) @@ -265,10 +276,12 @@ func TestSnapshot_Take_Restore(t *testing.T) { commitSnapshotter := &mockCommitSnapshotter{ items: items, } + storageSnapshotter := &mockStorageSnapshotter{items: map[string][]byte{}} + extSnapshotter := newExtSnapshotter(10) expectChunks := snapshotItems(items, extSnapshotter) - manager := snapshots.NewManager(store, opts, commitSnapshotter, &mockStorageSnapshotter{}, nil, coretesting.NewNopLogger()) + manager := snapshots.NewManager(store, opts, commitSnapshotter, storageSnapshotter, nil, coretesting.NewNopLogger()) err := manager.RegisterExtensions(extSnapshotter) require.NoError(t, err) @@ -418,3 +431,107 @@ func TestSnapshot_Take_Prune(t *testing.T) { _, err = manager.Prune(2) require.Error(t, err) } + +func TestSnapshot_Pruning_Take_Snapshot_Parallel(t *testing.T) { + store := setupStore(t) + + items := [][]byte{ + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + } + commitSnapshotter := &mockCommitSnapshotter{ + items: items, + } + extSnapshotter := newExtSnapshotter(10) + + expectChunks := snapshotItems(items, extSnapshotter) + manager := snapshots.NewManager(store, opts, commitSnapshotter, &mockStorageSnapshotter{}, nil, coretesting.NewNopLogger()) + err := manager.RegisterExtensions(extSnapshotter) + require.NoError(t, err) + + var prunedCount uint64 + // try take snapshot and pruning parallel while prune operation begins first + go func() { + checkError := func() bool { + _, err := manager.Create(4) + return err != nil + } + + require.Eventually(t, checkError, time.Millisecond*200, time.Millisecond) + }() + + prunedCount, err = manager.Prune(1) + require.NoError(t, err) + assert.EqualValues(t, 3, prunedCount) + + // creating a snapshot at a same height 4, should be true since we prune has finished + snapshot, err := manager.Create(4) + require.NoError(t, err) + + assert.Equal(t, &types.Snapshot{ + Height: 4, + Format: commitSnapshotter.SnapshotFormat(), + Chunks: 1, + Hash: []uint8{0xc5, 0xf7, 0xfe, 0xea, 0xd3, 0x4d, 0x3e, 0x87, 0xff, 0x41, 0xa2, 0x27, 0xfa, 0xcb, 0x38, 0x17, 0xa, 0x5, 0xeb, 0x27, 0x4e, 0x16, 0x5e, 0xf3, 0xb2, 0x8b, 0x47, 0xd1, 0xe6, 0x94, 0x7e, 0x8b}, + Metadata: types.Metadata{ + ChunkHashes: checksums(expectChunks), + }, + }, snapshot) + + // try take snapshot and pruning parallel while snapshot operation begins first + go func() { + checkError := func() bool { + _, err = manager.Prune(1) + return err != nil + } + + require.Eventually(t, checkError, time.Millisecond*200, time.Millisecond) + }() + + snapshot, err = manager.Create(5) + require.NoError(t, err) + + assert.Equal(t, &types.Snapshot{ + Height: 5, + Format: commitSnapshotter.SnapshotFormat(), + Chunks: 1, + Hash: []uint8{0xc5, 0xf7, 0xfe, 0xea, 0xd3, 0x4d, 0x3e, 0x87, 0xff, 0x41, 0xa2, 0x27, 0xfa, 0xcb, 0x38, 0x17, 0xa, 0x5, 0xeb, 0x27, 0x4e, 0x16, 0x5e, 0xf3, 0xb2, 0x8b, 0x47, 0xd1, 0xe6, 0x94, 0x7e, 0x8b}, + Metadata: types.Metadata{ + ChunkHashes: checksums(expectChunks), + }, + }, snapshot) +} + +func TestSnapshot_SnapshotIfApplicable(t *testing.T) { + store := setupStore(t) + + items := [][]byte{ + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + } + commitSnapshotter := &mockCommitSnapshotter{ + items: items, + } + extSnapshotter := newExtSnapshotter(10) + + snapshotOpts := snapshots.NewSnapshotOptions(1, 1) + + manager := snapshots.NewManager(store, snapshotOpts, commitSnapshotter, &mockStorageSnapshotter{}, nil, coretesting.NewNopLogger()) + err := manager.RegisterExtensions(extSnapshotter) + require.NoError(t, err) + + manager.SnapshotIfApplicable(4) + + checkLatestHeight := func() bool { + latestSnapshot, _ := store.GetLatest() + return latestSnapshot.Height == 4 + } + + require.Eventually(t, checkLatestHeight, time.Second*10, time.Second) + + pruned, err := manager.Prune(1) + require.NoError(t, err) + require.Equal(t, uint64(0), pruned) +} diff --git a/store/v2/storage/storage_test_suite.go b/store/v2/storage/storage_test_suite.go index 2bc745221d75..6b4247fffc8d 100644 --- a/store/v2/storage/storage_test_suite.go +++ b/store/v2/storage/storage_test_suite.go @@ -640,6 +640,72 @@ func (s *StorageTestSuite) TestDatabase_Prune_KeepRecent() { s.Require().Equal([]byte("val200"), bz) } +func (s *StorageTestSuite) TestDatabase_Restore() { + db, err := s.NewDB(s.T().TempDir()) + s.Require().NoError(err) + defer db.Close() + + toVersion := uint64(10) + keyCount := 10 + + // for versions 1-10, set 10 keys + for v := uint64(1); v <= toVersion; v++ { + cs := corestore.NewChangesetWithPairs(map[string]corestore.KVPairs{storeKey1: {}}) + for i := 0; i < keyCount; i++ { + key := fmt.Sprintf("key%03d", i) + val := fmt.Sprintf("val%03d-%03d", i, v) + + cs.AddKVPair(storeKey1Bytes, corestore.KVPair{Key: []byte(key), Value: []byte(val)}) + } + + s.Require().NoError(db.ApplyChangeset(v, cs)) + } + + latestVersion, err := db.GetLatestVersion() + s.Require().NoError(err) + s.Require().Equal(uint64(10), latestVersion) + + chStorage := make(chan *corestore.StateChanges, 5) + + go func() { + for i := uint64(11); i <= 15; i++ { + kvPairs := []corestore.KVPair{} + for j := 0; j < keyCount; j++ { + key := fmt.Sprintf("key%03d-%03d", j, i) + val := fmt.Sprintf("val%03d-%03d", j, i) + + kvPairs = append(kvPairs, corestore.KVPair{Key: []byte(key), Value: []byte(val)}) + } + chStorage <- &corestore.StateChanges{ + Actor: storeKey1Bytes, + StateChanges: kvPairs, + } + } + close(chStorage) + }() + + // restore with snapshot version smaller than latest version + // should return an error + err = db.Restore(9, chStorage) + s.Require().Error(err) + + // restore + err = db.Restore(11, chStorage) + s.Require().NoError(err) + + // check the storage + for i := uint64(11); i <= 15; i++ { + for j := 0; j < keyCount; j++ { + key := fmt.Sprintf("key%03d-%03d", j, i) + val := fmt.Sprintf("val%03d-%03d", j, i) + + v, err := db.Get(storeKey1Bytes, 11, []byte(key)) + s.Require().NoError(err) + s.Require().Equal([]byte(val), v) + } + } +} + func (s *StorageTestSuite) TestUpgradable() { ss, err := s.NewDB(s.T().TempDir()) s.Require().NoError(err) diff --git a/tests/e2e/accounts/lockup/periodic_lockup_test_suite.go b/tests/e2e/accounts/lockup/periodic_lockup_test_suite.go index 8e36befcc091..948f5eb8a30b 100644 --- a/tests/e2e/accounts/lockup/periodic_lockup_test_suite.go +++ b/tests/e2e/accounts/lockup/periodic_lockup_test_suite.go @@ -1,7 +1,6 @@ package lockup import ( - "fmt" "testing" "time" @@ -155,7 +154,6 @@ func (s *E2ETestSuite) TestPeriodicLockingAccount() { // check if tracking is updated accordingly lockupAccountInfoResponse := s.queryLockupAccInfo(ctx, app, accountAddr) - fmt.Println(lockupAccountInfoResponse) delLocking := lockupAccountInfoResponse.DelegatedLocking require.True(t, delLocking.AmountOf("stake").Equal(math.NewInt(100))) }) diff --git a/x/consensus/CHANGELOG.md b/x/consensus/CHANGELOG.md index 23c658a931ca..74694f4a7b0d 100644 --- a/x/consensus/CHANGELOG.md +++ b/x/consensus/CHANGELOG.md @@ -31,4 +31,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Features + +* (x/consensus) [#19483](https://github.com/cosmos/cosmos-sdk/pull/19483) Add consensus messages registration to consensus module. * [#20615](https://github.com/cosmos/cosmos-sdk/pull/20615) Add consensus messages to add cometinfo to consensus modules + +### API Breaking Changes + +* (x/consensus) [#19488](https://github.com/cosmos/cosmos-sdk/pull/19488) Consensus module creation takes `appmodule.Environment` instead of individual services. +* (x/consensus) [#18041](https://github.com/cosmos/cosmos-sdk/pull/18041) `ToProtoConsensusParams()` returns an error + diff --git a/x/consensus/keeper/keeper.go b/x/consensus/keeper/keeper.go index fbf7fcc41012..9236f76f8ddb 100644 --- a/x/consensus/keeper/keeper.go +++ b/x/consensus/keeper/keeper.go @@ -19,8 +19,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" ) -var StoreKey = "Consensus" - type Keeper struct { appmodule.Environment diff --git a/x/consensus/keeper/keeper_test.go b/x/consensus/keeper/keeper_test.go index 48188411b591..ed2bee648a70 100644 --- a/x/consensus/keeper/keeper_test.go +++ b/x/consensus/keeper/keeper_test.go @@ -38,7 +38,7 @@ func getDuration(d time.Duration) *time.Duration { } func (s *KeeperTestSuite) SetupTest(enabledFeatures bool) { - key := storetypes.NewKVStoreKey(consensusparamkeeper.StoreKey) + key := storetypes.NewKVStoreKey(types.StoreKey) testCtx := testutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test")) ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Height: 5}) encCfg := moduletestutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}) diff --git a/x/consensus/proto/cosmos/consensus/v1/tx.proto b/x/consensus/proto/cosmos/consensus/v1/tx.proto index d6b21625c41b..afecf31d97b8 100644 --- a/x/consensus/proto/cosmos/consensus/v1/tx.proto +++ b/x/consensus/proto/cosmos/consensus/v1/tx.proto @@ -38,9 +38,9 @@ message MsgUpdateParams { cometbft.types.v1.EvidenceParams evidence = 3; cometbft.types.v1.ValidatorParams validator = 4; - // Since: cosmos-sdk 0.51 - cometbft.types.v1.ABCIParams abci = 5 [deprecated = true, (cosmos_proto.field_added_in) = "cosmos-sdk 0.50"]; - cometbft.types.v1.SynchronyParams synchrony = 6 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.51"]; + cometbft.types.v1.ABCIParams abci = 5 [deprecated = true, (cosmos_proto.field_added_in) = "cosmos-sdk 0.50"]; + + cometbft.types.v1.SynchronyParams synchrony = 6 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.52"]; cometbft.types.v1.FeatureParams feature = 7 [(cosmos_proto.field_added_in) = "cosmos-sdk 0.52"]; } diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 71c950aa292e..832658049d2c 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -31,37 +31,17 @@ func (msg MsgUpdateParams) ToProtoConsensusParams() (cmtproto.ConsensusParams, e PubKeyTypes: msg.Validator.PubKeyTypes, }, Version: cmttypes.DefaultConsensusParams().ToProto().Version, // Version is stored in x/upgrade - Feature: &cmtproto.FeatureParams{}, - Synchrony: &cmtproto.SynchronyParams{}, + Feature: msg.Feature, + Synchrony: msg.Synchrony, } if msg.Abci != nil { - cp.Feature.VoteExtensionsEnableHeight = &types.Int64Value{ - Value: msg.Abci.VoteExtensionsEnableHeight, - } - } - - if msg.Feature != nil { - if msg.Feature.VoteExtensionsEnableHeight != nil { - cp.Feature.VoteExtensionsEnableHeight = &types.Int64Value{ - Value: msg.Feature.GetVoteExtensionsEnableHeight().GetValue(), - } + if cp.Feature == nil { + cp.Feature = &cmtproto.FeatureParams{} } - if msg.Feature.PbtsEnableHeight != nil { - cp.Feature.PbtsEnableHeight = &types.Int64Value{ - Value: msg.Feature.GetPbtsEnableHeight().GetValue(), - } - } - } - if msg.Synchrony != nil { - if msg.Synchrony.MessageDelay != nil { - delay := *msg.Synchrony.MessageDelay - cp.Synchrony.MessageDelay = &delay - } - if msg.Synchrony.Precision != nil { - precision := *msg.Synchrony.Precision - cp.Synchrony.Precision = &precision + cp.Feature.VoteExtensionsEnableHeight = &types.Int64Value{ + Value: msg.Abci.VoteExtensionsEnableHeight, } } diff --git a/x/consensus/types/tx.pb.go b/x/consensus/types/tx.pb.go index fec7fc671890..33f9d9a38eb6 100644 --- a/x/consensus/types/tx.pb.go +++ b/x/consensus/types/tx.pb.go @@ -44,7 +44,6 @@ type MsgUpdateParams struct { Block *v1.BlockParams `protobuf:"bytes,2,opt,name=block,proto3" json:"block,omitempty"` Evidence *v1.EvidenceParams `protobuf:"bytes,3,opt,name=evidence,proto3" json:"evidence,omitempty"` Validator *v1.ValidatorParams `protobuf:"bytes,4,opt,name=validator,proto3" json:"validator,omitempty"` - // Since: cosmos-sdk 0.51 Abci *v1.ABCIParams `protobuf:"bytes,5,opt,name=abci,proto3" json:"abci,omitempty"` // Deprecated: Do not use. Synchrony *v1.SynchronyParams `protobuf:"bytes,6,opt,name=synchrony,proto3" json:"synchrony,omitempty"` Feature *v1.FeatureParams `protobuf:"bytes,7,opt,name=feature,proto3" json:"feature,omitempty"` @@ -179,39 +178,39 @@ func init() { func init() { proto.RegisterFile("cosmos/consensus/v1/tx.proto", fileDescriptor_2135c60575ab504d) } var fileDescriptor_2135c60575ab504d = []byte{ - // 507 bytes of a gzipped FileDescriptorProto + // 506 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x93, 0x4f, 0x6b, 0x13, 0x41, 0x18, 0xc6, 0xb3, 0x36, 0x69, 0xcd, 0x28, 0x14, 0x27, 0x4a, 0xa7, 0xa1, 0x0e, 0x31, 0x88, 0x94, 0x60, 0x66, 0x9b, 0x58, 0x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0x3e, 0x8c, 0x78, 0x30, 0x42, 0xcb, 0x7f, 0x3d, 0xcb, 0x5e, 0xe6, 0x49, + 0x33, 0x6b, 0x7f, 0x66, 0x76, 0xad, 0x3c, 0x09, 0xbe, 0x00, 0x2b, 0x07, 0x8c, 0xca, 0x61, 0xc4, + 0xd0, 0x8a, 0x0a, 0x6d, 0x14, 0x84, 0x3e, 0xd5, 0x8e, 0x7f, 0x45, 0x66, 0x29, 0x0f, 0xee, 0xbf, + 0x9f, 0x8d, 0x5b, 0xf9, 0x8b, 0xfb, 0x38, 0x1b, 0xb7, 0x6e, 0xe4, 0x66, 0xf3, 0xf8, 0xb7, 0x2d, + 0x5e, 0xd8, 0x8d, 0xe6, 0x3a, 0x58, 0x5b, 0x78, 0x64, 0x31, 0x11, 0x26, 0xf6, 0xee, 0x07, 0x03, + 0x2c, 0xed, 0x0a, 0x17, 0xbe, 0x05, 0x17, 0xcf, 0xac, 0xd3, 0x75, 0x52, 0xb0, 0xfd, 0x64, 0x21, + 0xa5, 0x7e, 0xf3, 0x7f, 0x5c, 0x59, 0x57, 0xb3, 0xf6, 0x75, 0xf1, 0x7e, 0xdb, 0x77, 0xeb, 0x95, + 0x77, 0xb3, 0x71, 0xcb, 0xe8, 0xdd, 0xfb, 0x32, 0xc1, 0xc6, 0xe9, 0x04, 0x1b, 0x3f, 0x27, 0xd8, + 0xf8, 0x34, 0xc5, 0xa5, 0xd3, 0x29, 0x2e, 0x7d, 0x9f, 0xe2, 0xd2, 0x6b, 0xac, 0x09, 0xe1, 0x0c, + 0x88, 0xc7, 0xcf, 0x5c, 0x53, 0x8d, 0xb1, 0xbf, 0xac, 0xbe, 0x89, 0x5b, 0xbf, 0x02, 0x00, 0x00, + 0xff, 0xff, 0x84, 0xf1, 0x97, 0xc0, 0xcd, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used.