Skip to content

Commit

Permalink
no space left on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Jul 26, 2024
1 parent cadd4a0 commit 97affcd
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 147 deletions.
20 changes: 5 additions & 15 deletions integration_tests/configs/cosmovisor.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ config {
'app-config'+: {
'app-db-backend': 'rocksdb',
'minimum-gas-prices': '100000000000basetcro',
store:: super.store,
streamers:: super.streamers,
'iavl-lazy-loading':: super['iavl-lazy-loading'],
},
validators: [super.validators[0] {
'app-config':: super['app-config'],
'app-config'+: {
store: {
streamers: ['versiondb'],
},
},
}] + super.validators[1:],
genesis+: {
app_state+: {
Expand All @@ -28,22 +30,10 @@ config {
],
},
},
evm+: {
params+: {
// emulate the environment on production network
extra_eips: [
'2929',
'2200',
'1884',
'1344',
],
},
},
feemarket+: {
params+: {
no_base_fee: false,
base_fee:: super.base_fee,
initial_base_fee: super.base_fee,
},
},
gov: {
Expand Down
19 changes: 8 additions & 11 deletions integration_tests/configs/upgrade-test-package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ let
shortRev = builtins.substring 0 7 rev;
};
}).defaultNix;
# v0.7.0
released_0 = (fetchFlake "crypto-org-chain/cronos" "799ac47e293403bd57580d2ff96bb8d9851c3cde").default;
# v0.8.0
released_1 = (fetchFlake "crypto-org-chain/cronos" "2f2cc88b501b47149690fdef05afbbbe5bc116c9").default;
# v1.0.15
released_2 = (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
# v1.1.1
released_3 = (fetchFlake "crypto-org-chain/cronos" "10b8eeb9052e3c52aa59dec15f5d3aca781d1271").default;
releasedGenesis = (fetchFlake "crypto-org-chain/cronos" "1f5e2618362303d91f621b47cbc1115cf4fa0195").default;
# release/v1.1.x
released1_1 = (fetchFlake "crypto-org-chain/cronos" "69a80154b6b24fca15f3562e2c4b312ee1092220").default;
# release/v1.2.x
released1_2 = (fetchFlake "crypto-org-chain/cronos" "1aea999eef67a0a01b22422bad94b36e45b9759a").default;
current = pkgs.callPackage ../../. { };
in
pkgs.linkFarm "upgrade-test-package" [
{ name = "genesis"; path = released_0; }
{ name = "v0.7.0-hotfix"; path = released_1; }
{ name = "v1.0.0"; path = released_2; }
{ name = "v1.1.0"; path = released_3; }
{ name = "genesis"; path = releasedGenesis; }
{ name = "v1.1.0"; path = released1_1; }
{ name = "v1.2"; path = released1_2; }
{ name = "v1.3"; path = current; }
]
2 changes: 1 addition & 1 deletion integration_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ def test_submit_send_enabled(cronos, tmp_path):
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(cronos, rsp)
approve_proposal(cronos, rsp["events"])
print("check params have been updated now")
p = cli.query_bank_send()
assert sorted(p, key=lambda x: x["denom"]) == send_enable
4 changes: 2 additions & 2 deletions integration_tests/test_gov_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_evm_update_param(cronos, tmp_path):
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(cronos, rsp)
approve_proposal(cronos, rsp["events"])
print("check params have been updated now")
p = cli.query_params("evm")["params"]
assert not p["chain_config"]["merge_netsplit_block"]
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_gov_update_params(cronos, tmp_path):
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(cronos, rsp)
approve_proposal(cronos, rsp["events"])
print("check params have been updated now")
rsp = cli.query_params()
print("params", rsp)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_gravity.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def test_gov_token_mapping(gravity, tmp_path, is_legacy):
rsp = submit_proposal(cli, tmp_path, is_legacy, denom, crc21.address)
assert rsp["code"] == 0, rsp["raw_log"]

approve_proposal(gravity.cronos, rsp)
approve_proposal(gravity.cronos, rsp["events"])

print("check the contract mapping exists now")
rsp = cli.query_contract_by_denom(denom)
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/test_ibc_update_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ def check_status():
},
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(ibc.cronos, rsp)
approve_proposal(ibc.cronos, rsp["events"])
default_trust_period = "1209600s"
assert_trust_period(default_trust_period)
148 changes: 43 additions & 105 deletions integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
from pathlib import Path

