-
Notifications
You must be signed in to change notification settings - Fork 367
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
Track confirmation block hash and return via Confirm::get_relevant_txids
#1796
Track confirmation block hash and return via Confirm::get_relevant_txids
#1796
Conversation
Marked draft for now, will switch after concept ACK. |
Codecov ReportBase: 90.78% // Head: 91.23% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1796 +/- ##
==========================================
+ Coverage 90.78% 91.23% +0.44%
==========================================
Files 87 89 +2
Lines 47604 50973 +3369
Branches 47604 50973 +3369
==========================================
+ Hits 43218 46503 +3285
- Misses 4386 4470 +84
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
c1d82ac
to
0ff16b4
Compare
Just discussed this with Matt in Discord, I'll count this as concept ACK. |
Would it be helpful to also return the confirmation height, so a user could trivially verify if a transaction has been dropped by knowing the depth of recent reorgs? |
Not sure, as the height to compare it to is always due to change meaning it may be ambiguous what 'recent reorgs' are. So including height might invite users to do some comparisons that are likely gonna be race-y again? |
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, feel free to squash.
This really needs some kind of testing. It should be pretty straightforward to just add relevant assertions in some of the existing reorg tests, I hope. |
cd2378a
to
c937807
Compare
Now added a test that we're indeed getting the expected confirmation block hash with c937807. Let me know if it's fine to squash. |
c937807
to
24c5dde
Compare
lightning/src/chain/onchaintx.rs
Outdated
@@ -548,7 +552,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> { | |||
/// `conf_height` represents the height at which the transactions in `txn_matched` were | |||
/// confirmed. This does not need to equal the current blockchain tip height, which should be | |||
/// provided via `cur_height`, however it must never be higher than `cur_height`. | |||
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) | |||
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, conf_hash: BlockHash, cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) |
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.
I know its not really your fault, but man this is confusing - update_claims_view
takes block hash and height parameters for "what block/height this tx was included in" but is often called without any txn and dummy (current block) values. Can we split the function in two and have the part that operates on txn_matched
be separate? Should be a straightforward change and would make this PR much more clearly correct.
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.
Now split the method into update_claims_view_from_requests
and update_claims_view_from_matched_txn
in 0f9fc8a. I also DRYed the onchain event processing that would always run into process_onchain_events_awaiting_threshold_conf
.
lightning/src/chain/onchaintx.rs
Outdated
/// `conf_height` represents the height at which the transactions in `txn_matched` were | ||
/// confirmed. This does not need to equal the current blockchain tip height, which should be | ||
/// provided via `cur_height`, however it must never be higher than `cur_height`. | ||
pub(crate) fn update_claims_view<B: Deref, F: Deref, L: Deref>(&mut self, txn_matched: &[&Transaction], requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L) | ||
pub(crate) fn update_claims_view_from_requests<B: Deref, F: Deref, L: Deref>(&mut self, | ||
requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B, |
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.
Should drop the conf_height
- nothing is being confirmed. Can also drop the corresponding docs which talk about txn_matched
.
Can you fix the above docs on conf_height
which mentions txn_matched
?
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.
Done hope I'm not misinterpreting something here:
$ git diff-tree -U2 0f9fc8a 84073d
diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs
index ee557eb7..8fbfa215 100644
--- a/lightning/src/chain/onchaintx.rs
+++ b/lightning/src/chain/onchaintx.rs
@@ -552,7 +552,7 @@ impl<ChannelSigner: Sign> OnchainTxHandler<ChannelSigner> {
/// preimage after force-close.
///
- /// `conf_height` represents the height at which the transactions in `txn_matched` were
- /// confirmed. This does not need to equal the current blockchain tip height, which should be
- /// provided via `cur_height`, however it must never be higher than `cur_height`.
+ /// `conf_height` represents the minimal height at which the request could get confirmed. This
+ /// does not need to equal the current blockchain tip height, which should be provided via
+ /// `cur_height`, however it must never be higher than `cur_height`.
pub(crate) fn update_claims_view_from_requests<B: Deref, F: Deref, L: Deref>(&mut self,
requests: Vec<PackageTemplate>, conf_height: u32, cur_height: u32, broadcaster: &B,
Basically LGTM, feel free to squash from my PoV, but will need re-review from multiple reviewers here. |
0f9fc8a
to
84073d6
Compare
Squashed commits. |
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
84073d6
to
1a9fec5
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.
Just some nits.
1a9fec5
to
e6b7bc2
Compare
Addressed nits, squashed again (and accidentally rebased on main in the process... Sorry 😢 ) |
e6b7bc2
to
1a80eac
Compare
Recovered the most recent base before the accident. So the latest squash diff is:
|
FWIW, in the future, the update_claims_view split could be in a separate commit. Not worth trying to split it now that its done, though. |
1a80eac
to
ee34469
Compare
Alright, split it out again. |
ee34469
to
2084f11
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.
Two doc nits, feel free to ignore unless/until you have more review comments from others.
2084f11
to
de9cd52
Compare
Previously, `Confirm::get_relevant_txids()` only returned a list of transactions that have to be monitored for reorganization out of the chain. This interface however required double bookkeeping: while we internally keep track of the best block, height, etc, it would also require the user to keep track which transaction was previously confirmed in which block and to take actions based on any change, e.g, to reconfirm them when the block would be reorged-out and the transactions had been reconfirmed in another block. Here, we track the confirmation block hash internally and return it via `Confirm::get_relevant_txids()` to the user, which alleviates the requirement for double bookkeeping: the user can now simply check whether the given transaction is still confirmed and in the given block, and take action if not. We also split `update_claims_view`: Previously it was one, now it's two methods: `update_claims_view_from_matched_txn` and `update_claims_view_from_requests`.
de9cd52
to
9685d6c
Compare
Addressed nits and squashed again, CI should be happy now. |
Didn't we go with two commits earlier? |
Yea, we did split it before, but not sure its worth bothering to hold this up more for that - the total diff is only +129 −60 so its not like its big enough that its hard to read. |
Previously,
Confirm::get_relevant_txids()
only returned a list of transactions that have to be monitored for reorganization out of the chain. This interface however required a double bookkeeping: while we internally keep track of the best block, height, etc, it would also require the user to keep track which transaction was previously confirmed in which block and to take actions based on any change, e.g, to reconfirm them when the block would be reorged-out and the transactions had been reconfirmed in another block.Here, we track the confirmation block hash internally and return it via
Confirm::get_relevant_txids()
to the user, which alleviates the requirement for double bookkeeping: the user can now simply check whether the given transactions are still confirmed via the given blocks, and take action if they are not.