From 592e81c8974f20d38e186d75ebaefade575e24af Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Thu, 30 Sep 2021 21:35:52 +1000 Subject: [PATCH] Re-trigger sending commit in case we start up in `PendingCommit` For now the behavior is: Once the user pressed the button commit will be published and also retried upon startup. --- daemon/src/maker_cfd.rs | 7 +++++++ daemon/src/model/cfd.rs | 4 ++++ daemon/src/taker_cfd.rs | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/daemon/src/maker_cfd.rs b/daemon/src/maker_cfd.rs index 8133915..b3d9c89 100644 --- a/daemon/src/maker_cfd.rs +++ b/daemon/src/maker_cfd.rs @@ -97,6 +97,13 @@ impl Actor { tracing::info!("Refund transaction published on chain: {}", txid); } + for cfd in cfds.iter().filter(|cfd| Cfd::is_pending_commit(cfd)) { + let signed_commit_tx = cfd.commit_tx()?; + let txid = wallet.try_broadcast_transaction(signed_commit_tx).await?; + + tracing::info!("Commit transaction published on chain: {}", txid); + } + Ok(Self { db, wallet, diff --git a/daemon/src/model/cfd.rs b/daemon/src/model/cfd.rs index 3736343..8349040 100644 --- a/daemon/src/model/cfd.rs +++ b/daemon/src/model/cfd.rs @@ -654,6 +654,10 @@ impl Cfd { matches!(self.state.clone(), CfdState::MustRefund { .. }) } + pub fn is_pending_commit(&self) -> bool { + matches!(self.state.clone(), CfdState::PendingCommit { .. }) + } + pub fn is_cleanup(&self) -> bool { matches!( self.state.clone(), diff --git a/daemon/src/taker_cfd.rs b/daemon/src/taker_cfd.rs index 46a91c4..9730787 100644 --- a/daemon/src/taker_cfd.rs +++ b/daemon/src/taker_cfd.rs @@ -90,6 +90,13 @@ impl Actor { tracing::info!("Refund transaction published on chain: {}", txid); } + for cfd in cfds.iter().filter(|cfd| Cfd::is_pending_commit(cfd)) { + let signed_commit_tx = cfd.commit_tx()?; + let txid = wallet.try_broadcast_transaction(signed_commit_tx).await?; + + tracing::info!("Commit transaction published on chain: {}", txid); + } + Ok(Self { db, wallet,