@@ -2,6 +2,8 @@ package keeper
2
2
3
3
import (
4
4
"encoding/hex"
5
+ "errors"
6
+ "fmt"
5
7
"io"
6
8
7
9
snapshot "github.com/cosmos/cosmos-sdk/snapshots/types"
@@ -98,37 +100,53 @@ func (ws *WasmSnapshotter) Restore(
98
100
return snapshot.SnapshotItem {}, snapshot .ErrUnknownFormat
99
101
}
100
102
101
- func restoreV1 (ctx sdk.Context , k * Keeper , compressedCode []byte ) error {
103
+ func restoreV1 (ctx sdk.Context , k * Keeper , compressedCode []byte , num int ) error {
102
104
wasmCode , err := ioutils .Uncompress (compressedCode , uint64 (types .MaxWasmSize ))
103
105
if err != nil {
104
106
return sdkerrors .Wrap (types .ErrCreateFailed , err .Error ())
105
107
}
106
108
107
109
// FIXME: check which codeIDs the checksum matches??
108
- _ , err = k .wasmVM .Create (wasmCode )
110
+ checkSum , err : = k .wasmVM .Create (wasmCode )
109
111
if err != nil {
110
112
return sdkerrors .Wrap (types .ErrCreateFailed , err .Error ())
111
113
}
114
+ ctx .Logger ().Info (fmt .Sprintf ("Restored %d WASM code with checksum %X" , num , checkSum ))
112
115
return nil
113
116
}
114
117
115
118
func finalizeV1 (ctx sdk.Context , k * Keeper ) error {
116
- // FIXME: ensure all codes have been uploaded?
119
+ var errCheckingExistence error
120
+ k .IterateCodeInfos (ctx , func (id uint64 , info types.CodeInfo ) bool {
121
+ _ , err := k .GetByteCode (ctx , id )
122
+ if err != nil {
123
+ e := fmt .Sprintf ("Could not find byte code for ID %d hash %X: %s" , id , info .CodeHash , err )
124
+ ctx .Logger ().Error (e )
125
+ errCheckingExistence = errors .New (e )
126
+ }
127
+
128
+ return false
129
+ })
130
+ if errCheckingExistence != nil {
131
+ return errCheckingExistence
132
+ }
117
133
return k .InitializePinnedCodes (ctx )
118
134
}
119
135
120
136
func (ws * WasmSnapshotter ) processAllItems (
121
137
height uint64 ,
122
138
protoReader protoio.Reader ,
123
- cb func (sdk.Context , * Keeper , []byte ) error ,
139
+ cb func (sdk.Context , * Keeper , []byte , int ) error ,
124
140
finalize func (sdk.Context , * Keeper ) error ,
125
141
) (snapshot.SnapshotItem , error ) {
126
142
ctx := sdk .NewContext (ws .cms , tmproto.Header {Height : int64 (height )}, false , log .NewNopLogger ())
127
143
128
144
// keep the last item here... if we break, it will either be empty (if we hit io.EOF)
129
145
// or contain the last item (if we hit payload == nil)
130
146
var item snapshot.SnapshotItem
147
+ itemNum := 0
131
148
for {
149
+ itemNum ++
132
150
item = snapshot.SnapshotItem {}
133
151
err := protoReader .ReadMsg (& item )
134
152
if err == io .EOF {
@@ -144,7 +162,7 @@ func (ws *WasmSnapshotter) processAllItems(
144
162
break
145
163
}
146
164
147
- if err := cb (ctx , ws .wasm , payload .Payload ); err != nil {
165
+ if err := cb (ctx , ws .wasm , payload .Payload , itemNum ); err != nil {
148
166
return snapshot.SnapshotItem {}, sdkerrors .Wrap (err , "processing snapshot item" )
149
167
}
150
168
}
0 commit comments