Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simulation: vanilla simulation tests #71

Merged
merged 13 commits into from
Jul 26, 2022
Merged

simulation: vanilla simulation tests #71

merged 13 commits into from
Jul 26, 2022

Conversation

SebastianElvis
Copy link
Member

@SebastianElvis SebastianElvis commented Jul 21, 2022

Partially fixes BM-79

This PR implements the support of all simulation tests specified in Makefile. Specifically, one can use make test-sim-<sim_test_name> to run a simulation test, which bootstraps a Babylon SimApp with random parameters and genesis files, triggers certain random operations, and verifies certain correctness properties. Note that make test and thus the current CI program does not trigger any simulation test.

The current Makefile provides the following simulation tests:

  • make test-sim-import-export
  • make test-sim-after-import
  • make test-sim-multi-seed-long
  • make test-sim-multi-seed-short
  • make test-sim-custom-genesis-multi-seed
  • make test-sim-profile
  • make test-sim-custom-genesis-fast
  • make test-sim-nondeterminism
  • make test-sim-benchmark
  • make test-sim-benchmark-invariants

At the moment, none of them is successful, since we haven't finished the implementation yet. Some sample simulation tests are attached below. This does not mean to be a blocker for our current work -- the integration test phase will happen after we finish implementing all the functionalities. It would be useful for us to find bugs early though.

I also marked @vitsalis as reviewer since Vitalis did the initial migration of /simapp so may have experience on debugging it. Thanks in advance!

Results of make test-sim-import-export

➜  babylon git:(simulation-tests) ✗ make test-sim-import-export
Running application import/export simulation. This may take several minutes...
Allocating 4 workers...
[W2] Worker is up and running
[W3] Worker is up and running
[W1] Worker is up and running
[W0] Worker is up and running
[W0] Spawned simulation with pid 92408 [seed=7 stdout=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-7-date-07-22-2022_151348.stdout stderr=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-7-date-07-22-2022_151348.stderr]
[W2] Spawned simulation with pid 92409 [seed=1 stdout=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-1-date-07-22-2022_151348.stdout stderr=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-1-date-07-22-2022_151348.stderr]
[W3] Spawned simulation with pid 92407 [seed=2 stdout=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-2-date-07-22-2022_151348.stdout stderr=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-2-date-07-22-2022_151348.stderr]
[W1] Spawned simulation with pid 92410 [seed=4 stdout=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-4-date-07-22-2022_151348.stdout stderr=/var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/app-simulation-seed-4-date-07-22-2022_151348.stderr]
exit status 1
[W0] Seed 7: FAILED
To reproduce run: go test ./simapp -run TestAppImportExport -Enabled=true -NumBlocks=50 -Genesis= -Verbose=true -Commit=true -Seed=7 -Period=5 -ExportParamsPath /var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/sim_params-7.json -ExportStatePath /var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/sim_state-7.json -v -timeout 24h
ERROR OUTPUT

exit status 1
panic: halting simulations

