erigontech / erigon

Ethereum implementation on the efficiency frontier https://erigon.gitbook.io
GNU Lesser General Public License v3.0
3.11k stars 1.09k forks source link

Wrong query result from database node #10267

Closed fridary closed 1 month ago

fridary commented 4 months ago

Erigon version: erigon version 2.59.3-088fd8ef OS & Version: Ubuntu 20.04.6 LTS Python: 3.11.7 web3py: 6.16.0 Erigon Command (with flags/config): ExecStart=/home/root/erigon/build/bin/erigon --internalcl --datadir=/disk_sde/erigon --http.api=eth,erigon,engine,web3,net,debug,trace,txpool --authrpc.jwtsecret=/home/root/erigon/jwtsecret --metrics --prune.h.before=13916166 --prune.r.before=13916166 --prune.t.before=13916166 --prune.c.before=13916166 --torrent.download.rate=128mb

I noticed weird bug: on my local node I am getting empty results when making query to node with web3py function get_logs(), although if I do the same query on any other public node, I am getting correct results (not empty). 1) Can someone please check on your node? Maybe there is a problem with indexing? Or I need to add extra flags/params to start Erigon?

Below example is to find OwnershipTransferred() event for contract 0x0000000004D5e7002012A80aE8c08d7339d22c91. On etherscan we can see this transaction 8 days ago: https://etherscan.io/tx/0x76b62531174e339a60e865afcc6296b6ae4dd4a5f59bfa464fb84cf0e07f2a4f

I want to clarify that Erigon works great, all other queries I can do with correct results (like eth_getTransactionReceipt) via RPC and with web3py. If I change fromBlock=1 to any other like fromBlock=19760000 10 days ago - the same results.

Code:

from web3 import Web3
import json

for testnet in ['http://127.0.0.1:8545', 'https://eth-pokt.nodies.app']:
    w3 = Web3(Web3.HTTPProvider(testnet))
    if not w3.is_connected():
        raise Exception("w3 not connected")

    print(f"last block:", w3.eth.block_number)
    contract = w3.eth.contract(address='0x0000000004D5e7002012A80aE8c08d7339d22c91', abi=json.loads('[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]'))
    events = contract.events.OwnershipTransferred.get_logs(fromBlock=1) # 19760000 (10 days ago) the same result
    print(f'result for {testnet}:')
    print(events)

Result:

last block: 19836132
result for http://127.0.0.1:8545:
()
last block: 19836132
result for https://eth-pokt.nodies.app:
(AttributeDict({'args': AttributeDict({'previousOwner': '0x0000000000000000000000000000000000000000', 'newOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222'}), 'event': 'OwnershipTransferred', 'logIndex': 366, 'transactionIndex': 174, 'transactionHash': HexBytes('0x76b62531174e339a60e865afcc6296b6ae4dd4a5f59bfa464fb84cf0e07f2a4f'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x8a3d7fa288eea48e5eb9036520ca7343d6876a1d543992a2b57b1d7bfb093e4b'), 'blockNumber': 19776554}), AttributeDict({'args': AttributeDict({'previousOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222', 'newOwner': '0x0000000000000000000000000000000000000000'}), 'event': 'OwnershipTransferred', 'logIndex': 292, 'transactionIndex': 137, 'transactionHash': HexBytes('0xefc5894e2688ea822880f0e038624948c096240c38d87cba7b13c3df4c103cdd'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x857d9529212ae678a5ad57070faef854758c8d90ed18f02e46652546df8859fe'), 'blockNumber': 19776762}))

update: I did this without web3py and getting absolutely the same result (so problem not in web3py). Code:

address = '0x0000000004D5e7002012A80aE8c08d7339d22c91'
event_signature_hash = w3.keccak(text="OwnershipTransferred(address,address)").hex()
events = requests.post(testnet, json={"method":"eth_getLogs","params":[{"fromBlock": 1, "address": address, "topics": [event_signature_hash]}],"id":1,"jsonrpc":"2.0"}, headers={"Content-Type": "application/json"}).json()['result']
shohamc1 commented 2 months ago

Hi, can you try on 2.60.2? I am unable to replicate the issue (on commit 2f41075a5).

last block: 20204731
result for http://127.0.0.1:8545:
(AttributeDict({'args': AttributeDict({'previousOwner': '0x0000000000000000000000000000000000000000', 'newOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222'}), 'event': 'OwnershipTransferred', 'logIndex': 366, 'transactionIndex': 174, 'transactionHash': HexBytes('0x76b62531174e339a60e865afcc6296b6ae4dd4a5f59bfa464fb84cf0e07f2a4f'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x8a3d7fa288eea48e5eb9036520ca7343d6876a1d543992a2b57b1d7bfb093e4b'), 'blockNumber': 19776554}), AttributeDict({'args': AttributeDict({'previousOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222', 'newOwner': '0x0000000000000000000000000000000000000000'}), 'event': 'OwnershipTransferred', 'logIndex': 292, 'transactionIndex': 137, 'transactionHash': HexBytes('0xefc5894e2688ea822880f0e038624948c096240c38d87cba7b13c3df4c103cdd'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x857d9529212ae678a5ad57070faef854758c8d90ed18f02e46652546df8859fe'), 'blockNumber': 19776762}))
last block: 20204731
result for https://eth-pokt.nodies.app:
(AttributeDict({'args': AttributeDict({'previousOwner': '0x0000000000000000000000000000000000000000', 'newOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222'}), 'event': 'OwnershipTransferred', 'logIndex': 366, 'transactionIndex': 174, 'transactionHash': HexBytes('0x76b62531174e339a60e865afcc6296b6ae4dd4a5f59bfa464fb84cf0e07f2a4f'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x8a3d7fa288eea48e5eb9036520ca7343d6876a1d543992a2b57b1d7bfb093e4b'), 'blockNumber': 19776554}), AttributeDict({'args': AttributeDict({'previousOwner': '0xd2192c3C3Af5a2eC1F2920171ACb94B6F6BF2222', 'newOwner': '0x0000000000000000000000000000000000000000'}), 'event': 'OwnershipTransferred', 'logIndex': 292, 'transactionIndex': 137, 'transactionHash': HexBytes('0xefc5894e2688ea822880f0e038624948c096240c38d87cba7b13c3df4c103cdd'), 'address': '0x0000000004D5e7002012A80aE8c08d7339d22c91', 'blockHash': HexBytes('0x857d9529212ae678a5ad57070faef854758c8d90ed18f02e46652546df8859fe'), 'blockNumber': 19776762}))
AskAlexSharov commented 1 month ago

closing as no activity. feel free to reopen