Browse Source

Merge #724

724: Ack messages r=da-kami a=da-kami

This is a temporary workaround to avoid scenarios described in https://github.com/itchysats/itchysats/issues/364
Once we deal with incomplete DLCs this can go away.

Co-authored-by: Daniel Karzel <daniel@comit.network>
chore/leaner-release-process
bors[bot] 3 years ago
committed by GitHub
parent
commit
53a4c0536a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      daemon/src/setup_contract.rs
  2. 30
      daemon/src/wire.rs

31
daemon/src/setup_contract.rs

@ -2,7 +2,8 @@ use crate::model::cfd::{Cet, Dlc, RevokedCommit, Role};
use crate::model::{Leverage, Price, Usd};
use crate::tokio_ext::FutureExt;
use crate::wire::{
Msg0, Msg1, Msg2, RollOverMsg, RollOverMsg0, RollOverMsg1, RollOverMsg2, SetupMsg,
Msg0, Msg1, Msg2, Msg3, RollOverMsg, RollOverMsg0, RollOverMsg1, RollOverMsg2, RollOverMsg3,
SetupMsg,
};
use crate::{model, oracle, payout_curve, wallet};
use anyhow::{Context, Result};
@ -231,6 +232,8 @@ pub async fn new(
.merge(msg2.signed_lock)
.context("Failed to merge lock PSBTs")?;
tracing::info!("Exchanged signed lock transaction");
// TODO: In case we sign+send but never receive (the signed lock_tx from the other party) we
// need some fallback handling (after x time) to spend the outputs in a different way so the
// other party cannot hold us hostage
@ -271,7 +274,18 @@ pub async fn new(
})
.collect::<Result<HashMap<_, _>>>()?;
tracing::info!("Exchanged signed lock transaction");
// TODO: Remove send- and receiving ACK messages once we are able to handle incomplete DLC
// monitoring
sink.send(SetupMsg::Msg3(Msg3))
.await
.context("Failed to send Msg3")?;
let _ = stream
.select_next_some()
.timeout(Duration::from_secs(60))
.await
.context("Expected Msg3 within 60 seconds")?
.try_into_msg3()
.context("Failed to read Msg3")?;
Ok(Dlc {
identity: sk,
@ -560,6 +574,19 @@ pub async fn roll_over(
script_pubkey: dlc.commit.2.script_pubkey(),
});
// TODO: Remove send- and receiving ACK messages once we are able to handle incomplete DLC
// monitoring
sink.send(RollOverMsg::Msg3(RollOverMsg3))
.await
.context("Failed to send Msg3")?;
let _ = stream
.select_next_some()
.timeout(Duration::from_secs(60))
.await
.context("Expected Msg3 within 60 seconds")?
.try_into_msg3()
.context("Failed to read Msg3")?;
Ok(Dlc {
identity: sk,
identity_counterparty: dlc.identity_counterparty,

30
daemon/src/wire.rs

@ -209,6 +209,13 @@ pub enum SetupMsg {
/// Upon receiving this message from the other party we merge our signature and then the lock
/// tx is fully signed and can be published on chain.
Msg2(Msg2),
/// Message acknowledging that we received everything
///
/// Simple ACK message used at the end of the message exchange to ensure that both parties sent
/// and received everything and we did not run into timeouts on the other side.
/// This is used to avoid one party publishing the lock transaction while the other party ran
/// into a timeout.
Msg3(Msg3),
}
impl SetupMsg {
@ -235,6 +242,14 @@ impl SetupMsg {
bail!("Not Msg2")
}
}
pub fn try_into_msg3(self) -> Result<Msg3> {
if let Self::Msg3(v) = self {
Ok(v)
} else {
bail!("Not Msg3")
}
}
}
#[derive(Debug, Serialize, Deserialize)]
@ -334,12 +349,16 @@ pub struct Msg2 {
pub signed_lock: PartiallySignedTransaction, // TODO: Use binary representation
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Msg3;
#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "type", content = "payload")]
pub enum RollOverMsg {
Msg0(RollOverMsg0),
Msg1(RollOverMsg1),
Msg2(RollOverMsg2),
Msg3(RollOverMsg3),
}
#[derive(Debug, Serialize, Deserialize)]
@ -372,6 +391,14 @@ impl RollOverMsg {
bail!("Not Msg2")
}
}
pub fn try_into_msg3(self) -> Result<RollOverMsg3> {
if let Self::Msg3(v) = self {
Ok(v)
} else {
bail!("Not Msg3")
}
}
}
#[derive(Debug, Serialize, Deserialize)]
@ -386,6 +413,9 @@ pub struct RollOverMsg2 {
pub revocation_sk: SecretKey,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RollOverMsg3;
impl From<CfdTransactions> for RollOverMsg1 {
fn from(txs: CfdTransactions) -> Self {
let cets = txs

Loading…
Cancel
Save