Skip to content
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

getPastEvents only returns results if fromBlock is high enough #1297

Closed
JohanTh opened this issue Jan 17, 2018 · 7 comments
Closed

getPastEvents only returns results if fromBlock is high enough #1297

JohanTh opened this issue Jan 17, 2018 · 7 comments

Comments

@JohanTh
Copy link

JohanTh commented Jan 17, 2018

Using web3@1.0.0-beta.27.

Unless I have the fromBlock set to a too high number I get an error message when using getPastEvents. Setting it to 0 or removing it does not work. Depending on which address I am filtering on I have to set the fromBlock differently to not get this error message.

The error:

I20180117-00:31:35.710(1)? Error: CONNECTION ERROR: Couldn't connect to node on IPC.
I20180117-00:31:35.712(1)?     at Object.InvalidConnection (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\web3-core-helpers\src\errors.js:35:16)
I20180117-00:31:35.712(1)?     at WebsocketProvider._timeout (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\web3-providers-ws\src\index.js:192:48)
I20180117-00:31:35.713(1)?     at W3CWebSocket.connection.onclose (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\web3-providers-ws\src\index.js:96:15)
I20180117-00:31:35.713(1)?     at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\yaeti\lib\EventTarget.js:107:17)
I20180117-00:31:35.714(1)?     at W3CWebSocket.onClose (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\websocket\lib\W3CWebSocket.js:228:10)
I20180117-00:31:35.714(1)?     at WebSocketConnection.<anonymous> (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\websocket\lib\W3CWebSocket.js:201:17)
I20180117-00:31:35.715(1)?     at emitTwo (events.js:126:13)
I20180117-00:31:35.716(1)?     at WebSocketConnection.emit (events.js:214:7)
I20180117-00:31:35.716(1)?     at WebSocketConnection.drop (C:\Users\gatsu\Documents\Meteor\dapp\node_modules\websocket\lib\WebSocketConnection.js:468:14)
I20180117-00:31:35.717(1)?     at C:\Users\gatsu\Documents\Meteor\dapp\node_modules\websocket\lib\WebSocketConnection.js:301:18
I20180117-00:31:35.718(1)?     at _combinedTickCallback (internal/process/next_tick.js:131:7)
I20180117-00:31:35.718(1)?     at process._tickCallback (internal/process/next_tick.js:180:9)

My event:

const fromBlock = 0;
const toBlock = latestBlock.numer - 10000;

contract.getPastEvents("CreatorContent", {
  filter: {
    creator: address,
  },
  fromBlock: fromBlock,
  toBlock: toBlock,
}, (error, event) => {
  // ...
});
@JohanTh JohanTh changed the title getPastEvents only returns results if fromBlock is high enough getPastEvents only returns results if fromBlock is high enough Jan 17, 2018
@frozeman
Copy link
Contributor

Which node are you using, or infura?
normally if you dont send fromBlock its latest. Its shouldnt error though

@JohanTh
Copy link
Author

JohanTh commented Jan 17, 2018

I am running a gwhale node locally. Can it be a node setting issue?

I run this node using gwhale --syncmode "full" --cache=4096 --networkid 30373 --mine --minerthreads 1 --rpc --rpcapi="db,eth,net,web3,personal,web3" --rpccorsdomain="http://localhost:3000" --rpcport 8545 --ws --wsapi="db,eth,net,web3,personal,web3" --wsorigins="*" --wsport 8546 --datadir="D:\Eth\whalecoin" --etherbase="0x0c0d7a5b34321e436ce826a5dd56a9121cd54c49" console

Sorry, not providing a fromBlock gives an empty array as results but no error, so it's working when it's latest.

Could we find out why the connection closes?

@JohanTh
Copy link
Author

JohanTh commented Jan 19, 2018

This was a "max frame size" issue, I increased maxReceivedFrameSize and maxReceivedMessageSize to solve it in node_modules\websocket\lib\WebSocketClient.js and node_modules\websocket\lib\WebSocketServer.js.

@JohanTh JohanTh closed this as completed Jan 19, 2018
@eladmallel
Copy link

@JohanTh thanks for sharing this! could you please share how you increased these values?

was it by editing the npm module code directly? - for that you'd have to fork the library and then source your package from a git repo for this change to work anywhere (i.e. CI servers)

or was it a different approach somehow setting up your web3 client with a different configuration?

thanks!!

@JohanTh
Copy link
Author

JohanTh commented Sep 10, 2018

@eladmallel I edited the npm modules directly. Not the best way but works for me since my app was made for myself only so I did not bother forking.

@eladmallel
Copy link

@JohanTh thank you!

@daffl
Copy link
Contributor

daffl commented Sep 18, 2018

Made a comment how it can be done now without modifying your node modules in #1217 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants