Remove check for wasm limit size in state sync (#1471)
* Remove check for wasm limit size in state sync * Fix comments * Store original value in variable
This commit is contained in:
@@ -129,7 +129,7 @@ func parseVerificationFlags(gzippedWasm []byte, flags *flag.FlagSet) (string, st
|
||||
// wasm is gzipped in parseStoreCodeArgs
|
||||
// checksum generation will be decoupled here
|
||||
// reference https://github.com/CosmWasm/wasmvm/issues/359
|
||||
raw, err := ioutils.Uncompress(gzippedWasm, uint64(types.MaxWasmSize))
|
||||
raw, err := ioutils.Uncompress(gzippedWasm, int64(types.MaxWasmSize))
|
||||
if err != nil {
|
||||
return "", "", nil, fmt.Errorf("invalid zip: %w", err)
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
// Uncompress expects a valid gzip source to unpack or fails. See IsGzip
|
||||
func Uncompress(gzipSrc []byte, limit uint64) ([]byte, error) {
|
||||
if uint64(len(gzipSrc)) > limit {
|
||||
func Uncompress(gzipSrc []byte, limit int64) ([]byte, error) {
|
||||
if int64(len(gzipSrc)) > limit {
|
||||
return nil, types.ErrLimit.Wrapf("max %d bytes", limit)
|
||||
}
|
||||
zr, err := gzip.NewReader(bytes.NewReader(gzipSrc))
|
||||
@@ -21,7 +21,7 @@ func Uncompress(gzipSrc []byte, limit uint64) ([]byte, error) {
|
||||
}
|
||||
zr.Multistream(false)
|
||||
defer zr.Close()
|
||||
bz, err := io.ReadAll(LimitReader(zr, int64(limit)))
|
||||
bz, err := io.ReadAll(LimitReader(zr, limit))
|
||||
if types.ErrLimit.Is(err) {
|
||||
return nil, errorsmod.Wrapf(err, "max %d bytes", limit)
|
||||
}
|
||||
|
||||
@@ -121,6 +121,9 @@ func TestGenesisExportImport(t *testing.T) {
|
||||
return false
|
||||
})
|
||||
|
||||
originalMaxWasmSize := types.MaxWasmSize
|
||||
types.MaxWasmSize = 1
|
||||
|
||||
// re-import
|
||||
var importState types.GenesisState
|
||||
err = dstKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState)
|
||||
@@ -133,6 +136,12 @@ func TestGenesisExportImport(t *testing.T) {
|
||||
srcIT := srcCtx.KVStore(wasmKeeper.storeKey).Iterator(nil, nil)
|
||||
dstIT := dstCtx.KVStore(dstKeeper.storeKey).Iterator(nil, nil)
|
||||
|
||||
t.Cleanup(func() {
|
||||
types.MaxWasmSize = originalMaxWasmSize
|
||||
srcIT.Close()
|
||||
dstIT.Close()
|
||||
})
|
||||
|
||||
for i := 0; srcIT.Valid(); i++ {
|
||||
require.True(t, dstIT.Valid(), "[%s] destination DB has less elements than source. Missing: %x", wasmKeeper.storeKey.Name(), srcIT.Key())
|
||||
require.Equal(t, srcIT.Key(), dstIT.Key(), i)
|
||||
@@ -143,8 +152,6 @@ func TestGenesisExportImport(t *testing.T) {
|
||||
if !assert.False(t, dstIT.Valid()) {
|
||||
t.Fatalf("dest Iterator still has key :%X", dstIT.Key())
|
||||
}
|
||||
srcIT.Close()
|
||||
dstIT.Close()
|
||||
}
|
||||
|
||||
func TestGenesisInit(t *testing.T) {
|
||||
|
||||
@@ -170,7 +170,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte,
|
||||
|
||||
if ioutils.IsGzip(wasmCode) {
|
||||
ctx.GasMeter().ConsumeGas(k.gasRegister.UncompressCosts(len(wasmCode)), "Uncompress gzip bytecode")
|
||||
wasmCode, err = ioutils.Uncompress(wasmCode, uint64(types.MaxWasmSize))
|
||||
wasmCode, err = ioutils.Uncompress(wasmCode, int64(types.MaxWasmSize))
|
||||
if err != nil {
|
||||
return 0, checksum, types.ErrCreateFailed.Wrap(errorsmod.Wrap(err, "uncompress wasm archive").Error())
|
||||
}
|
||||
@@ -212,7 +212,7 @@ func (k Keeper) storeCodeInfo(ctx sdk.Context, codeID uint64, codeInfo types.Cod
|
||||
func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeInfo, wasmCode []byte) error {
|
||||
if ioutils.IsGzip(wasmCode) {
|
||||
var err error
|
||||
wasmCode, err = ioutils.Uncompress(wasmCode, uint64(types.MaxWasmSize))
|
||||
wasmCode, err = ioutils.Uncompress(wasmCode, math.MaxInt64)
|
||||
if err != nil {
|
||||
return types.ErrCreateFailed.Wrap(errorsmod.Wrap(err, "uncompress wasm archive").Error())
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package keeper
|
||||
import (
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"math"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cometbft/cometbft/libs/log"
|
||||
@@ -99,7 +100,7 @@ func restoreV1(_ sdk.Context, k *Keeper, compressedCode []byte) error {
|
||||
if !ioutils.IsGzip(compressedCode) {
|
||||
return types.ErrInvalid.Wrap("not a gzip")
|
||||
}
|
||||
wasmCode, err := ioutils.Uncompress(compressedCode, uint64(types.MaxWasmSize))
|
||||
wasmCode, err := ioutils.Uncompress(compressedCode, math.MaxInt64)
|
||||
if err != nil {
|
||||
return errorsmod.Wrap(types.ErrCreateFailed, err.Error())
|
||||
}
|
||||
|
||||
@@ -67,6 +67,12 @@ func TestSnapshotter(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, snapshot)
|
||||
|
||||
originalMaxWasmSize := types.MaxWasmSize
|
||||
types.MaxWasmSize = 1
|
||||
t.Cleanup(func() {
|
||||
types.MaxWasmSize = originalMaxWasmSize
|
||||
})
|
||||
|
||||
// when snapshot imported into dest app instance
|
||||
destWasmApp := app.SetupWithEmptyStore(t)
|
||||
require.NoError(t, destWasmApp.SnapshotManager().Restore(*snapshot))
|
||||
|
||||
Reference in New Issue
Block a user