Browse Source

Add acknowledge message at the end of rollover

This is to avoid going on chain in a scenario where one party finished the rollover, while the other party ran into a timeout after send-/receiving the last message for the revoke-commit.
chore/leaner-release-process
Daniel Karzel 3 years ago
parent
commit
2781f57e29
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 16
      daemon/src/setup_contract.rs
  2. 12
      daemon/src/wire.rs

16
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, Msg3, 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};
@ -573,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,

12
daemon/src/wire.rs

@ -358,6 +358,7 @@ pub enum RollOverMsg {
Msg0(RollOverMsg0),
Msg1(RollOverMsg1),
Msg2(RollOverMsg2),
Msg3(RollOverMsg3),
}
#[derive(Debug, Serialize, Deserialize)]
@ -390,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)]
@ -404,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