import pytest
import requests
from pystarport import ports
from pystarport.cluster import SUPERVISOR_CONFIG_FILE

from .cosmoscli import DEFAULT_GAS_PRICE
from .network import Cronos, setup_custom_cronos
from .utils import (
ADDRS,
CONTRACTS,
KEYS,
approve_proposal,
deploy_contract,
edit_ini_sections,
get_consensus_params,
get_send_enable,
send_transaction,
sign_transaction,
wait_for_block,
wait_for_new_blocks,
wait_for_port,
Expand All @@ -36,6 +34,15 @@ def custom_cronos(tmp_path_factory):
yield from setup_cronos_test(tmp_path_factory)


def get_txs(base_port, end):
port = ports.rpc_port(base_port)
res = []
for h in range(1, end):
url = f"http://127.0.0.1:{port}/block_results?height={h}"
res.append(requests.get(url).json().get("result")["txs_results"])
return res


def init_cosmovisor(home):
"""
build and setup cosmovisor directory structure in each node's home directory
Expand Down Expand Up @@ -111,39 +118,8 @@ def exec(c, tmp_path_factory):
- it should work transparently
"""
cli = c.cosmos_cli()
port = ports.api_port(c.base_port(0))
w3 = c.w3
gas_price = w3.eth.gas_price
erc20 = deploy_contract(
w3,
CONTRACTS["TestERC20A"],
key=KEYS["validator"],
gas_price=gas_price,
)
tx = erc20.functions.transfer(ADDRS["community"], 10).build_transaction(
{
"from": ADDRS["validator"],
"gasPrice": gas_price,
}
)
signed = sign_transaction(w3, tx, KEYS["validator"])
txhash0 = w3.eth.send_raw_transaction(signed.rawTransaction)
receipt0 = w3.eth.wait_for_transaction_receipt(txhash0)
block0 = hex(receipt0["blockNumber"])
logs0 = w3.eth.get_logs({"fromBlock": block0, "toBlock": block0})

def assert_eth_call():
rsp = w3.eth.call(
{
"from": ADDRS["validator"],
"to": erc20.address,
"data": tx["data"],
},
block0,
)
assert (1,) == w3.codec.decode(("uint256",), rsp)

assert_eth_call()
base_port = c.base_port(0)
port = ports.api_port(base_port)
send_enable = [
{"denom": "basetcro", "enabled": False},
{"denom": "stake", "enabled": True},
Expand All @@ -160,16 +136,10 @@ def assert_eth_call():
fp.flush()

c.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_port(ports.evmrpc_port(c.base_port(0)))
wait_for_port(ports.evmrpc_port(base_port))
wait_for_new_blocks(cli, 1)

def do_upgrade(
plan_name,
target,
mode=None,
method="submit-legacy-proposal",
gas_prices=DEFAULT_GAS_PRICE,
):
def do_upgrade(plan_name, target, mode=None):
rsp = cli.gov_propose_legacy(
"community",
"software-upgrade",
Expand All @@ -178,69 +148,32 @@ def do_upgrade(
"title": "upgrade test",
"description": "ditto",
"upgrade-height": target,
"deposit": "1basetcro",
"deposit": "10000basetcro",
},
mode=mode,
method=method,
gas_prices=gas_prices,
)
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(c, rsp, gas_prices=gas_prices)
approve_proposal(c, rsp["logs"][0]["events"])

# update cli chain binary
c.chain_binary = (
Path(c.chain_binary).parent.parent.parent / f"{plan_name}/bin/cronosd"
)
# block should pass the target height
wait_for_block(c.cosmos_cli(), target + 2, timeout=480)
wait_for_port(ports.rpc_port(c.base_port(0)))

target1 = cli.block_height() + 15
print("upgrade v0.8.0 height", target1)
gas_prices = "5000000000000basetcro"
do_upgrade(
"v0.7.0-hotfix",
target1,
"block",
method="submit-proposal",
gas_prices=gas_prices,
)
cli = c.cosmos_cli()

target2 = cli.block_height() + 15
print("upgrade v1.0 height", target2)
do_upgrade(
"v1.0.0",
target2,
"block",
method="submit-proposal",
gas_prices=gas_prices,
)
cli = c.cosmos_cli()

wait_for_port(ports.evmrpc_port(c.base_port(0)))

receipt = send_transaction(
c.w3,
{
"to": ADDRS["community"],
"value": 1000,
"maxFeePerGas": 10000000000000,
"maxPriorityFeePerGas": 10000,
},
)
assert receipt.status == 1
wait_for_port(ports.rpc_port(base_port))

# test migrate keystore
cli.migrate_keystore()
target3 = cli.block_height() + 15
print("upgrade v1.1 height", target3)
height = cli.block_height()
target_height0 = height + 15
print("upgrade v1.1 height", target_height0)

do_upgrade("v1.1.0", target3, "block", gas_prices=gas_prices)
do_upgrade("v1.1.0", target_height0, "block")
cli = c.cosmos_cli()

# check basic tx works
wait_for_port(ports.evmrpc_port(c.base_port(0)))
wait_for_port(ports.evmrpc_port(base_port))
receipt = send_transaction(
c.w3,
{
Expand All @@ -251,6 +184,9 @@ def do_upgrade(
},
)
assert receipt.status == 1
height = cli.block_height()
target_height1 = height + 15
print("upgrade v1.2 height", target_height1)

w3 = c.w3
random_contract = deploy_contract(
Expand All @@ -269,13 +205,11 @@ def do_upgrade(
)
print("old values", old_height, old_balance, old_base_fee)

target4 = cli.block_height() + 15
print("upgrade v1.3 height", target4)
do_upgrade("v1.3", target4, gas_prices=gas_prices)
do_upgrade("v1.2", target_height1)
cli = c.cosmos_cli()

# check basic tx works
wait_for_port(ports.evmrpc_port(c.base_port(0)))
wait_for_port(ports.evmrpc_port(base_port))
receipt = send_transaction(
c.w3,
{
Expand Down Expand Up @@ -304,7 +238,7 @@ def do_upgrade(
ADDRS["validator"]
)
# check consensus params
port = ports.rpc_port(c.base_port(0))
port = ports.rpc_port(base_port)
res = get_consensus_params(port, w3.eth.get_block_number())
assert res["block"]["max_gas"] == "60000000"

Expand All @@ -317,10 +251,10 @@ def do_upgrade(
max_callback_gas = cli.query_params()["max_callback_gas"]
assert max_callback_gas == "50000", max_callback_gas

e0 = cli.query_params("evm", height=target3 - 1)["params"]
e1 = cli.query_params("evm", height=target4 - 1)["params"]
f0 = cli.query_params("feemarket", height=target3 - 1)["params"]
f1 = cli.query_params("feemarket", height=target4 - 1)["params"]
e0 = cli.query_params("evm", height=target_height0 - 1)["params"]
e1 = cli.query_params("evm", height=target_height1 - 1)["params"]
f0 = cli.query_params("feemarket", height=target_height0 - 1)["params"]
f1 = cli.query_params("feemarket", height=target_height1 - 1)["params"]
assert e0["evm_denom"] == e1["evm_denom"] == "basetcro"

# update the genesis time = current time + 5 secs
Expand All @@ -336,14 +270,18 @@ def do_upgrade(
c.supervisorctl("start", "cronos_777-1-node0", "cronos_777-1-node1")
wait_for_new_blocks(c.cosmos_cli(), 1)

assert e0 == cli.query_params("evm", height=target3 - 1)["params"]
assert e1 == cli.query_params("evm", height=target4 - 1)["params"]
assert f0 == cli.query_params("feemarket", height=target3 - 1)["params"]
assert f1 == cli.query_params("feemarket", height=target4 - 1)["params"]
height = cli.block_height()
target_height2 = height + 15
print("upgrade v1.3 height", target_height2)
txs = get_txs(base_port, height)
do_upgrade("v1.3", target_height2)
assert txs == get_txs(base_port, height)

assert w3.eth.wait_for_transaction_receipt(txhash0)["logs"] == receipt0["logs"]
assert w3.eth.get_logs({"fromBlock": block0, "toBlock": block0}) == logs0
assert_eth_call()
cli = c.cosmos_cli()
assert e0 == cli.query_params("evm", height=target_height0 - 1)["params"]
assert e1 == cli.query_params("evm", height=target_height1 - 1)["params"]
assert f0 == cli.query_params("feemarket", height=target_height0 - 1)["params"]
assert f1 == cli.query_params("feemarket", height=target_height1 - 1)["params"]


def test_cosmovisor_upgrade(custom_cronos: Cronos, tmp_path_factory):
Expand Down
Loading

0 comments on commit 97affcd

Please sign in to comment.