Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit fac43e5

Browse files
authored
json-rpc(filters) fix block hash on newBlock filter (#1503)
* tests(filters) add block hash check on newBlock filter * tests(filters) fix linting errors * fix(filters): fix newBlock filter response * fix(filters): add changes on CHANGELOG file
1 parent 7f196ce commit fac43e5

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
102102
* (rpc) [#1405](https://github.com/evmos/ethermint/pull/1405) Fix uninitialized chain ID field in gRPC requests.
103103
* (analytics) [#1434](https://github.com/evmos/ethermint/pull/1434) Remove unbound labels from custom tendermint metrics.
104104
* (rpc) [#1484](https://github.com/evmos/ethermint/pull/1484) Align empty account result for old blocks as ethereum instead of return account not found error.
105+
* (rpc) [#1503](https://github.com/evmos/ethermint/pull/1503) Fix block hashes returned on JSON-RPC filter `eth_newBlockFilter`.
105106

106107

107108
## [v0.19.3] - 2022-10-14

rpc/namespaces/ethereum/eth/filters/api.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,9 @@ func (api *PublicFilterAPI) NewBlockFilter() rpc.ID {
292292
continue
293293
}
294294

295-
baseFee := types.BaseFeeFromEvents(data.ResultBeginBlock.Events)
296-
297-
header := types.EthHeaderFromTendermint(data.Header, ethtypes.Bloom{}, baseFee)
298295
api.filtersMu.Lock()
299296
if f, found := api.filters[headerSub.ID()]; found {
300-
f.hashes = append(f.hashes, header.Hash())
297+
f.hashes = append(f.hashes, common.BytesToHash(data.Header.Hash()))
301298
}
302299
api.filtersMu.Unlock()
303300
case <-errCh:

tests/integration_tests/test_filters.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ def test_pending_transaction_filter(cluster):
2121
txhash = send_successful_transaction(w3)
2222
assert txhash in flt.get_new_entries()
2323

24+
# check if tx_hash is valid
25+
tx = w3.eth.get_transaction(txhash)
26+
assert tx.hash == txhash
27+
2428
# without new txs since last call
2529
assert flt.get_new_entries() == []
2630

@@ -34,8 +38,14 @@ def test_block_filter(cluster):
3438

3539
# with tx
3640
send_successful_transaction(w3)
37-
blocks = flt.get_new_entries()
38-
assert len(blocks) >= 1
41+
block_hashes = flt.get_new_entries()
42+
assert len(block_hashes) >= 1
43+
44+
# check if the returned block hash is correct
45+
# getBlockByHash
46+
block = w3.eth.get_block(block_hashes[0])
47+
# block should exist
48+
assert block.hash == block_hashes[0]
3949

4050
# without new txs since last call
4151
assert flt.get_new_entries() == []

tests/integration_tests/utils.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from eth_account import Account
1313
from hexbytes import HexBytes
1414
from web3._utils.transactions import fill_nonce, fill_transaction_defaults
15+
from web3.exceptions import TimeExhausted
1516

1617
load_dotenv(Path(__file__).parent.parent.parent / "scripts/.env")
1718
Account.enable_unaudited_hdwallet_features()
@@ -149,17 +150,27 @@ def sign_transaction(w3, tx, key=KEYS["validator"]):
149150
return acct.sign_transaction(tx)
150151

151152

152-
def send_transaction(w3, tx, key=KEYS["validator"]):
153+
def send_transaction(w3, tx, key=KEYS["validator"], i=0):
154+
if i > 3:
155+
raise TimeExhausted
153156
signed = sign_transaction(w3, tx, key)
154157
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
155-
return w3.eth.wait_for_transaction_receipt(txhash)
158+
try:
159+
return w3.eth.wait_for_transaction_receipt(txhash, timeout=20)
160+
except TimeExhausted:
161+
return send_transaction(w3, tx, key, i + 1)
156162

157163

158-
def send_successful_transaction(w3):
164+
def send_successful_transaction(w3, i=0):
165+
if i > 3:
166+
raise TimeExhausted
159167
signed = sign_transaction(w3, {"to": ADDRS["community"], "value": 1000})
160168
txhash = w3.eth.send_raw_transaction(signed.rawTransaction)
161-
receipt = w3.eth.wait_for_transaction_receipt(txhash)
162-
assert receipt.status == 1
169+
try:
170+
receipt = w3.eth.wait_for_transaction_receipt(txhash, timeout=20)
171+
assert receipt.status == 1
172+
except TimeExhausted:
173+
return send_successful_transaction(w3, i + 1)
163174
return txhash
164175

165176

0 commit comments

Comments
 (0)