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
chainntnfs+lnrpc/chainrpc: add ChainNotifier RPC subserver #2314
chainntnfs+lnrpc/chainrpc: add ChainNotifier RPC subserver #2314
Conversation
It doesn't build:
|
45fad52
to
431dbf1
Compare
Reminder: immediately send current block after |
Ntfr log not enabled in main |
Crash when spend ntfn without tx hash comes in:
After setting outpoint hard to nil in the sub server, this pr seems to work for me! |
ctrl-c on lnd:
|
df122a4
to
a5da112
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.
Solid PR, +1 for the embedded bug fix along the way. Could likely have been broken up into two distinct PRs, but too late for that as review/testing has already begun on this instance. The amount of duplication throughout the PR is rather painful...and something we're all aware of as far as a major issue within the notifier package in general. Not saying we need to address this now, but it's apparent that most of the size of this PR is due to all changes being 3x'd (sometimes more) across the sub-packages.
Occurs to me that we could even start to use this sub-server within the integration tests to obtain a very tight hook w.r.t when lnd
see certain transactions/blocks.
If there is so much duplication, can't more be extracted into reusable methods first and build the new functionality on top of that?
This is just automated output, if the code is slightly different it isn't reported by |
Tried to build several commits with |
Yes we plan to do that in the future, and have outlined what that would look like, but it's a much larger change the would modify the entire package vs this change that adds some new functionality. Was just pointing it out in the diff really, wasn't an attempt to convey that we should do it immediately. |
a5da112
to
e3ecc52
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.
great changes and refactoring! some comments from an initial pass, will circle back for a more thorough review 👍
e3ecc52
to
2831eab
Compare
Still many commits failing: |
2831eab
to
dc63149
Compare
dc63149
to
ff24faa
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.
Looking pretty good now, running on multiple nodes, just one notable comment I plan on investigating before we start merging this through. Also needs a rebase.
// known block, then we'll immediately dispatch | ||
// a notification for the current tip. | ||
if msg.bestBlock == nil { | ||
b.notifyBlockEpochClient( |
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.
How do the current sub-systems handle this extra notification? In operation things seem to be fine which is a good sign, but will take a look at the existing block epoch handling to ensure we're not missing any edge cases.
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 💎
Been testing on multiple nodes for the past week with no immediate issues. Once this is in, I'd say we need to put a hold on all other non abstraction adding changes to this section of the codebase. At the end of the day, there should be a single notifier, with distinct chain backends that simply notify us of new blocks, and give us a consistent view of re-orgs.
Needs a rebase.
These structs allow us to request notifications for either txids/outpoints or output scripts. We'll be using these in later commits to index confirmation and spend requests within the TxNotifier.
In this commit, we refactor the HeightHintCache and its underlying interfaces to be able to manipulate hints for ConfRequests and SpendRequests. By doing so, we'll be able to manipulate hints for scripts if the request includes either a zero hash or a zero outpoint.
In this commit, we modify the TxNotifier's ConnectTip method to also detect whether a registered script has been confirmed or spent on-chain by a transaction in the connected block. Once detected, notifications for them will be queued up for dispatch as with txids/outpoints. We've also refactored the ConnectTip method into smaller and reusable methods, which will serve useful later.
In this commit, we extend the BtcdNotifier to support registering scripts for confirmation notifications. Once the script has been detected as confirmed within the chain, a confirmation notification will be dispatched to through the Confirmed channel of the ConfirmationEvent returned upon registration. For scripts that have confirmed in the past, the `historicalConfDetails` method has been modified to skip the txindex and go straight to scanning the chain manually if confirmation request is for a script. When scanning the chain, we'll determine whether the script has been confirmed by locating the script in an output of a confirmed transaction. For scripts that have yet to confirm, they will be properly tracked within the TxNotifier.
In this commit, we extend the BitcoindNotifier to support registering scripts for confirmation notifications. Once the script has been detected as confirmed within the chain, a confirmation notification will be dispatched to through the Confirmed channel of the ConfirmationEvent returned upon registration. For scripts that have confirmed in the past, the `historicalConfDetails` method has been modified to skip the txindex and go straight to scanning the chain manually if confirmation request is for a script. When scanning the chain, we'll determine whether the script has been confirmed by locating the script in an output of a confirmed transaction. For scripts that have yet to confirm, they will be properly tracked within the TxNotifier.
In this commit, we extend the NeutrinoNotifier to support registering scripts for confirmation notifications. Once the script has been detected as confirmed within the chain, a confirmation notification will be dispatched to through the Confirmed channel of the ConfirmationEvent returned upon registration. For scripts that have confirmed in the past, the `historicalConfDetails` method has been modified to determine whether the script has been confirmed by locating the script in an output of a confirmed transaction. For scripts that have yet to confirm, a filter update is sent to the underlying rescan to ensure that we match and dispatch on the script when processing new blocks. Along the way, we also address an issue where we'd miss detecting that a transaction/script has confirmed in the future due to not receiving a historical dispatch request from the underlying txNotifier. To fix this, we ensure that we always update our filters to detect the confirmation at tip, regardless of whether a historical rescan was detected or not.
In this commit, we extend the BtcdNotifier to support registering scripts for spends notifications. Once the script has been detected as spent within the chain, a spend notification will be dispatched through the Spend channel of the SpendEvent returned upon registration. For scripts that have been spent in the past, the rescan logic has been modified to match on the script rather than the outpoint. This is done by encoding the script as an address. For scripts that are unspent, a request to the backend will be sent to alert the BtcdNotifier of when the script was spent by a transaction. To make this request we encode the script as an address, as this is what the backend uses to detect the spend. The transaction will then be proxied through the txUpdates concurrent queue, which will hand it off to the underlying txNotifier and dispatch spend notifications to the relevant clients. Along the way, we also address an issue where we'd miss detecting that an outpoint/script has been spent in the future due to not receiving a historical dispatch request from the underlying txNotifier. To fix this, we ensure that we always request the backend to notify us of the spend once it detects it at tip, regardless of whether a historical rescan was detected or not.
In this commit, we extend the BitcoindNotifier to support registering scripts for spends notifications. Once the script has been detected as spent within the chain, a spend notification will be dispatched through the Spend channel of the SpendEvent returned upon registration. For scripts that have been spent in the past, the rescan logic has been modified to match on the script rather than the outpoint. This is done by re-deriving the script of the output a transaction input is spending and checking whether it matches ours. For scripts that are unspent, a request to the backend will be sent to alert the BitcoindNotifier of when the script was spent by a transaction. To make this request we encode the script as an address, as this is what the backend uses to detect the spend. The transaction will then be proxied through the txUpdates concurrent queue, which will hand it off to the underlying txNotifier and dispatch spend notifications to the relevant clients. Along the way, we also address an issue where we'd miss detecting that an outpoint/script has been spent in the future due to not receiving a historical dispatch request from the underlying txNotifier. To fix this, we ensure that we always request the backend to notify us of the spend once it detects it at tip, regardless of whether a historical rescan was detected or not.
In this commit, we extend the NeutrinoNotifier to support registering scripts for spends notifications. Once the script has been detected as spent within the chain, a spend notification will be dispatched through the Spend channel of the SpendEvent returned upon registration. For scripts that have been spent in the past, the rescan logic has been modified to match on the script rather than the outpoint. A concurrent queue for relevant transactions has been added to proxy notifications from the underlying rescan to the txNotifier. This is needed for scripts, as we cannot perform a historical rescan for scripts through `GetUtxo`, like we do with outpoints. For scripts that are unspent, a filter update is sent to the underlying rescan to ensure that we match and dispatch on the script when processing new blocks. Along the way, we also address an issue where we'd miss detecting that an outpoint/script has been spent in the future due to not receiving a historical dispatch request from the underlying txNotifier. To fix this, we ensure that we always request the backend to notify us of the spend once it detects it at tip, regardless of whether a historical rescan was detected or not.
In this commit, we modify GetTestTxidAndScript to generate new P2PKH scripts. This is needed to properly test confirmations and spends of unique scripts on-chain within the set of interface-level test cases.
ff24faa
to
59e2be5
Compare
Rebased. |
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 🛡
PR shown to be functional with no major regressions in testing, landing this now so we can move on with our other projects that depend on this. Any additional review comments can be executed as follow up PRs, with any major changes blocked on further refactoring in this area.
In this PR, we introduce a new RPC subserver for lnd's ChainNotifier as defined in
chainnotifier.proto
. This new subserver has its own macaroon state and gives users a simplifiedinterface for a gRPC service that is able to dispatch notifications for blocks, transaction/script confirmations, and output/script spends.
In order to satisfy some of the requirements of the service, some changes were necessary to lnd's ChainNotifier. These changes include:
In order to enable this service, lnd must be built with the
chainrpc
build tag.Depends on #2291.