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

BREAKING CHANGE: make getLatestBlockhash async #402

Merged
merged 30 commits into from
Apr 17, 2024

Conversation

Ansonhkg
Copy link
Collaborator

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

  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • yarn test:e2e:nodejs --filter=test-latest-blockhash.mjs

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link
Collaborator

@DashKash54 DashKash54 left a 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?

@glitch003
Copy link
Collaborator

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.

glitch003
glitch003 previously approved these changes Mar 19, 2024
Copy link
Collaborator

@glitch003 glitch003 left a 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

Copy link
Contributor

@MaximusHaximus MaximusHaximus left a 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.

  1. Can we move this code to live in core, since it is managing the same state as core does anyway?
  2. Can we avoid re-implementing 'get most common value' and error handling/logging, by instead adding the method core that calls this.connect() and then returns this.latestBlockhash?
  • We're already updating the latestBlockhash property during connect() 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.

@Ansonhkg Ansonhkg requested a review from MaximusHaximus March 20, 2024 08:17
@Ansonhkg
Copy link
Collaborator Author

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.

  1. Can we move this code to live in core, since it is managing the same state as core does anyway?
  2. Can we avoid re-implementing 'get most common value' and error handling/logging, by instead adding the method core that calls this.connect() and then returns this.latestBlockhash?
  • We're already updating the latestBlockhash property during connect() 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 :)

Copy link
Contributor

@MaximusHaximus MaximusHaximus left a 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.

@Ansonhkg Ansonhkg requested a review from MaximusHaximus March 21, 2024 11:08
@Ansonhkg
Copy link
Collaborator Author

Merge conflicts occurred after another PR was rebased and merged to master

MaximusHaximus
MaximusHaximus previously approved these changes Mar 25, 2024
Copy link
Contributor

@MaximusHaximus MaximusHaximus left a comment

Choose a reason for hiding this comment

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

👍 :shipit:

@MaximusHaximus
Copy link
Contributor

@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
joshLong145
joshLong145 previously approved these changes Apr 16, 2024
@Ansonhkg Ansonhkg requested a review from MaximusHaximus April 16, 2024 22:57
@joshLong145
Copy link

@MaximusHaximus conflicts are resolved can you re review?

@Ansonhkg Ansonhkg requested a review from jtary April 17, 2024 14:22
jtary
jtary previously approved these changes Apr 17, 2024
packages/core/src/lib/lit-core.ts Outdated Show resolved Hide resolved
@Ansonhkg Ansonhkg dismissed stale reviews from jtary and joshLong145 via 389bcc0 April 17, 2024 16:47
@Ansonhkg Ansonhkg requested review from jtary and joshLong145 April 17, 2024 16:47
@Ansonhkg Ansonhkg merged commit 83a070b into master Apr 17, 2024
4 checks passed
@Ansonhkg Ansonhkg deleted the feature/lit-2674-js-sdk-make-getlatestblockhash-async branch April 17, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants