-
Notifications
You must be signed in to change notification settings - Fork 286
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 blockhash cache and allow user-supplied blockhash #102
Conversation
Codecov Report
@@ Coverage Diff @@
## master #102 +/- ##
==========================================
+ Coverage 88.02% 88.71% +0.68%
==========================================
Files 32 32
Lines 2130 2179 +49
==========================================
+ Hits 1875 1933 +58
+ Misses 255 246 -9 |
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.
LGTM! Just a small nit on type hinting.
self, | ||
endpoint: Optional[str] = None, | ||
commitment: Optional[Commitment] = None, | ||
blockhash_cache: Union[BlockhashCache, bool] = False, |
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.
blockhash_cache: Union[BlockhashCache, bool] = False, | |
blockhash_cache: Optional[BlockhashCache] = None, |
What is the purpose of Union[BlockhashCache, bool]
?
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.
Yeah, the idea here is just that the user can say blockhash_cache=True
and get the default cache behaviour without having to import the BlockhashCache
class.
Two changes here, for people who want to reduce RPC calls from fetching recent blockhashes:
Firstly, allow the user to pass a recent blockhash to
.send_transaction
and its dependent functions themselves. Useful for those who may want to run a separate loop to maintain a recent blockhash.Secondly, introduce an experimental (for now) blockhash cache that the user can opt in to. The blockhash cache works as follows:
ttl
seconds (defaults to 60).We prefer unused blockhashes because reusing blockhashes can cause errors in some edge cases,
and we prefer slightly older blockhashes because they're more likely to be accepted by every validator.
blockhash that is younger than
ttl
seconds.More discussion on the blockhash caching here https://discordapp.com/channels/791995070613159966/882624712813998121/888379125679685692
Bonus changes:
alt_stubbed_sender
fixture toasync_stubbed_sender
just so it's a little clearer what it's for.