Skip to content

Commit bf1b8ec

Browse files
author
Antoine Riard
committed
Check if funding transaction is final for propagation
If the funding transaction is timelocked beyond the next block of our best known chain tip, return an APIError instead of silently failing at broadcast attempt.
1 parent 22dc964 commit bf1b8ec

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,6 +2783,9 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
27832783
/// Returns an [`APIError::APIMisuseError`] if the funding_transaction spent non-SegWit outputs
27842784
/// or if no output was found which matches the parameters in [`Event::FundingGenerationReady`].
27852785
///
2786+
/// Returns [`APIError::APIMisueError`] if the funding transaction is not final for propagation
2787+
/// across the p2p network.
2788+
///
27862789
/// Returns [`APIError::ChannelUnavailable`] if a funding transaction has already been provided
27872790
/// for the channel or if the channel has been closed as indicated by [`Event::ChannelClosed`].
27882791
///
@@ -2810,6 +2813,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
28102813
});
28112814
}
28122815
}
2816+
{
2817+
let height = self.best_block.read().unwrap().height();
2818+
// Transactions are evaluated as final by network mempools at the next block.
2819+
if funding_transaction.lock_time < 500_000_000 && funding_transaction.lock_time > height + 1 {
2820+
return Err(APIError::APIMisuseError {
2821+
err: "Funding transaction asbolute timelock is non-final".to_owned()
2822+
});
2823+
}
2824+
}
28132825
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, |chan, tx| {
28142826
let mut output_index = None;
28152827
let expected_spk = chan.get_funding_redeemscript().to_v0_p2wsh();

0 commit comments

Comments
 (0)