goroutine 35 [running]:
main.worker(0x0, 0x0, 0x0)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/tools/cmd/runsim@v1.0.0/main.go:216 +0x62a
main.main.func2(0x0)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/tools/cmd/runsim@v1.0.0/main.go:160 +0x5c
created by main.main
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/tools/cmd/runsim@v1.0.0/main.go:158 +0xb87
make: *** [test-sim-import-export] Error 2
➜  babylon git:(simulation-tests) go test ./simapp -run TestAppImportExport -Enabled=true -NumBlocks=50 -Genesis= -Verbose=true -Commit=true -Seed=7 -Period=5 -ExportParamsPath /var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/sim_params-7.json -ExportStatePath /var/folders/nc/xylzz6v962z061mh6h5hdlp40000gn/T/sim-logs-3967573608/sim_state-7.json -v -timeout 24h
# github.com/keybase/go-keychain
cgo-gcc-prolog:81:11: warning: 'SecKeychainCreate' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:301:10: note: 'SecKeychainCreate' has been explicitly marked deprecated here
cgo-gcc-prolog:139:11: warning: 'SecKeychainLock' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:357:10: note: 'SecKeychainLock' has been explicitly marked deprecated here
cgo-gcc-prolog:159:11: warning: 'SecKeychainOpen' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:287:10: note: 'SecKeychainOpen' has been explicitly marked deprecated here
cgo-gcc-prolog:183:11: warning: 'SecKeychainUnlock' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:347:10: note: 'SecKeychainUnlock' has been explicitly marked deprecated here
cgo-gcc-prolog:203:11: warning: 'SecTrustedApplicationCreateFromPath' is deprecated: first deprecated in macOS 10.15 - No longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrustedApplication.h:59:10: note: 'SecTrustedApplicationCreateFromPath' has been explicitly marked deprecated here
# github.com/babylonchain/babylon/simapp.test
ld: warning: could not create compact unwind for _blst_sha256_block_data_order: does not use RBP or RSP based frame
=== RUN   TestAppImportExport
Starting SimulateFromSeed with randomness created with seed 7
Randomized simulation params:
{}
Selected randomly generated parameters for simulated genesis:
{
  stake_per_account: "25069342080",
  initially_bonded_validators: "243"
}
Selected randomly generated auth parameters:
{
 "max_memo_characters": 193,
 "tx_sig_limit": 5,
 "tx_size_cost_per_byte": 12,
 "sig_verify_cost_ed25519": 796,
 "sig_verify_cost_secp256k1": 548
}
Selected randomly generated bank parameters:
{
 "send_enabled": [
  {
   "denom": "stake",
   "enabled": true
  }
 ],
 "default_send_enabled": true
}
Selected randomly generated capability parameters:
{
 "index": 615,
 "owners": null
}
Selected randomly generated governance parameters:
{
 "starting_proposal_id": 14,
 "deposits": null,
 "votes": null,
 "proposals": null,
 "deposit_params": {
  "min_deposit": [
   {
    "denom": "stake",
    "amount": "390"
   }
  ],
  "max_deposit_period": 132396000000000
 },
 "voting_params": {
  "voting_period": 2987000000000
 },
 "tally_params": {
  "quorum": "0.493000000000000000",
  "threshold": "0.462000000000000000",
  "veto_threshold": "0.304000000000000000"
 }
}
Selected randomly generated minting parameters:
{
 "minter": {
  "inflation": "0.800000000000000000",
  "annual_provisions": "0.000000000000000000"
 },
 "params": {
  "mint_denom": "stake",
  "inflation_rate_change": "0.010000000000000000",
  "inflation_max": "0.200000000000000000",
  "inflation_min": "0.070000000000000000",
  "goal_bonded": "0.670000000000000000",
  "blocks_per_year": 6311520
 }
}
Selected randomly generated staking parameters:
{
 "unbonding_time": 89093000000000,
 "max_validators": 156,
 "max_entries": 7,
 "historical_entries": 5613,
 "bond_denom": "stake"
}
Selected randomly generated distribution parameters:
{
 "params": {
  "community_tax": "0.160000000000000000",
  "base_proposer_reward": "0.180000000000000000",
  "bonus_proposer_reward": "0.020000000000000000",
  "withdraw_addr_enabled": true
 },
 "fee_pool": {
  "community_pool": []
 },
 "delegator_withdraw_infos": null,
 "outstanding_rewards": null,
 "validator_accumulated_commissions": null,
 "validator_historical_rewards": null,
 "validator_current_rewards": null,
 "delegator_starting_infos": null,
 "validator_slash_events": null
}
Selected randomly generated slashing parameters:
{
 "params": {
  "signed_blocks_window": 439,
  "min_signed_per_window": "0.600000000000000000",
  "downtime_jail_duration": 12148000000000,
  "slash_fraction_double_sign": "0.021276595744680851",
  "slash_fraction_downtime": "0.020833333333333333"
 },
 "signing_infos": [],
 "missed_blocks": []
}
Selected randomly generated evidence parameters:
{}
Selected randomly generated epoching parameters:
{
 "epoch_interval": 141
}
Selected randomly generated consensus parameters:
{
 "block": {
  "max_bytes": 28429274,
  "max_gas": -1
 },
 "evidence": {
  "max_age_num_blocks": 14848,
  "max_age_duration": 89093000000000
 },
 "validator": {
  "pub_key_types": [
   "ed25519"
  ]
 }
}
I[2022-07-22|15:14:17.975] asserting crisis invariants                  module=x/crisis inv=0/11 name=gov/module-account
I[2022-07-22|15:14:17.975] asserting crisis invariants                  module=x/crisis inv=1/11 name=bank/nonnegative-outstanding
I[2022-07-22|15:14:17.976] asserting crisis invariants                  module=x/crisis inv=2/11 name=bank/total-supply
I[2022-07-22|15:14:17.977] asserting crisis invariants                  module=x/crisis inv=3/11 name=distribution/nonnegative-outstanding
I[2022-07-22|15:14:17.978] asserting crisis invariants                  module=x/crisis inv=4/11 name=distribution/can-withdraw
I[2022-07-22|15:14:17.994] asserting crisis invariants                  module=x/crisis inv=5/11 name=distribution/reference-count
I[2022-07-22|15:14:17.996] asserting crisis invariants                  module=x/crisis inv=6/11 name=distribution/module-account
I[2022-07-22|15:14:17.996] asserting crisis invariants                  module=x/crisis inv=7/11 name=staking/module-accounts
I[2022-07-22|15:14:17.997] asserting crisis invariants                  module=x/crisis inv=8/11 name=staking/nonnegative-power
I[2022-07-22|15:14:17.999] asserting crisis invariants                  module=x/crisis inv=9/11 name=staking/positive-delegation
I[2022-07-22|15:14:17.999] asserting crisis invariants                  module=x/crisis inv=10/11 name=staking/delegator-shares
I[2022-07-22|15:14:18.177] asserted all invariants                      module=x/crisis duration=202.010459ms height=0
--- FAIL: TestAppImportExport (0.71s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4eb71ac]

