Skip to content

Commit 88691a6

Browse files
author
Antoine Riard
committed
Implement concurrent broadcast tolerance for distributed watchtowers
With a distrbuted watchtowers deployment, where each monitor is plugged to its own chain view, there is no guarantee that block are going to be seen in same order. Watchtower may diverge in their acceptance of a submitted `commitment_signed` update due to a block timing-out a HTLC and provoking a subset but yet not seen by the other watchtower subset. Any update reject by one of the watchtower must block offchain coordinator to move channel state forward and release revocation secret for previous state. In this case, we want any watchtower from the rejection subset to still be able to claim outputs if the concurrent state, has accepted by the other subset, is confirming. This improve overall watchtower system fault-tolerance. This change stores local commitment transaction unconditionally and fail the update if there is knowledge of an already signed commitment transaction (ChannelMonitor.local_tx_signed=true).
1 parent 343aacc commit 88691a6

File tree

2 files changed

+16
-28
lines changed

2 files changed

+16
-28
lines changed

lightning/src/ln/channelmonitor.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,10 @@ pub struct ChannelMonitor<ChanSigner: ChannelKeys> {
824824
// Set once we've signed a holder commitment transaction and handed it over to our
825825
// OnchainTxHandler. After this is set, no future updates to our holder commitment transactions
826826
// may occur, and we fail any such monitor updates.
827+
//
828+
// In case of update rejection due to a locally already signed commitment transaction, we
829+
// nevertheless store update content to track in case of concurrent broadcast by another
830+
// remote monitor out-of-order with regards to the block view.
827831
holder_tx_signed: bool,
828832

829833
// We simply modify last_block_hash in Channel's block_connected so that serialization is
@@ -888,6 +892,11 @@ pub trait ManyChannelMonitor: Send + Sync {
888892
///
889893
/// Any spends of outputs which should have been registered which aren't passed to
890894
/// ChannelMonitors via block_connected may result in FUNDS LOSS.
895+
///
896+
/// In case of distributed watchtowers deployment, even if an Err is return, the new version
897+
/// must be written to disk, as state may have been stored but rejected due to a block forcing
898+
/// a commitment broadcast. This storage is used to claim outputs of rejected state confirmed
899+
/// onchain by another watchtower, lagging behind on block processing.
891900
fn update_monitor(&self, funding_txo: OutPoint, monitor: ChannelMonitorUpdate) -> Result<(), ChannelMonitorUpdateErr>;
892901

893902
/// Used by ChannelManager to get list of HTLC resolved onchain and which needed to be updated
@@ -1167,12 +1176,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11671176
feerate_per_kw: initial_holder_commitment_tx.feerate_per_kw,
11681177
htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
11691178
};
1170-
// Returning a monitor error before updating tracking points means in case of using
1171-
// a concurrent watchtower implementation for same channel, if this one doesn't
1172-
// reject update as we do, you MAY have the latest holder valid commitment tx onchain
1173-
// for which you want to spend outputs. We're NOT robust again this scenario right
1174-
// now but we should consider it later.
1175-
onchain_tx_handler.provide_latest_holder_tx(initial_holder_commitment_tx).unwrap();
1179+
onchain_tx_handler.provide_latest_holder_tx(initial_holder_commitment_tx);
11761180

11771181
ChannelMonitor {
11781182
latest_update_id: 0,
@@ -1327,9 +1331,6 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13271331
/// up-to-date as our holder commitment transaction is updated.
13281332
/// Panics if set_on_holder_tx_csv has never been called.
13291333
pub(super) fn provide_latest_holder_commitment_tx_info(&mut self, commitment_tx: HolderCommitmentTransaction, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
1330-
if self.holder_tx_signed {
1331-
return Err(MonitorUpdateError("A holder commitment tx has already been signed, no new holder commitment txn can be sent to our counterparty"));
1332-
}
13331334
let txid = commitment_tx.txid();
13341335
let sequence = commitment_tx.unsigned_tx.input[0].sequence as u64;
13351336
let locktime = commitment_tx.unsigned_tx.lock_time as u64;
@@ -1343,17 +1344,13 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
13431344
feerate_per_kw: commitment_tx.feerate_per_kw,
13441345
htlc_outputs: htlc_outputs,
13451346
};
1346-
// Returning a monitor error before updating tracking points means in case of using
1347-
// a concurrent watchtower implementation for same channel, if this one doesn't
1348-
// reject update as we do, you MAY have the latest holder valid commitment tx onchain
1349-
// for which you want to spend outputs. We're NOT robust again this scenario right
1350-
// now but we should consider it later.
1351-
if let Err(_) = self.onchain_tx_handler.provide_latest_holder_tx(commitment_tx) {
1352-
return Err(MonitorUpdateError("Holder commitment signed has already been signed, no further update of LOCAL commitment transaction is allowed"));
1353-
}
1347+
self.onchain_tx_handler.provide_latest_holder_tx(commitment_tx);
13541348
self.current_holder_commitment_number = 0xffff_ffff_ffff - ((((sequence & 0xffffff) << 3*8) | (locktime as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor);
1355-
mem::swap(&mut new_holder_commitment_tx, &mut self.current_holder_commitment_tx);
1349+
mem::swap(&mut new_local_commitment_tx, &mut self.current_local_commitment_tx);
13561350
self.prev_holder_signed_commitment_tx = Some(new_holder_commitment_tx);
1351+
if self.holder_tx_signed {
1352+
return Err(MonitorUpdateError("Latest holder commitment signed has already been signed, update is rejected"));
1353+
}
13571354
Ok(())
13581355
}
13591356

lightning/src/ln/onchaintx.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -877,18 +877,9 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
877877
}
878878
}
879879

880-
pub(super) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) -> Result<(), ()> {
881-
// To prevent any unsafe state discrepancy between offchain and onchain, once holder
882-
// commitment transaction has been signed due to an event (either block height for
883-
// HTLC-timeout or channel force-closure), don't allow any further update of holder
884-
// commitment transaction view to avoid delivery of revocation secret to counterparty
885-
// for the aformentionned signed transaction.
886-
if self.holder_htlc_sigs.is_some() || self.prev_holder_htlc_sigs.is_some() {
887-
return Err(());
888-
}
880+
pub(super) fn provide_latest_holder_tx(&mut self, tx: HolderCommitmentTransaction) {
889881
self.prev_holder_commitment = self.holder_commitment.take();
890882
self.holder_commitment = Some(tx);
891-
Ok(())
892883
}
893884

894885
fn sign_latest_holder_htlcs(&mut self) {

0 commit comments

Comments
 (0)