-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Problem: can't get back tx result of false-failed tx (#438)
* Problem: can't get back tx result of false-failed tx Closes: #437 Solution: - Support fetch tx receipts by replaying block - add integration test * fix PR suggestions
- Loading branch information
Showing
16 changed files
with
1,043 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
dotenv: ../../scripts/.env | ||
cronos_777-1: | ||
cmd: cronosd | ||
start-flags: "--trace" | ||
app-config: | ||
minimum-gas-prices: 0basetcro | ||
json-rpc: | ||
address: "0.0.0.0:{EVMRPC_PORT}" | ||
ws-address: "0.0.0.0:{EVMRPC_PORT_WS}" | ||
api: "eth,net,web3,debug,cronos" | ||
evm: | ||
max-tx-gas-wanted: 0 | ||
validators: | ||
- coins: 1000000000000000000stake,10000000000000000000000basetcro | ||
staked: 1000000000000000000stake | ||
mnemonic: ${VALIDATOR1_MNEMONIC} | ||
- coins: 1000000000000000000stake,10000000000000000000000basetcro | ||
staked: 1000000000000000000stake | ||
mnemonic: ${VALIDATOR2_MNEMONIC} | ||
accounts: | ||
- name: community | ||
coins: 10000000000000000000000basetcro | ||
mnemonic: ${COMMUNITY_MNEMONIC} | ||
- name: signer1 | ||
coins: 20000000000000000000000basetcro | ||
mnemonic: ${SIGNER1_MNEMONIC} | ||
- name: signer2 | ||
coins: 30000000000000000000000basetcro | ||
mnemonic: ${SIGNER2_MNEMONIC} | ||
|
||
genesis: | ||
consensus_params: | ||
block: | ||
max_bytes: "1048576" | ||
max_gas: "815000" | ||
app_state: | ||
evm: | ||
params: | ||
evm_denom: basetcro | ||
cronos: | ||
params: | ||
cronos_admin: ${CRONOS_ADMIN} | ||
enable_auto_deployment: true | ||
ibc_cro_denom: ${IBC_CRO_DENOM} | ||
gov: | ||
voting_params: | ||
voting_period: "10s" | ||
deposit_params: | ||
max_deposit_period: "10s" | ||
min_deposit: | ||
- denom: "basetcro" | ||
amount: "1" | ||
transfer: | ||
params: | ||
receive_enabled: true | ||
send_enabled: true | ||
feemarket: | ||
params: | ||
no_base_fee: false | ||
initial_base_fee: 100000000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
import web3 | ||
from web3._utils.method_formatters import receipt_formatter | ||
from web3.datastructures import AttributeDict | ||
|
||
from .network import setup_custom_cronos | ||
from .utils import ADDRS, CONTRACTS, KEYS, deploy_contract, sign_transaction | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def custom_cronos(tmp_path_factory): | ||
path = tmp_path_factory.mktemp("cronos") | ||
yield from setup_custom_cronos( | ||
path, 26000, Path(__file__).parent / "configs/low_block_gas_limit.yaml" | ||
) | ||
|
||
|
||
def test_replay_block(custom_cronos): | ||
w3: web3.Web3 = custom_cronos.w3 | ||
contract = deploy_contract( | ||
w3, | ||
CONTRACTS["TestMessageCall"], | ||
key=KEYS["community"], | ||
) | ||
iterations = 400 | ||
gas_limit = 800000 | ||
for i in range(10): | ||
nonce = w3.eth.get_transaction_count(ADDRS["validator"]) | ||
txs = [ | ||
contract.functions.test(iterations).buildTransaction( | ||
{ | ||
"nonce": nonce, | ||
"gas": gas_limit, | ||
} | ||
), | ||
contract.functions.test(iterations).buildTransaction( | ||
{ | ||
"nonce": nonce + 1, | ||
"gas": gas_limit, | ||
} | ||
), | ||
] | ||
txhashes = [ | ||
w3.eth.send_raw_transaction(sign_transaction(w3, tx).rawTransaction) | ||
for tx in txs | ||
] | ||
receipt1 = w3.eth.wait_for_transaction_receipt(txhashes[0]) | ||
try: | ||
receipt2 = w3.eth.wait_for_transaction_receipt(txhashes[1], timeout=10) | ||
except web3.exceptions.TimeExhausted: | ||
# expected exception, tx2 is included but failed. | ||
receipt2 = None | ||
break | ||
if receipt1.blockNumber == receipt2.blockNumber: | ||
break | ||
print( | ||
"tx1 and tx2 are included in two different blocks, retry now.", | ||
receipt1.blockNumber, | ||
receipt2.blockNumber, | ||
) | ||
else: | ||
assert False, "timeout" | ||
assert not receipt2 | ||
# check sender's nonce is increased twice, which means both txs are executed. | ||
assert nonce + 2 == w3.eth.get_transaction_count(ADDRS["validator"]) | ||
rsp = w3.provider.make_request( | ||
"cronos_replayBlock", [hex(receipt1.blockNumber), False] | ||
) | ||
assert "error" not in rsp, rsp["error"] | ||
assert 2 == len(rsp["result"]) | ||
|
||
# check the replay receipts are the same | ||
replay_receipts = [AttributeDict(receipt_formatter(item)) for item in rsp["result"]] | ||
assert replay_receipts[0].gasUsed == replay_receipts[1].gasUsed == receipt1.gasUsed | ||
assert replay_receipts[0].status == replay_receipts[1].status == receipt1.status | ||
assert ( | ||
replay_receipts[0].logsBloom | ||
== replay_receipts[1].logsBloom | ||
== receipt1.logsBloom | ||
) | ||
assert replay_receipts[0].cumulativeGasUsed == receipt1.cumulativeGasUsed | ||
assert replay_receipts[1].cumulativeGasUsed == receipt1.cumulativeGasUsed * 2 | ||
|
||
# check the postUpgrade mode | ||
rsp = w3.provider.make_request( | ||
"cronos_replayBlock", [hex(receipt1.blockNumber), True] | ||
) | ||
assert "error" not in rsp, rsp["error"] | ||
assert 2 == len(rsp["result"]) | ||
replay_receipts = [AttributeDict(receipt_formatter(item)) for item in rsp["result"]] | ||
assert replay_receipts[1].status == 0 | ||
assert replay_receipts[1].gasUsed == gas_limit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.