-
Notifications
You must be signed in to change notification settings - Fork 30
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
Only fetch onchain transactions from LND within start_time and end_time range #202
Only fetch onchain transactions from LND within start_time and end_time range #202
Conversation
e0d6aac
to
74518d2
Compare
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.
Thanks for the improvement!
Can you please squash the commits?
a01826c
to
901eff5
Compare
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.
tACK, LGTM 🎉
Thanks a lot for the fix!
901eff5
to
771d1ae
Compare
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
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, thank you! 🎉
// certain range, we will apply a buffer on the time range which we use to | ||
// find start and end block heights. This should ensure we widen the block | ||
// height range enough to fetch all relevant transactions within a time range. | ||
const blockTimeRangeBuffer = time.Hour * 24 |
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.
While 24 hours seems like a safe bet, in practice we could probably lower this to 12 hours.
Ensure that the
NodeAudit
RPC makes use of the providedstart_time
andend_time
arguments, in the sense that Faraday will only query the LND backend for onchain transactions using a block height range which corresponds to thestart_time
andend_time
(with a buffer).Motivation and Context
The
NodeAudit
request can currently fail for old LND nodes, with a lot of historical onchain activity. Even if the caller provides a small time range to produce the report for. This is because currently all onchain transactions are fetched from the LND backend, and then filtered in memory based on the given time range.This PR aims to alleviate most of the problem by ensuring Faraday does not need to query the entire history of onchain transactions when the caller provides a time range for the report.
Related issue
#177
Implementation Notes
I did not find any obvious way to resolve a timestamp to a block height, which needs to be provided for the queries to the LND backend. For now I chose an approach where we do a binary search on the entire blockchain to find the block height just before the provided timestamp.
This means we need to look up several block headers for each timestamp we want to resolve. I think this approach is fine for now, and in this context, considering that this RPC is a slow and heavy one anyways. Worst case is that we need to fetch ~20 block headers per timestamp we look up.
Future improvements
If we want to optimize the timestamp to block height resolving more, we could make use of this public API endpoint: https://mempool.space/docs/api/rest#get-block-timestamp
This endpoint seems to do a lookup from an internal DB (see here), which is likely more performant. In that case the current binary search mechanism could serve as only a fallback for if the mempool.space API is unavailable
We can also make use of pagination when querying onchain activity from the LND backend. This seems to require changes in the lndclient repository as well, to ensure that the
GetTransactions
RPC can be called with aindex_offset
andmax_transactions
, like described herePull Request Checklist
MinLndVersion
if your PR uses new RPC methods or fields oflnd
.