goroutine 28 [running]:
testing.tRunner.func1.2({0x50878e0, 0x6519ae0})
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1392 +0x39f
panic({0x50878e0, 0x6519ae0})
	/usr/local/Cellar/go/1.18.4/libexec/src/runtime/panic.go:838 +0x207
github.com/babylonchain/babylon/x/btclightclient/types.HeadersObjectKey(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/types/keys.go:35
github.com/babylonchain/babylon/x/btclightclient/keeper.headersState.CreateHeader({{0xa3771d8, 0xc000f7aa70}, {0x5aa69e0, 0xc00235e030}, {0x5aa69e0, 0xc00235e060}, {0x5aa69e0, 0xc00235e090}, {0x5aa69e0, 0xc00235e0c0}}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/state.go:41 +0x6c
github.com/babylonchain/babylon/x/btclightclient/keeper.Keeper.SetBaseBTCHeader({{0xa3771d8, 0xc000f7aa70}, {0x5a900a0, 0xc000f7a650}, {0x5a900a0, 0x0}, {0x5a917e8, 0x657d560}, {{0xa3771d8, 0xc000f7aa70}, ...}}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/base_btc_header.go:19 +0x266
github.com/babylonchain/babylon/x/btclightclient.InitGenesis({{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc00050e9c0}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, {0x0, ...}, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/genesis.go:13 +0x1d8
github.com/babylonchain/babylon/x/btclightclient.AppModule.InitGenesis({{{0xa3771d8, 0xc000f7aa70}}, {{0xa3771d8, 0xc000f7aa70}, {0x5a900a0, 0xc000f7a650}, {0x5a900a0, 0x0}, {0x5a917e8, 0x657d560}, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/module.go:152 +0x13e
github.com/cosmos/cosmos-sdk/types/module.(*Manager).InitGenesis(_, {{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc00050e9c0}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, ...}, ...}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/types/module/module.go:320 +0x29d
github.com/babylonchain/babylon/app.(*BabylonApp).InitChainer(_, {{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc00050e9c0}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/app/app.go:533 +0x20e
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).InitChain(0xc000ffc4e0, {{0x0, 0x48ff23b8f4, 0x6547760}, {0x52407d7, 0xe}, 0xc000679180, {0x0, 0x0, 0x0}, ...})
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/baseapp/abci.go:62 +0x455
github.com/cosmos/cosmos-sdk/x/simulation.initChain(0x0?, {0x3fed679087915380, 0x394, 0x3fcee5c9ad1a6d4c, {0xc0002790e0, _, _}, {_, _}, {_, ...}}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/x/simulation/simulate.go:43 +0x265
github.com/cosmos/cosmos-sdk/x/simulation.SimulateFromSeed({0x5aa9680?, 0xc000683860?}, {0x5a8d9e0?, 0xc00012a008}, 0x0?, _, _, {0xc00003e200, 0x1a, 0x20}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/x/simulation/simulate.go:77 +0x4d0
github.com/babylonchain/babylon/simapp.TestAppImportExport(0xc000683860)
	/Users/rhan0013/Projects/Babylon/babylon/simapp/sim_test.go:119 +0x5ec
testing.tRunner(0xc000683860, 0x58dd2c8)
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1486 +0x35f
FAIL	github.com/babylonchain/babylon/simapp	1.123s
FAIL

Results of make test-sim-benchmark

➜  babylon git:(simulation-tests) make test-sim-benchmark
Running application benchmark for numBlocks=500, blockSize=200. This may take awhile!
# github.com/keybase/go-keychain
cgo-gcc-prolog:81:11: warning: 'SecKeychainCreate' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:301:10: note: 'SecKeychainCreate' has been explicitly marked deprecated here
cgo-gcc-prolog:139:11: warning: 'SecKeychainLock' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:357:10: note: 'SecKeychainLock' has been explicitly marked deprecated here
cgo-gcc-prolog:159:11: warning: 'SecKeychainOpen' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:287:10: note: 'SecKeychainOpen' has been explicitly marked deprecated here
cgo-gcc-prolog:183:11: warning: 'SecKeychainUnlock' is deprecated: first deprecated in macOS 12.0 - Custom keychain management is no longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecKeychain.h:347:10: note: 'SecKeychainUnlock' has been explicitly marked deprecated here
cgo-gcc-prolog:203:11: warning: 'SecTrustedApplicationCreateFromPath' is deprecated: first deprecated in macOS 10.15 - No longer supported [-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/Security.framework/Headers/SecTrustedApplication.h:59:10: note: 'SecTrustedApplicationCreateFromPath' has been explicitly marked deprecated here
# github.com/babylonchain/babylon/simapp.test
ld: warning: could not create compact unwind for _blst_sha256_block_data_order: does not use RBP or RSP based frame
Starting SimulateFromSeed with randomness created with seed 42
Randomized simulation params:
{}
Selected randomly generated parameters for simulated genesis:
{
  stake_per_account: "452987287222",
  initially_bonded_validators: "246"
}
Selected randomly generated auth parameters:
{
 "max_memo_characters": 147,
 "tx_sig_limit": 6,
 "tx_size_cost_per_byte": 7,
 "sig_verify_cost_ed25519": 565,
 "sig_verify_cost_secp256k1": 567
}
Selected randomly generated bank parameters:
{
 "send_enabled": [
  {
   "denom": "stake",
   "enabled": true
  }
 ],
 "default_send_enabled": true
}
Selected randomly generated capability parameters:
{
 "index": 113,
 "owners": null
}
Selected randomly generated governance parameters:
{
 "starting_proposal_id": 61,
 "deposits": null,
 "votes": null,
 "proposals": null,
 "deposit_params": {
  "min_deposit": [
   {
    "denom": "stake",
    "amount": "682"
   }
  ],
  "max_deposit_period": 73290000000000
 },
 "voting_params": {
  "voting_period": 98099000000000
 },
 "tally_params": {
  "quorum": "0.404000000000000000",
  "threshold": "0.520000000000000000",
  "veto_threshold": "0.261000000000000000"
 }
}
Selected randomly generated minting parameters:
{
 "minter": {
  "inflation": "0.700000000000000000",
  "annual_provisions": "0.000000000000000000"
 },
 "params": {
  "mint_denom": "stake",
  "inflation_rate_change": "0.950000000000000000",
  "inflation_max": "0.200000000000000000",
  "inflation_min": "0.070000000000000000",
  "goal_bonded": "0.670000000000000000",
  "blocks_per_year": 6311520
 }
}
Selected randomly generated staking parameters:
{
 "unbonding_time": 462970000000000,
 "max_validators": 204,
 "max_entries": 7,
 "historical_entries": 1697,
 "bond_denom": "stake"
}
Selected randomly generated distribution parameters:
{
 "params": {
  "community_tax": "0.050000000000000000",
  "base_proposer_reward": "0.010000000000000000",
  "bonus_proposer_reward": "0.260000000000000000",
  "withdraw_addr_enabled": true
 },
 "fee_pool": {
  "community_pool": []
 },
 "delegator_withdraw_infos": null,
 "outstanding_rewards": null,
 "validator_accumulated_commissions": null,
 "validator_historical_rewards": null,
 "validator_current_rewards": null,
 "delegator_starting_infos": null,
 "validator_slash_events": null
}
Selected randomly generated slashing parameters:
{
 "params": {
  "signed_blocks_window": 803,
  "min_signed_per_window": "0.400000000000000000",
  "downtime_jail_duration": 18794000000000,
  "slash_fraction_double_sign": "0.027777777777777778",
  "slash_fraction_downtime": "0.015384615384615385"
 },
 "signing_infos": [],
 "missed_blocks": []
}
Selected randomly generated evidence parameters:
{}
Selected randomly generated epoching parameters:
{
 "epoch_interval": 205
}
Selected randomly generated consensus parameters:
{
 "block": {
  "max_bytes": 29380421,
  "max_gas": -1
 },
 "evidence": {
  "max_age_num_blocks": 77161,
  "max_age_duration": 462970000000000
 },
 "validator": {
  "pub_key_types": [
   "ed25519"
  ]
 }
}
--- FAIL: TestFullAppSimulation (0.72s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4eb71ac]

goroutine 52 [running]:
testing.tRunner.func1.2({0x50878e0, 0x6519ae0})
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1392 +0x39f
panic({0x50878e0, 0x6519ae0})
	/usr/local/Cellar/go/1.18.4/libexec/src/runtime/panic.go:838 +0x207
github.com/babylonchain/babylon/x/btclightclient/types.HeadersObjectKey(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/types/keys.go:35
github.com/babylonchain/babylon/x/btclightclient/keeper.headersState.CreateHeader({{0xe45e138, 0xc0000fc3e0}, {0x5aa69e0, 0xc001bc8480}, {0x5aa69e0, 0xc001bc84b0}, {0x5aa69e0, 0xc001bc84e0}, {0x5aa69e0, 0xc001bc8510}}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/state.go:41 +0x6c
github.com/babylonchain/babylon/x/btclightclient/keeper.Keeper.SetBaseBTCHeader({{0xe45e138, 0xc0000fc3e0}, {0x5a900a0, 0xc0000fd990}, {0x5a900a0, 0x0}, {0x5a917e8, 0x657d560}, {{0xe45e138, 0xc0000fc3e0}, ...}}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/base_btc_header.go:19 +0x266
github.com/babylonchain/babylon/x/btclightclient.InitGenesis({{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc001bc5240}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, {0x0, ...}, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/genesis.go:13 +0x1d8
github.com/babylonchain/babylon/x/btclightclient.AppModule.InitGenesis({{{0xe45e138, 0xc0000fc3e0}}, {{0xe45e138, 0xc0000fc3e0}, {0x5a900a0, 0xc0000fd990}, {0x5a900a0, 0x0}, {0x5a917e8, 0x657d560}, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/module.go:152 +0x13e
github.com/cosmos/cosmos-sdk/types/module.(*Manager).InitGenesis(_, {{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc001bc5240}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, ...}, ...}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/types/module/module.go:320 +0x29d
github.com/babylonchain/babylon/app.(*BabylonApp).InitChainer(_, {{0x5a9f318, 0xc00012c008}, {0x5aa7d00, 0xc001bc5240}, {{0x0, 0x0}, {0x52407d7, 0xe}, 0x0, ...}, ...}, ...)
	/Users/rhan0013/Projects/Babylon/babylon/app/app.go:533 +0x20e
github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).InitChain(0xc00053c680, {{0x0, 0x12975e331b, 0x6547760}, {0x52407d7, 0xe}, 0xc0026e3be0, {0x0, 0x0, 0x0}, ...})
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/baseapp/abci.go:62 +0x455
github.com/cosmos/cosmos-sdk/x/simulation.initChain(0x0?, {0x3fd7dfb258cb3fc6, 0x3c7, 0x3fe354bca10516e8, {0xc000695e18, _, _}, {_, _}, {_, ...}}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/x/simulation/simulate.go:43 +0x265
github.com/cosmos/cosmos-sdk/x/simulation.SimulateFromSeed({0x5aa9680?, 0xc000683a00?}, {0x5a8d9e0?, 0xc00012a008}, 0x0?, _, _, {0xc000d80400, 0x1a, 0x20}, ...)
	/Users/rhan0013/go/pkg/mod/github.com/cosmos/cosmos-sdk@v0.45.4/x/simulation/simulate.go:77 +0x4d0
github.com/babylonchain/babylon/simapp.TestFullAppSimulation(0xc000683a00)
	/Users/rhan0013/Projects/Babylon/babylon/simapp/sim_test.go:81 +0x5e8
testing.tRunner(0xc000683a00, 0x58dd2e0)
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/Cellar/go/1.18.4/libexec/src/testing/testing.go:1486 +0x35f
exit status 2
FAIL	github.com/babylonchain/babylon/simapp	1.135s
FAIL
make: *** [test-sim-benchmark] Error 1

@SebastianElvis SebastianElvis marked this pull request as ready for review July 22, 2022 05:21
@aakoshh
Copy link
Contributor

aakoshh commented Jul 22, 2022

@SebastianElvis thank you for the detailed description and the log output, amazing job!

I see this:

panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4eb71ac]
...
github.com/babylonchain/babylon/x/btclightclient/types.HeadersObjectKey(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/types/keys.go:35
github.com/babylonchain/babylon/x/btclightclient/keeper.headersState.CreateHeader(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/state.go:41 +0x6c
github.com/babylonchain/babylon/x/btclightclient/keeper.Keeper.SetBaseBTCHeader(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/keeper/base_btc_header.go:19 +0x266
github.com/babylonchain/babylon/x/btclightclient.InitGenesis(...)
	/Users/rhan0013/Projects/Babylon/babylon/x/btclightclient/genesis.go:13 +0x1d8

which points here. It looks like hash is nil, perhaps? Isn't that a bug that could be fixed?

Or are you saying this doesn't work because the btclightclient doens't have the Simulation support yet?

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic! It would be great if @vitsalis could have a look at what exactly is happening during the Genesis setup of the BTC light client to cause a panic, but this is super useful!

simapp/utils.go Outdated
Comment on lines 17 to 18
// NOTE: this function is identical to https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go. The reason of migrating it here is that it uses the modules' flags initialised in `init()`. Otherwise, if using `sdksimapp.SetupSimulation`, then `sdksimapp.FlagEnabledValue` and `sdksimapp.FlagVerboseValue` will be used, rather than those in `config.go` of our module.
// The other functions under https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go do not access flags and thus can be reused safely.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NOTE: this function is identical to https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go. The reason of migrating it here is that it uses the modules' flags initialised in `init()`. Otherwise, if using `sdksimapp.SetupSimulation`, then `sdksimapp.FlagEnabledValue` and `sdksimapp.FlagVerboseValue` will be used, rather than those in `config.go` of our module.
// The other functions under https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go do not access flags and thus can be reused safely.
// NOTE: this function is identical to https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go.
// The reason of migrating it here is that it uses the modules' flags initialised in `init()`. Otherwise,
// if using `sdksimapp.SetupSimulation`, then `sdksimapp.FlagEnabledValue` and `sdksimapp.FlagVerboseValue`
// will be used, rather than those in `config.go` of our module. The other functions under
// https://github.com/cosmos/cosmos-sdk/blob/v0.45.5/simapp/utils.go do not access flags and thus can be reused safely.

@vitsalis
Copy link
Member

@SebastianElvis I took a look at the error and turns out that genesis was not setup properly for the btclightclient. Pushed a commit to address that. Now the command make test-sim-benchmark fails with the following:

Starting the simulation from time Sat Jun 30 10:50:28 UTC 7162 (unixtime 163859280628)
Simulating... block 1/500, operation 0/285. Logs to writing to <log_file>
--- FAIL: TestAppStateDeterminism (0.18s)
    simulate.go:300: error on block  1/500, operation (7/285) from x/staking:
        invalid message type in {MsgCreateValidator, MsgDelegate, MsgUndelegate, MsgBeginRedelegate} messages. use wrapped versions instead
        Comment: unable to deliver tx

@SebastianElvis
Copy link
Member Author

SebastianElvis commented Jul 25, 2022

Thanks for the fix!

Now the command make test-sim-benchmark fails with the following:

This issue is because Babylon rejects the existing message types in the staking module and instead requires their wrapped versions. Will investigate and fix (either in this PR or the subsequent ones depending on the complexity and scope). Thanks!

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, other than the error that is generated when running the sim commands. Nice catches with the sdksimapp structure!

@SebastianElvis
Copy link
Member Author

I have fixed the failure caused by unwrapped message types by ruling out simulated messages in the staking module. In addition, I disabled changing the epoch interval on-the-fly in the simulation since this causes errors in the simulation but won't happen in MVP.

Now the simulation can run, but still not successfully. I believe the issue is out of this PR's scope -- it will be gone after all modules implement the simulation support.

Sample log is attached.

sample.log

@SebastianElvis SebastianElvis merged commit 41ee6c8 into main Jul 26, 2022
@SebastianElvis SebastianElvis deleted the simulation-tests branch July 26, 2022 01:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants