trufflesuite / ganache

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
2.62k stars 676 forks source link

Issues fetching logs in a fork mode #4074

Open benesjan opened 1 year ago

benesjan commented 1 year ago

Hello, I tried fetching a specific log topic from a block using the following command: curl http://127.0.0.1:8545/ -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"blockHash": "0xbbd9832d7b95ed3f989ed02f5c56721d6c1d6dce3675edb3b1446745a92a0ef5", "topics":["0x692cf5822a02f5edf084dc7249b3a06293621e069f11975ed70908ed10ed2e2c"]}],"id":1}'

when running ganache in a forked mode:

yarn ganache-cli --fork https://mainnet.infura.io/v3/MY_API_KEY

and I get the following response:

{"id":1,"jsonrpc":"2.0","result":[]}

when I request the data directly from mainnet I get the logs as expected:

{"jsonrpc":"2.0","id":1,"result":[{"address":"0xff1f2b4adb9df6fc8eafecdcbf96a2b351680455","blockHash":"0xbbd9832d7b95ed3f989ed02f5c56721d6c1d6dce3675edb3b1446745a92a0ef5","blockNumber":"0xf7ba95","data":"0x00000000000000000000000000000000000000000000000016f5542f3d78100000000000000000000000000000000000000000000000000019073d0ff485ac720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","logIndex":"0xa2","removed":false,"topics":["0x692cf5822a02f5edf084dc7249b3a06293621e069f11975ed70908ed10ed2e2c","0x000c7d713b49da00000000000000000000000000000000000000000200000006","0x000000000000000000000000000000000000000000000000000000000002d440"],"transactionHash":"0xb729f4470ef59d330f4939ef5215617b07ab65b2b6ea273fb2dc6e903df0edfa","transactionIndex":"0x4b"},{"address":"0xff1f2b4adb9df6fc8eafecdcbf96a2b351680455","blockHash":"0xbbd9832d7b95ed3f989ed02f5c56721d6c1d6dce3675edb3b1446745a92a0ef5","blockNumber":"0xf7ba95","data":"0x0000000000000000000000000000000000000000000000000bf810fb43b1a0000000000000000000000000000000000000000000000000000af867c43704f1ea0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000","logIndex":"0xac","removed":false,"topics":["0x692cf5822a02f5edf084dc7249b3a06293621e069f11975ed70908ed10ed2e2c","0x000de0b6b3a76400000000000000000000000000200000000000000000000006","0x000000000000000000000000000000000000000000000000000000000002d441"],"transactionHash":"0xb729f4470ef59d330f4939ef5215617b07ab65b2b6ea273fb2dc6e903df0edfa","transactionIndex":"0x4b"}]}

I am running currently the newest ganache:

image

When I start ganache it correctly displays the forked mode and I double checked that the infura URL is correct:

image

Any ideas what might be the issue? Thank you

MicaiahReid commented 1 year ago

This seems to be a bug to me. When getting logs if Ganache can't getNumberByHash, it returns nothing:

const blockNumber = await blockchain.blocks.getNumberFromHash(
  filter.blockHash
);
if (!blockNumber) return [];

and when trying to get the number by hash, we don't check the fork. We only check the local block indexes:

async getNumberFromHash(hash: string | Buffer | Tag) {
  return this.#blockIndexes.get(Data.toBuffer(hash)).catch(e => {
    if (e.status === NOTFOUND) return null;
    throw e;
  }) as Promise<Buffer | null>;
}
MicaiahReid commented 1 year ago

Related: #3692, #3739