Skip to content

Commit

Permalink
CV statesync format 4 provide/restore actual store versions
Browse files Browse the repository at this point in the history
  • Loading branch information
chillyvee committed Dec 2, 2022
1 parent 90e3738 commit 626a01d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
2 changes: 2 additions & 0 deletions proto/cosmos/base/store/snapshots/v1beta1/snapshot.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ message SnapshotItem {
// Since: cosmos-sdk 0.46
message SnapshotStoreItem {
string name = 1;
// version is ideally block height, but not guaranteed
uint64 version = 2;
}

// SnapshotIAVLItem is an exported IAVL node.
Expand Down
14 changes: 11 additions & 3 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,8 @@ func (rs *Store) Snapshot(height uint64, protoWriter protoio.Writer) error {
err := protoWriter.WriteMsg(&snapshottypes.SnapshotItem{
Item: &snapshottypes.SnapshotItem_Store{
Store: &snapshottypes.SnapshotStoreItem{
Name: store.name,
Name: store.name,
Version: uint64(storeVersion),
},
},
})
Expand Down Expand Up @@ -892,14 +893,21 @@ loop:
if !ok || store == nil {
return snapshottypes.SnapshotItem{}, sdkerrors.Wrapf(sdkerrors.ErrLogic, "cannot import into non-IAVL store %q", item.Store.Name)
}
importer, err = store.Import(int64(height))
// Importer height must reflect the node height (which usually matches the block height, but not always)
rs.logger.Debug("Restore", "store", item.Store.Name, "version", item.Store.Version)
if item.Store.Version == 0 {
fmt.Printf("!!!!!!!!!!!!!!!!! Restore Error, Snapshot Missing Version, Use Another Peer !!!!!!!!!!!!!!!!")
rs.logger.Error("Restore Error, Snapshot Missing Version, Use Another Peer", "store", item.Store.Name, "version", item.Store.Version)
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(sdkerrors.ErrLogic, "Snapshot Without Store Version Not Supported, Use Another Peer")
}
importer, err = store.Import(int64(item.Store.Version))
if err != nil {
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(err, "import failed")
}
defer importer.Close()

case *snapshottypes.SnapshotItem_IAVL:
if importer == nil {
rs.logger.Error("Restore Error, Unexepected IAVL Node")
return snapshottypes.SnapshotItem{}, sdkerrors.Wrap(sdkerrors.ErrLogic, "received IAVL node item before store item")
}
if item.IAVL.Height > math.MaxInt8 {
Expand Down
6 changes: 5 additions & 1 deletion store/snapshots/types/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ package types
// CurrentFormat is the currently used format for snapshots. Snapshots using the same format
// must be identical across all nodes for a given height, so this must be bumped when the binary
// snapshot output changes.
const CurrentFormat uint32 = 3
// Format #1 - Assumes all stores in multistore have version == height
// Format #2 - Unknown Usage
// Format #3 - v0.46
// Format #4 - Transmits actual store version within multistore
const CurrentFormat uint32 = 4
36 changes: 36 additions & 0 deletions store/snapshots/types/snapshot.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 626a01d

Please sign in to comment.