Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Smarter Tokens fetching #3546

Merged
merged 13 commits into from
Nov 23, 2016
Merged

Smarter Tokens fetching #3546

merged 13 commits into from
Nov 23, 2016

Conversation

ngotchac
Copy link
Contributor

WIP for #3240

It was useless to fetch data for each and every token on every new block.
Tokens data is not editable. Only meta data can be modified, so we just need to check for this specific event on new block only (no need to poll every second). Same for new tokens registered (might not even be that necessary...).

Fixes also an issue where all accounts were being checked for balances, even deleted ones.

@ngotchac ngotchac added A0-pleasereview 🤓 Pull request needs code review. M7-ui labels Nov 21, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 54e2844 on ng-smarter-contracts into ** on master**.

@@ -50,10 +51,15 @@ export function inHash (hash) {
return inHex(hash);
}

export function pad (input, length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we have this function already? (Seems duplicated)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pads the topics on the right

@@ -232,51 +233,102 @@ export default class Contract {
return this._subscribe(event, options, callback);
};

event.register = (options = {}, callback) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, not 100% sure I get the difference between event.register and event.subscribe - not from an API user POV.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The register method actually calls eth_getFilterChanges every second, which is unnecessary for getting token meta data updates (will be max a change for every block). We could actually call it every minute or so if needed...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, still unsure about how to explain this since it sits on the API interface. Obviously for any filter when pending is not included (toBlock) just calling the new filter on new blocks is more than enough. (Something to probably think about and enhance)

The case here is that we have 2 external APIs now - how does anybody decide what to use, seems we are making the external interface very complex now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess for filters querying pending blocks too it could be useful to query every second (not sure though). True from the API perspective, but didn't want to change the whole behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. As a dapp developer - what do I use? subscribe or register? As it stands the naming is almost interchangeable. We want things simple so people don't need to overthink things, but still allow them to do anything.

So to accomplish this, would have -

  1. not have yet another external interface event
  2. only polled for rapid changes when pending is the toBlock
  3. poll for filter changes on new blocks only when latest is toBlock
  4. when we poll for tokens, specify latest

... all wrapped in contracts.js. This way anybody using the API doesn't need to care about times and polling, the API just does the right thing, as asked. (Plus no confusion)

Copy link
Contributor Author

@ngotchac ngotchac Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this. First I wanted to call it manualSubscribe or something like that. Will fix

this._sendSubscriptionChanges();
}

_unsubscribeToChanges = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unsubscribeFromChanges? (;

@derhuerst
Copy link
Contributor

I haven't looked into this in detail, but at ng-smarter-contracts the events of my account 0x00D189b71E5b42a88aa3e83173D4a6926e665336 are not showing up, while on master, they are.

@ngotchac
Copy link
Contributor Author

The transactions ?

@derhuerst
Copy link
Contributor

@ngotchac

The transactions ?

Yes, may be related to master commits not merged into ng-smarter-contracts.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling ef2c170 on ng-smarter-contracts into ** on master**.

toBlock: 'latest'
}, (error, logs) => {
if (error) {
return console.error('balances::attachToNewToken', 'failed to attacht to tokenreg Registered', error.toString(), error.stack);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/attacht/attach/

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 7f36600 on ng-smarter-contracts into ** on master**.

@jacogr
Copy link
Contributor

jacogr commented Nov 22, 2016

Failing tests -


  1) api/contract/Contract subscribe valid events sets the subscriptionId returned:
     TransportError: eth_newFilter: undefined: undefined
      at http.js:77:25
      at process._tickCallback (internal/process/next_tick.js:103:7)

  2) api/contract/Contract subscribe valid events creates a new filter and retrieves the logs on it:
     TransportError: eth_newFilter: undefined: undefined
      at http.js:77:25
      at process._tickCallback (internal/process/next_tick.js:103:7)

  3) api/contract/Contract subscribe valid events returns the logs to the callback:
     TransportError: eth_newFilter: undefined: undefined
      at http.js:77:25
      at process._tickCallback (internal/process/next_tick.js:103:7)

@jacogr jacogr added A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. and removed A0-pleasereview 🤓 Pull request needs code review. labels Nov 22, 2016
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling f4f2c5e on ng-smarter-contracts into ** on master**.

@jacogr jacogr added the A8-looksgood 🦄 Pull request is reviewed well. label Nov 23, 2016
@jacogr jacogr removed the A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. label Nov 23, 2016
@jacogr jacogr merged commit 33dd491 into master Nov 23, 2016
@jacogr jacogr deleted the ng-smarter-contracts branch November 23, 2016 09:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants