Skip to content

Commit

Permalink
fix wasm statesync
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed May 13, 2024
1 parent 435cf96 commit afb31a6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 0 deletions.
Binary file added a.wasm
Binary file not shown.
13 changes: 13 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
customauthtx "github.com/classic-terra/core/v2/custom/auth/tx"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"

// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/v2/client/docs/statik"
Expand Down Expand Up @@ -237,6 +238,18 @@ func NewTerraApp(
app.SetPostHandler(postHandler)
app.SetEndBlocker(app.EndBlocker)

// must be before Loading version
// requires the snapshot store to be created and registered as a BaseAppOption
// see cmd/wasmd/root.go: 206 - 214 approx
if manager := app.SnapshotManager(); manager != nil {
err := manager.RegisterExtensions(
wasmkeeper.NewWasmSnapshotter(app.CommitMultiStore(), &app.WasmKeeper),
)
if err != nil {
panic(fmt.Errorf("failed to register snapshot extension: %s", err))
}
}

if loadLatest {
if err := app.LoadLatestVersion(); err != nil {
tmos.Exit(err.Error())
Expand Down
15 changes: 15 additions & 0 deletions lmao.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"code_bytes": "lmao",
"code_id": "3",
"code_info": {
"code_hash": "+bSrIgKlEQtlPn3+PkE7M20UI07UR9iC4dm9VRK0SJE=",
"creator": "terra15kc4dkquya20yx09avpdw8796unj709xuyxjyc",
"instantiate_config": {
"address": "",
"addresses": [],
"permission": "Everybody"
}
},
"pinned": false
}

17 changes: 17 additions & 0 deletions prop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"title": "Proposal to decrease MaxBlockSize",
"description": "Proposal to decrease MaxBlockSize from 5mb to 2mb to avoid peer-to-peer spams",

"changes": [
{
"subspace": "baseapp",
"key": "BlockParams",
"value": {
"max_bytes": "2000000",
"max_gas": "100000000"
}
}
],
"metadata": "AQ==",
"deposit": "1000000000000uluna"
}
Binary file added test2.wasm
Binary file not shown.
52 changes: 52 additions & 0 deletions verify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import json

# Load the JSON file
with open('mytestnet/config/genesis.json', 'r') as f:
data = json.load(f)

# Define the expected structure
expected_structure = {
"code_bytes": str,
"code_id": str,
"code_info": {
"code_hash": str,
"creator": str,
"instantiate_config": {
"address": str,
"addresses": list,
"permission": str
}
},
"pinned": bool
}

# Function to check if a dictionary matches the expected structure
# def check_structure(obj, expected):
# if isinstance(obj, dict):
# for key, value in expected.items():
# if key not in obj or not isinstance(obj[key], value):
# return False
# if isinstance(value, dict) and not check_structure(obj[key], value):
# return False
# return True
# return False

def check_structure(obj, expected):
if isinstance(obj, dict):
for key, value in expected.items():
if key not in obj:
return False
if isinstance(value, dict):
if not isinstance(obj[key], dict):
return False
if not check_structure(obj[key], value):
return False
elif not isinstance(obj[key], value):
return False
return True
return False

# Check each element in the codes array
for code in data['app_state']['wasm']['codes']:
if not check_structure(code, expected_structure):
print("Code structure is not as expected:", code)
Binary file added x/wasm/keeper/testdata/test.wasm
Binary file not shown.

0 comments on commit afb31a6

Please sign in to comment.