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

Add support for getLogs() on FilterAPI #199

Open
EnchanterIO opened this issue Aug 29, 2019 · 7 comments
Open

Add support for getLogs() on FilterAPI #199

EnchanterIO opened this issue Aug 29, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@EnchanterIO
Copy link
Contributor

Summary

Some web3 libraries such as https://www.npmjs.com/package/ethers and other projects have the necessity to filter Lightchain logs.

The web3 method is called getLogs() and translates to Geth API as eth_getLogs.

ethers/providers/json-rpc-provider.ts

            case 'getLogs':
                if (params.filter && params.filter.address != null) {
                    params.filter.address = getLowerCase(params.filter.address);
                }
                return this.send('eth_getLogs', [params.filter]);

Steps to resolve

  1. Implement func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([]*types.Log, error) {

Screen Shot 2019-08-29 at 15 26 02

From: go-ethereum/eth/filters/api.go

Something like this should work as fix:

lightchain/database/database.go

		if _, ok := v.Service.(*filters.PublicFilterAPI); ok {
			v.Service = filters.NewPublicFilterAPI(
				db.eth.APIBackend,
				false,
			)
		}
@EnchanterIO EnchanterIO added the bug Something isn't working label Aug 29, 2019
@ggarri
Copy link
Contributor

ggarri commented Aug 29, 2019

Test code

const { providers } = require("ethers");
const BlocksToScan = 6001; // Relayers re-register to the hub every 6000 blocks
const hubContractAddress = "0x511bed1c29bc163c96b7d4dde28c7e0590aa44f5";

(async () => {
  const jsonRpcProvider = new providers.JsonRpcProvider(
    "https://node.sirius.lightstreams.io"
  );
  const latestBlock = await jsonRpcProvider.getBlockNumber();
  console.log("latestBlock", latestBlock);
  const fromBlock = latestBlock - BlocksToScan;
  const relayAddedEvents = await jsonRpcProvider.getLogs({
    fromBlock,
    address: hubContractAddress
  });
  // never get a response
  console.log("relayAddedEvents", relayAddedEvents);
})();

@EnchanterIO
Copy link
Contributor Author

UPDATE: Seems like we have the filtering API in place without me writing any extra Lightchain code. I also wrote the tests for the Ethers.js library as we may use it a lot from now on and the filtering logic and everything seems to work on Standalone but I am having issues on Sirius. Investigating why.

Screen Shot 2019-08-30 at 14 59 13

@EnchanterIO
Copy link
Contributor Author

Hanging call:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x7A120", "address": "0xb4aB862fE086f5Baf4f81d8F1564E168d0731630", "topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"]}],"id":74}' https://node.sirius.lightstreams.io

@EnchanterIO
Copy link
Contributor Author

EnchanterIO commented Sep 3, 2019

HA. A working call:

~ $curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x8618C", "address": "0xDa8B4c62b70e4441a52c4a45829c64B97124DC7b"}],"id":161}' https://node.sirius.lightstreams.io

{"jsonrpc":"2.0","id":161,"result":[{"address":"0xda8b4c62b70e4441a52c4a45829c64b97124dc7b","topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x8619e","transactionHash":"0xe74b0c6f2c7db0690ba3c44f93486f00f3d35cadf42ad8d7bc53d0fc8c01f0b4","transactionIndex":"0x0","blockHash":"0xd1a855008bfd74f460e4efe85c315376088cd96e62d015739a770f3d7a21b697","logIndex":"0x0","removed":false}]}

The question is... what's the difference. ID seems to be irrelevant from Go code perspective.

Screen Shot 2019-09-03 at 11 22 30

@EnchanterIO
Copy link
Contributor Author

Additional reproducable hanging sandbox from Portis: https://codesandbox.io/s/lightstreams-get-logs-dquuh

@EnchanterIO
Copy link
Contributor Author

Testing differences between Geth versions 1.8.27 and 1.9.2.

Using Geth 1.9.2 with improved test suite logging and assertions as in commit below.

Truffle connected to Local Sirius

Screen Shot 2019-09-03 at 11 57 13

cURL connected to Local Sirius

~ $curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x86184", "address": "0xE499D895ECFB8d6474706072f0d367077B7924e6", "topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"]}],"id":161}' http://localhost:8545

{"jsonrpc":"2.0","id":161,"result":[{"address":"0xe499d895ecfb8d6474706072f0d367077b7924e6","topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x861e8","transactionHash":"0xb1b0aa655af9d5105ffbb6fe25c2a486d917dd953d4cd51a3e8d4e69bfe450ab","transactionIndex":"0x0","blockHash":"0x67fef288a0f323fb60825c695c4a23e164a5773a46609a813312b922da30c16e","logIndex":"0x0","removed":false}]}

Screen Shot 2019-09-03 at 12 00 01

cURL connected to Remote Sirius

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x86184", "address": "0xE499D895ECFB8d6474706072f0d367077B7924e6", "topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"]}],"id":161}' https://node.sirius.lightstreams.io

{"jsonrpc":"2.0","id":161,"result":[{"address":"0xe499d895ecfb8d6474706072f0d367077b7924e6","topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x861e8","transactionHash":"0xb1b0aa655af9d5105ffbb6fe25c2a486d917dd953d4cd51a3e8d4e69bfe450ab","transactionIndex":"0x0","blockHash":"0x67fef288a0f323fb60825c695c4a23e164a5773a46609a813312b922da30c16e","logIndex":"0x0","removed":false}]}

Works all like charm 👍

Using Geth 1.8.27 with improved test suite logging and assertions as in commit below.

... to be tested in few seconds

EnchanterIO added a commit that referenced this issue Sep 3, 2019
Fixes bug in cache memory size management.

PS: Missing hardcoded change: "return nil" in validateState() as well in core/block_validator.go
as validateBlock() otherwise the blocks are not compatible.
@EnchanterIO
Copy link
Contributor Author

Using Geth 1.8.27

lightchain $lightchain version
Version: 1.3.1 Fast && Safe

Truffle connected to Local Sirius

Screen Shot 2019-09-03 at 12 16 19

cURL connected to Local Sirius

Screen Shot 2019-09-03 at 12 17 29

~ $curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x86184", "address": "0x0ba10ec1CCEaF2f17f71f22284cfac876E916Dab", "topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"]}],"id":161}' http://localhost:8545

{"jsonrpc":"2.0","id":161,"result":[{"address":"0x0ba10ec1cceaf2f17f71f22284cfac876e916dab","topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x86201","transactionHash":"0x1716860f9bd41fe3e074c70ed30cdf337f8d638449332c3223282f5a8dcda612","transactionIndex":"0x0","blockHash":"0x839a6ac0ff7c7fe36c8e4f4aadf73eb4480b5992ebfa704a5bb3397378ed63a0","logIndex":"0x0","removed":false}]}

cURL connected to Remote Sirius

~ $curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"fromBlock": "0x86184", "address": "0x0ba10ec1CCEaF2f17f71f22284cfac876E916Dab", "topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"]}],"id":161}' https://node.sirius.lightstreams.io

{"jsonrpc":"2.0","id":161,"result":[{"address":"0x0ba10ec1cceaf2f17f71f22284cfac876e916dab","topics":["0xb84f62b93fd66a0d09e52bd30961fc71e750f3f1a9c1584fda93aa5e056e7f34"],"data":"0x0000000000000000000000000000000000000000000000000000000000000001","blockNumber":"0x86201","transactionHash":"0x1716860f9bd41fe3e074c70ed30cdf337f8d638449332c3223282f5a8dcda612","transactionIndex":"0x0","blockHash":"0x839a6ac0ff7c7fe36c8e4f4aadf73eb4480b5992ebfa704a5bb3397378ed63a0","logIndex":"0x0","removed":false}]}

Works all like charm as well 👍 hmmm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants