-
Notifications
You must be signed in to change notification settings - Fork 345
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
Tx-Sync: Track spent WatchedOutput
s and re-add if unconfirmed
#2946
Tx-Sync: Track spent WatchedOutput
s and re-add if unconfirmed
#2946
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #2946 +/- ##
==========================================
+ Coverage 89.18% 90.01% +0.83%
==========================================
Files 117 117
Lines 95541 99416 +3875
Branches 95541 99416 +3875
==========================================
+ Hits 85205 89489 +4284
+ Misses 7840 7714 -126
+ Partials 2496 2213 -283 ☔ View full report in Codecov by Sentry. |
8ae8f02
to
0c8d233
Compare
Previously, we would track a spending transaction but wouldn't account for it being reorged out of the chain, in which case we wouldn't monitor the `WatchedOutput`s until they'd be reloaded on restart. Here, we keep any `WatchedOutput`s around until their spends are sufficiently confirmed and only prune them after `ANTI_REORG_DELAY`.
b1e51db
to
6ded069
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.
One nit, otherwise 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.
Looks good modulo the comments.
7253062
to
68c75dd
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. Feel free to squash.
@@ -342,15 +342,19 @@ where | |||
// unwrap() safety: len() > 0 is checked above | |||
let pos = *indexes.first().unwrap() as usize; | |||
if let Some(tx) = maybe_await!(self.client.get_tx(&txid))? { | |||
let txid = tx.txid(); | |||
if tx.txid() != *txid { |
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.
nit: may as well pass txid by value
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.
Previously, we would just push to the `confirmed_txs` `Vec`, leading to redundant `Confirm::transactions_confirmed` calls, especially now that we re-confirm previously disconnected spends. Here, we ensure that we don't push additional `ConfirmedTx` entries if already one with matching `Txid` is present. This not only gets rid of the spurious `transactions_confirmed` calls (which are harmless), but more importantly saves us from issuing unnecessary network calls, which improves latency.
d7dafc9
to
b71c6e2
Compare
Squashed commits and included the following changes: > git diff-tree -U2 d7dafc94 b71c6e2f6
diff --git a/lightning-transaction-sync/src/esplora.rs b/lightning-transaction-sync/src/esplora.rs
index e7952d6c2..538918ada 100644
--- a/lightning-transaction-sync/src/esplora.rs
+++ b/lightning-transaction-sync/src/esplora.rs
@@ -274,5 +274,5 @@ where
continue;
}
- if let Some(confirmed_tx) = maybe_await!(self.get_confirmed_tx(&txid, None, None))? {
+ if let Some(confirmed_tx) = maybe_await!(self.get_confirmed_tx(*txid, None, None))? {
confirmed_txs.push(confirmed_tx);
}
@@ -297,5 +297,5 @@ where
if let Some(confirmed_tx) = maybe_await!(self
.get_confirmed_tx(
- &spending_txid,
+ spending_txid,
spending_tx_status.block_hash,
spending_tx_status.block_height,
@@ -320,5 +320,5 @@ where
#[maybe_async]
fn get_confirmed_tx(
- &self, txid: &Txid, expected_block_hash: Option<BlockHash>, known_block_height: Option<u32>,
+ &self, txid: Txid, expected_block_hash: Option<BlockHash>, known_block_height: Option<u32>,
) -> Result<Option<ConfirmedTx>, InternalError> {
if let Some(merkle_block) = maybe_await!(self.client.get_merkle_block(&txid))? {
@@ -335,5 +335,5 @@ where
let mut indexes = Vec::new();
let _ = merkle_block.txn.extract_matches(&mut matches, &mut indexes);
- if indexes.len() != 1 || matches.len() != 1 || matches[0] != *txid {
+ if indexes.len() != 1 || matches.len() != 1 || matches[0] != txid {
log_error!(self.logger, "Retrieved Merkle block for txid {} doesn't match expectations. This should not happen. Please verify server integrity.", txid);
return Err(InternalError::Failed);
@@ -343,5 +343,5 @@ where
let pos = *indexes.first().unwrap() as usize;
if let Some(tx) = maybe_await!(self.client.get_tx(&txid))? {
- if tx.txid() != *txid {
+ if tx.txid() != txid {
log_error!(self.logger, "Retrieved transaction for txid {} doesn't match expectations. This should not happen. Please verify server integrity.", txid);
return Err(InternalError::Failed);
@@ -350,10 +350,10 @@ where
if let Some(block_height) = known_block_height {
// We can take a shortcut here if a previous call already gave us the height.
- return Ok(Some(ConfirmedTx { tx, txid: *txid, block_header, pos, block_height }));
+ return Ok(Some(ConfirmedTx { tx, txid, block_header, pos, block_height }));
}
let block_status = maybe_await!(self.client.get_block_status(&block_hash))?;
if let Some(block_height) = block_status.height {
- return Ok(Some(ConfirmedTx { tx, txid: *txid, block_header, pos, block_height }));
+ return Ok(Some(ConfirmedTx { tx, txid, block_header, pos, block_height }));
} else {
// If any previously-confirmed block suddenly is no longer confirmed, we found |
Fixes #2734.
Previously, we would track a spending transaction but wouldn't account for it being reorged out of the chain, in which case we wouldn't monitor the
WatchedOutput
s until they'd be reloaded on restart.In the first commit, we keep any
WatchedOutput
s around until their spends are sufficiently confirmed and only prune them afterANTI_REORG_DELAY
.Moreover, we dedup any
ConfirmedTx
s entries before handing them toConfirm::transactions_confirmed
. Previously, we would just push to theconfirmed_txs
Vec
, leading to redundantConfirm::transactions_confirmed
calls, especially now that we re-confirm previously disconnected spends.In the second commit, we ensure that we don't push additional
ConfirmedTx
entries if already one with matchingTxid
is present. This not only gets rid of the spurioustransactions_confirmed
calls (which are harmless), butmore importantly saves us from issuing unnecessary network calls, which improves latency.