From cdcb18d3adf974473a4232714885b2155a815dc8 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Thu, 28 Apr 2022 20:49:02 +0200 Subject: [PATCH] Cleanup from Simon's comments --- x/wasm/ioutils/utils.go | 1 + x/wasm/keeper/snapshotter.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/x/wasm/ioutils/utils.go b/x/wasm/ioutils/utils.go index 0a2fea8c73..d4b8abf349 100644 --- a/x/wasm/ioutils/utils.go +++ b/x/wasm/ioutils/utils.go @@ -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 diff --git a/x/wasm/keeper/snapshotter.go b/x/wasm/keeper/snapshotter.go index 2a3b255eb0..7e81acda67 100644 --- a/x/wasm/keeper/snapshotter.go +++ b/x/wasm/keeper/snapshotter.go @@ -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)