fix: rootmulti's Restore don't return the next unknown item as expected (#11286)
## Description Solution: - return the next unknown item and add a unit test to ensure that. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
This commit is contained in:
parent
e657190604
commit
41bd879acb
|
@ -182,6 +182,14 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
|
|||
target := newMultiStoreWithMixedMounts(dbm.NewMemDB())
|
||||
version := uint64(source.LastCommitID().Version)
|
||||
require.EqualValues(t, 3, version)
|
||||
dummyExtensionItem := snapshottypes.SnapshotItem{
|
||||
Item: &snapshottypes.SnapshotItem_Extension{
|
||||
Extension: &snapshottypes.SnapshotExtensionMeta{
|
||||
Name: "test",
|
||||
Format: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
chunks := make(chan io.ReadCloser, 100)
|
||||
go func() {
|
||||
|
@ -190,12 +198,16 @@ func TestMultistoreSnapshotRestore(t *testing.T) {
|
|||
defer streamWriter.Close()
|
||||
err := source.Snapshot(version, streamWriter)
|
||||
require.NoError(t, err)
|
||||
// write an extension metadata
|
||||
err = streamWriter.WriteMsg(&dummyExtensionItem)
|
||||
require.NoError(t, err)
|
||||
}()
|
||||
|
||||
streamReader, err := snapshots.NewStreamReader(chunks)
|
||||
require.NoError(t, err)
|
||||
_, err = target.Restore(version, snapshottypes.CurrentFormat, streamReader)
|
||||
nextItem, err := target.Restore(version, snapshottypes.CurrentFormat, streamReader)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, *dummyExtensionItem.GetExtension(), *nextItem.GetExtension())
|
||||
|
||||
assert.Equal(t, source.LastCommitID(), target.LastCommitID())
|
||||
for key, sourceStore := range source.GetStores() {
|
||||
|
|
|
@ -755,9 +755,11 @@ func (rs *Store) Restore(
|
|||
// a SnapshotStoreItem, telling us which store to import into. The following items will contain
|
||||
// SnapshotNodeItem (i.e. ExportNode) until we reach the next SnapshotStoreItem or EOF.
|
||||
var importer *iavltree.Importer
|
||||
var snapshotItem snapshottypes.SnapshotItem
|
||||
loop:
|
||||
for {
|
||||
snapshotItem := &snapshottypes.SnapshotItem{}
|
||||
err := protoReader.ReadMsg(snapshotItem)
|
||||
snapshotItem = snapshottypes.SnapshotItem{}
|
||||
err := protoReader.ReadMsg(&snapshotItem)
|
||||
if err == io.EOF {
|
||||
break
|
||||
} else if err != nil {
|
||||
|
@ -811,8 +813,7 @@ func (rs *Store) Restore(
|
|||
}
|
||||
|
||||
default:
|
||||
// pass back the unrecognized item.
|
||||
return *snapshotItem, nil
|
||||
break loop
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -825,7 +826,7 @@ func (rs *Store) Restore(
|
|||
}
|
||||
|
||||
flushMetadata(rs.db, int64(height), rs.buildCommitInfo(int64(height)), []int64{})
|
||||
return snapshottypes.SnapshotItem{}, rs.LoadLatestVersion()
|
||||
return snapshotItem, rs.LoadLatestVersion()
|
||||
}
|
||||
|
||||
func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID, params storeParams) (types.CommitKVStore, error) {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue