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

Problem: no header hash from fallback historicalInfo #540

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (rpc) [#516](https://github.com/crypto-org-chain/ethermint/pull/516) Avoid method eth_chainId crashed due to nil pointer on IsEIP155 check.
* (cli) [#524](https://github.com/crypto-org-chain/ethermint/pull/524) Allow tx evm raw run for generate only when offline with evm-denom flag.
* (rpc) [#527](https://github.com/crypto-org-chain/ethermint/pull/527) Fix balance consistency between trace-block and state machine.
* (rpc) [#534](https://github.com/crypto-org-chain/ethermint/pull/534) Fix opBlockhash when no block header in abci request.
* (rpc) [#534](https://github.com/crypto-org-chain/ethermint/pull/534), [#540](https://github.com/crypto-org-chain/ethermint/pull/540) Fix opBlockhash when no block header in abci request.
* (rpc) [#536](https://github.com/crypto-org-chain/ethermint/pull/536) Fix validate basic after transaction conversion with raw field.
* (cli) [#537](https://github.com/crypto-org-chain/ethermint/pull/537) Fix unsuppored sign mode SIGN_MODE_TEXTUAL for bank transfer.

Expand Down
25 changes: 9 additions & 16 deletions tests/integration_tests/test_fee_history.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import hashlib
import json
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path

Expand All @@ -9,9 +8,9 @@
from .network import setup_custom_ethermint
from .utils import (
ADDRS,
approve_proposal,
eth_to_bech32,
send_transaction,
submit_gov_proposal,
w3_wait_for_block,
w3_wait_for_new_blocks,
)
Expand Down Expand Up @@ -167,27 +166,21 @@ def update_feemarket_param(node, tmp_path, new_multiplier=2, new_denominator=200
p["base_fee"] = new_base_fee
p["elasticity_multiplier"] = new_multiplier
p["base_fee_change_denominator"] = new_denominator
proposal = tmp_path / "proposal.json"

# governance module account as signer
data = hashlib.sha256("gov".encode()).digest()[:20]
signer = eth_to_bech32(data)
proposal_src = {
"messages": [
authority = eth_to_bech32(data)
submit_gov_proposal(
node,
tmp_path,
messages=[
{
"@type": "/ethermint.feemarket.v1.MsgUpdateParams",
"authority": signer,
"authority": authority,
"params": p,
}
],
"deposit": "2aphoton",
"title": "title",
"summary": "summary",
}
proposal.write_text(json.dumps(proposal_src))
rsp = cli.submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(node, rsp)
print("check params have been updated now")
)
p = cli.get_params("feemarket")["params"]
assert p["base_fee"] == new_base_fee
assert p["elasticity_multiplier"] == new_multiplier
Expand Down
32 changes: 30 additions & 2 deletions tests/integration_tests/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import hashlib
import json
import re
import subprocess
Expand All @@ -14,7 +15,9 @@
CONTRACTS,
approve_proposal,
deploy_contract,
eth_to_bech32,
send_transaction,
submit_gov_proposal,
wait_for_block,
wait_for_port,
)
Expand Down Expand Up @@ -84,7 +87,7 @@
)


def test_cosmovisor_upgrade(custom_ethermint: Ethermint):
def test_cosmovisor_upgrade(custom_ethermint: Ethermint, tmp_path):
"""
- propose an upgrade and pass it
- wait for it to happen
Expand All @@ -100,7 +103,8 @@
old_erc20_balance = contract.caller.balanceOf(ADDRS["validator"])
print("old values", old_height, old_balance, old_base_fee)

target_height = w3.eth.block_number + 10
height_before = w3.eth.block_number
target_height = height_before + 10
print("upgrade height", target_height)

plan_name = "sdk50"
Expand Down Expand Up @@ -166,3 +170,27 @@
)
)
assert p == {"allowed_clients": ["06-solomachine", "07-tendermint", "09-localhost"]}

p = cli.get_params("evm")["params"]
header_hash_num = "2"
p["header_hash_num"] = header_hash_num
# governance module account as signer
data = hashlib.sha256("gov".encode()).digest()[:20]
authority = eth_to_bech32(data)
submit_gov_proposal(
custom_ethermint,
tmp_path,
messages=[
{
"@type": "/ethermint.evm.v1.MsgUpdateParams",
"authority": authority,
"params": p,
}
],
)
p = cli.get_params("evm")["params"]
assert p["header_hash_num"] == header_hash_num, p
contract, _ = deploy_contract(w3, CONTRACTS["TestBlockTxProperties"])
res = contract.caller.getBlockHash(height_before).hex()
blk = w3.eth.get_block(height_before)
assert f"0x{res}" == blk.hash.hex(), res

Check failure on line 196 in tests/integration_tests/test_upgrade.py

View workflow job for this annotation

GitHub Actions / integration_tests (upgrade)

test_cosmovisor_upgrade AssertionError: 0000000000000000000000000000000000000000000000000000000000000000 assert '0x0000000000000000000000000000000000000000000000000000000000000000' == '0x7258087dde956b57bbb4fd6f459e0fe2a408a44d86bb14ebf462f0b13d2cfb64' - 0x7258087dde956b57bbb4fd6f459e0fe2a408a44d86bb14ebf462f0b13d2cfb64 + 0x0000000000000000000000000000000000000000000000000000000000000000
15 changes: 15 additions & 0 deletions tests/integration_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,21 @@ def cb(attrs):
assert proposal["status"] == "PROPOSAL_STATUS_PASSED", proposal


def submit_gov_proposal(ethermint, tmp_path, **kwargs):
proposal = tmp_path / "proposal.json"
proposal_src = {
"title": "title",
"summary": "summary",
"deposit": "2aphoton",
**kwargs,
}
proposal.write_text(json.dumps(proposal_src))
rsp = ethermint.cosmos_cli().submit_gov_proposal(proposal, from_="community")
assert rsp["code"] == 0, rsp["raw_log"]
approve_proposal(ethermint, rsp)
print("check params have been updated now")


class ContractAddress(rlp.Serializable):
fields = [
("from", rlp.sedes.Binary()),
Expand Down
29 changes: 26 additions & 3 deletions x/evm/keeper/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"github.com/evmos/ethermint/x/evm/statedb"
"github.com/evmos/ethermint/x/evm/types"

cmttypes "github.com/cometbft/cometbft/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
ethtypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -100,16 +101,38 @@
if err != nil {
return common.Hash{}
}
if ctx.BlockHeight() < h {
latestHeight := ctx.BlockHeight()
if latestHeight < h {
return common.Hash{}
}
if ctx.BlockHeight() == h {
latest, err := ethermint.SafeUint64(latestHeight)
if err != nil {
return common.Hash{}

Check warning on line 110 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L110

Added line #L110 was not covered by tests
}
if latestHeight == h {
headerHash := ctx.HeaderHash()
if len(headerHash) != 0 {
return common.BytesToHash(headerHash)
}
}
return common.BytesToHash(k.GetHeaderHash(ctx, height))
hash := k.GetHeaderHash(ctx, height)
if len(hash) > 0 {
return common.BytesToHash(hash)

Check warning on line 120 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L118-L120

Added lines #L118 - L120 were not covered by tests
}
if height < latest-k.GetParams(ctx).HeaderHashNum {
return common.Hash{}

Check warning on line 123 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L122-L123

Added lines #L122 - L123 were not covered by tests
}
histInfo, err := k.stakingKeeper.GetHistoricalInfo(ctx, h)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
k.Logger(ctx).Debug("historical info not found", "height", h, "err", err.Error())
return common.Hash{}

Check warning on line 128 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L125-L128

Added lines #L125 - L128 were not covered by tests
}
header, err := cmttypes.HeaderFromProto(&histInfo.Header)
if err != nil {
k.Logger(ctx).Error("failed to cast tendermint header from proto", "error", err)
return common.Hash{}

Check warning on line 133 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L130-L133

Added lines #L130 - L133 were not covered by tests
}
return common.BytesToHash(header.Hash())

Check warning on line 135 in x/evm/keeper/state_transition.go

View check run for this annotation

Codecov / codecov/patch

x/evm/keeper/state_transition.go#L135

Added line #L135 was not covered by tests
}
}

Expand Down
Loading