Cleanup from Simon's comments

This commit is contained in:
Ethan Frey
2022-04-28 20:49:02 +02:00
parent a154a9a124
commit cdcb18d3ad
2 changed files with 6 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import (
"compress/gzip"
)
// Note: []byte can never be const as they are inherently mutable
var (
// magic bytes to identify gzip.
// See https://www.ietf.org/rfc/rfc1952.txt

View File

@@ -89,17 +89,17 @@ func (ws *WasmSnapshotter) Snapshot(height uint64, protoWriter protoio.Writer) e
cacheMS := ws.cms.CacheMultiStore()
ctx := sdk.NewContext(cacheMS, tmproto.Header{}, false, log.NewNopLogger())
uniqueHashes := make(map[string]bool)
seenBefore := make(map[string]bool)
var rerr error
ws.wasm.IterateCodeInfos(ctx, func(id uint64, info types.CodeInfo) bool {
// Many code ids may point to the same code hash... only sync it once
hexHash := hex.EncodeToString(info.CodeHash)
// if uniqueHashes, just skip this one and move to the next
if uniqueHashes[hexHash] {
// if seenBefore, just skip this one and move to the next
if seenBefore[hexHash] {
return false
}
uniqueHashes[hexHash] = true
seenBefore[hexHash] = true
// load code and abort on error
wasmBytes, err := ws.wasm.GetByteCode(ctx, id)
@@ -160,7 +160,7 @@ func (ws *WasmSnapshotter) processAllItems(
cb func(sdk.Context, *Keeper, []byte) error,
finalize func(sdk.Context, *Keeper) error,
) (snapshot.SnapshotItem, error) {
ctx := sdk.NewContext(ws.cms, tmproto.Header{}, false, log.NewNopLogger())
ctx := sdk.NewContext(ws.cms, tmproto.Header{Height: int64(height)}, false, log.NewNopLogger())
// keep the last item here... if we break, it will either be empty (if we hit io.EOF)
// or contain the last item (if we hit payload == nil)