-
Notifications
You must be signed in to change notification settings - Fork 73
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
BREAKING CHANGE: make getLatestBlockhash async #402
BREAKING CHANGE: make getLatestBlockhash async #402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also want to remove the poller? I don't see it being removed?
Also is the purpose of this PR to always pull the latest blockhash from the nodes before making a request?
packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Outdated
Show resolved
Hide resolved
packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Outdated
Show resolved
Hide resolved
this makes sense to me and looks good. i think we should add caching? if the block hash is less than 30s old, no need to talk to the nodes and get the latest? probably a good idea to prevent developers that like, accidentally call getLatestBlockhash() on every react re-render from hitting the nodes more than necessary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving pending resolution of open questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is re-implementing a lot of existing logic from lit-core
, where we do this exact process already during the connect()
flow. In fact, functionally it is the same, as it handshakes with all nodes, and even rebuilds the connectedNodes
, but in its current state it leaves connectedNodes
in an inconsistent state for the duration of this process -- while we're waiting on handshakes to return, the set will be mutated 'in place' - calling connect()
no longer does that as of LIT-2560 -- and this could possibly run multiple concurrent handshakes if the method is called multiple times close together, which connect()
will no longer do.
- Can we move this code to live in
core
, since it is managing the same state ascore
does anyway? - Can we avoid re-implementing 'get most common value' and error handling/logging, by instead adding the method
core
that callsthis.connect()
and then returnsthis.latestBlockhash
?
- We're already updating the
latestBlockhash
property duringconnect()
execution anyway, using another implementation that already gets the 'most common string' in the returned values from the nodes - We already have error handling and logging on fetching the blockhash from each node and an error is thrown if we fail to get the blockhash from any node
This method in lit-node-client
can then be delegated to the core
implementation.
When we find a better place to source latestBlockhash
from, we can replace the connect()
usage in lit-core
to be lighter-weight.
Great points! Made relevant changes :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lookin' good -- thanks for adding a test for it. Just a few things in-line.
packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts
Outdated
Show resolved
Hide resolved
…khash-async Signed-off-by: Anson <ansonox@gmail.com>
Merge conflicts occurred after another PR was rebased and merged to master |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@Ansonhkg I assume we want this to land in this week's release w/ other breaking changes -- LMK as soon as the conflicts are resolved and I'll re-add approved review so you can get it merged :). It sure will be nice when we get to the point that we're not modifying package.json in our feature PRs anymore :) |
…lit-2674-js-sdk-make-getlatestblockhash-async
@MaximusHaximus conflicts are resolved can you re review? |
Description
"so i was thinking about how we get the poller out of the JS SDK. the main issue is that
litNodeClient.getLatestBlockhash();
is not async. if we make it async, then we can remove the poller, and just get the latest block hash when they call that function. this is a breaking change, but def worth it IMO"Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: