-
Notifications
You must be signed in to change notification settings - Fork 5k
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
eth.getBlock sometimes returns an array #3568
Comments
@wbt To summarize, you're seeing
Questions
|
@cgewecke That seems almost correct, but I hesitate to say it's definitely an array of logs. The objects in the array have all the fields that a Log object should, but also include fields The behavior is occasional and appears non-deterministic, probably to the exact same degree that the order of arrival of past events is non-deterministic. (The program flow is that when an event comes in, it calls I am using a WebsocketProvider (ws) connected to geth running on localhost. The core of the revised test setup is:
The calling context does include this: |
@wbt Is it possible to show where/how |
@wbt What is the mining interval of your private network? |
@cgewecke It's a 5 second mining interval. The events being fetched for this test occurred during migrations, generally in the 2500-2800 block range, with no new events being added since, though the code is set up intending to handle any new events if they were to occur (they just aren't, in this testing).
Relevant snippet of where the events are getting fetched:
The call to |
FYI, I did go back and renamed |
Here is another clue: As a new first line in If I look at the transaction hashes in the I suspect that at some point in preparing data for the I am also observing the following, though I don't know if it's related: There are 66 unique events in the particular test set I am using at the moment, triggered by a slightly smaller number of unique transactions. If I add a log statement immediately before and immediately after the call to web3's |
Also as an FYI, I observe the same issue when using automining Ganche, with events in a different block range, so this makes me think it's less likely to actually be an issue in Geth. However, there's less randomness in Ganache. The array was returned on the same block info request, with the same set of logs (and therefore the same set of missing events), on 10/10 trials. Using Ganache seems to be a step toward reproducibility. |
Debugged in #3573. |
Expected behavior
web3.eth.getBlock "Returns a block matching the block number or block hash."
Actual behavior
In most cases, the expected behavior, but in some cases not. When I call
web3.eth.getBlock(blockNumber, function(error, blockData) {
...where blockNumber is a number (e.g. 2577),
blockData
typically contains an Object more or less as described in the documentation. However, sometimes, I get back an ARRAY containing Objects, but where the "blockNumber" field does not match the requested block number. These arrays range in length from 0 (empty), including 1, to 17 (probably higher, but this is what I've observed in limited testing).The object keys also look a little different, containing keys
address
(40-hex-digit string),topics
(an array of a couple 64-hex-digit strings),data
(320-hex-digit-string),blockNumber
(hex string without leading zeros padding it to a specific length, notably different fromnumber
as specified in the Block object),transactionHash
(64-hex-digit string),transactionIndex
(usually '0x0'),blockHash
(64-hex-digit string),logIndex
(usually '0x0'),removed
(usually false),gasLimit
(undefined),gasUsed
(undefined),size
(undefined),timestamp
(undefined), andnumber
(undefined).There is no
nonce
,hash
,from
,to
,value
,gas
,gasPrice
orinput
fields as in a Transaction object.My inspection of the object is within the callback, and the callback is defined in the call. The call is the primary/only contents of a Promise constructor in a wrapper function, which is called several times in different asynchronous chains kicked off by arrival of an event in the block for which data (specifically, the timestamp) is being requested. In repeated testing, I am getting the arrival of the exact same set of past events on the same contract on the same private chain running on Geth 1.9.1-stable. In these tests, the set of blocks for which an array is returned instead of a Block object seems random, with the probability of an array being returned somewhere around 1.5%.
Steps to reproduce the behavior
Unfortunately, I don't have reliable reproduction steps as the effect appears to be somewhat random.
Environment
npm 6.14.5, node v9.3.0, web3 1.2.7, Windows 10
The text was updated successfully, but these errors were encountered: