Ganache-cli: eth_getFilterLogs returns empty array after eth_getTransactionReceipt return logs

Created on 1 Apr 2016  路  4Comments  路  Source: trufflesuite/ganache-cli

Hi.
When I'm running big test suits it reproduced 90% of the time. Here is the testrpc log:

eth_sendTransaction

  Gas usage: 102749
  Block Number: 0x09

eth_getTransactionByHash
eth_getTransactionReceipt
eth_getFilterLogs

Every time there is an event caused by transaction, most of the time eth_getFilterLogs produces nothing, while eth_getTransactionReceipt before it clearly reports that logs are there.
If I run this test without other tests, it always works.

If this is not a bug, than what am I really interested in, is how to know that logs from transaction is already there, so I can check there was or there wasn't any logs?

If you think that there might be a race condition, than there is probably not, cause I'm specifically calling eth_getFilterLogs after I'm sure there is logs in receipt.

All 4 comments

Similar problems for me when I'm trying to call myEvent.get(function(err,logs){...}); to get past events from a contract. logs is always empty. No error either.

myEvent.watch(function(err,res){...}) works fine however.

Are you guys passing filter parameters to event, i.e., in this example: https://github.com/ethereum/wiki/wiki/JavaScript-API#example-52

You can only get past logs if you specify fromBlock: 0.

As far as my research get me, you can't get past logs due to this: https://github.com/MetaMask/provider-engine/issues/1
But my problem is about latest block. Workaround that I'm using at the moment is:

  1. Setup events watcher (without polling)
  2. Get the transaction receipt, count logs there
  3. Do allEvents.get() repeatedly until it produced the number of events found in step 2
  4. Do myEvent.get() one time to get the events I'm looking for

In this way it is always working. But in some tests it takes up to 5 seconds before allEvents.get() produces all the events.

There's been a number of tickets like this, so here is my response I'm giving to all of them:

Apologies for the late response on this. I've written tests for events recently and they seem to work fine on the latest TestRPC. Please check my comment here: https://github.com/ethereumjs/testrpc/issues/118#issuecomment-232201066

It's likely that you're setting up your listener _after_ the TestRPC mines a block. Thus, the TestRPC is exposing a race condition in your application you didn't know you had. Always set up your listener _before_ making the transaction that fires the event.

Please reopen if you're still seeing this issue.

However, here's my individual response to this one:

As far as I can tell from web3, allEvents.get() isn't meant to be used to get all past events (at least, not until the beginning of time). Instead, it only gets all events since the event filter was created. For instance, check these tests here: https://github.com/ethereumjs/testrpc/blob/master/test/events.js

In this case, .get() appears to be working. Now, perhaps I don't understand your guy's expected use case, but so far the people who reported this issue suffered from a subtle race condition in their application: i.e., they made the transaction then started listening. Make sure you're you create you listen for your event first, then fire the transaction that produces the event. This is the only way to ensure there is no race condition in your application.

I'm trying to clean up all the issues here to better focus our work. Please reopen if you still have this issue, or if it is more subtle than I expect. Thanks for your guy's help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gskerry picture gskerry  路  3Comments

ralph-pichler picture ralph-pichler  路  6Comments

dwalintukan picture dwalintukan  路  6Comments

pradeeps picture pradeeps  路  6Comments

xavierlepretre picture xavierlepretre  路  5Comments