Remove Refund timelock and T0/T1/T2

There are no refund timelock, only a cancellation timelock and punish
timelock.

Refund can be done as soon as the cancellation transaction is published.
This commit is contained in:
Franck Royer 2020-12-22 15:47:09 +11:00
parent 405e377f79
commit f0736d0906
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
11 changed files with 194 additions and 158 deletions

View file

@ -4,7 +4,7 @@ use crate::{
bob, monero,
monero::{CreateWalletForOutput, Transfer},
transport::{ReceiveMessage, SendMessage},
Epoch,
ExpiredTimelocks,
};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
@ -28,7 +28,9 @@ use std::{
use tokio::{sync::Mutex, time::timeout};
use tracing::{error, info};
pub mod message;
use crate::bitcoin::{current_epoch, wait_for_t1, BlockHeight, TransactionBlockHeight};
use crate::bitcoin::{
current_epoch, wait_for_cancel_timelock_to_expire, BlockHeight, TransactionBlockHeight,
};
pub use message::{Message, Message0, Message1, Message2};
#[derive(Debug)]
@ -74,7 +76,7 @@ pub fn action_generator<N, B>(
S_b_bitcoin,
v,
xmr,
refund_timelock,
cancel_timelock,
punish_timelock,
refund_address,
redeem_address,
@ -138,7 +140,7 @@ where
.await;
let poll_until_btc_has_expired = poll_until_block_height_is_gte(
bitcoin_client.as_ref(),
tx_lock_height + refund_timelock,
tx_lock_height + cancel_timelock,
)
.shared();
pin_mut!(poll_until_btc_has_expired);
@ -221,7 +223,7 @@ where
if let Err(SwapFailed::AfterXmrLock(Reason::BtcExpired)) = swap_result {
let refund_result: Result<(), RefundFailed> = async {
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, refund_timelock, a.public(), B);
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, cancel_timelock, a.public(), B);
let signed_tx_cancel = {
let sig_a = a.sign(tx_cancel.digest());
let sig_b = tx_cancel_sig_bob.clone();
@ -292,7 +294,7 @@ where
// with the refund on Monero. Doing so may be too verbose with the current,
// linear approach. A different design may be required
if let Err(RefundFailed::BtcPunishable) = refund_result {
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, refund_timelock, a.public(), B);
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, cancel_timelock, a.public(), B);
let tx_punish =
bitcoin::TxPunish::new(&tx_cancel, &punish_address, punish_timelock);
let tx_punish_txid = tx_punish.txid();
@ -410,7 +412,7 @@ impl State {
rng: &mut R,
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
redeem_address: bitcoin::Address,
punish_address: bitcoin::Address,
@ -425,7 +427,7 @@ impl State {
v_a,
btc,
xmr,
refund_timelock,
cancel_timelock,
punish_timelock,
redeem_address,
punish_address,
@ -441,7 +443,7 @@ pub struct State0 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
pub btc: bitcoin::Amount,
pub xmr: monero::Amount,
pub refund_timelock: u32,
pub cancel_timelock: u32,
pub punish_timelock: u32,
pub redeem_address: bitcoin::Address,
pub punish_address: bitcoin::Address,
@ -455,7 +457,7 @@ impl State0 {
v_a: monero::PrivateViewKey,
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
redeem_address: bitcoin::Address,
punish_address: bitcoin::Address,
@ -468,7 +470,7 @@ impl State0 {
punish_address,
btc,
xmr,
refund_timelock,
cancel_timelock,
punish_timelock,
}
}
@ -510,7 +512,7 @@ impl State0 {
v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: msg.refund_address,
redeem_address: self.redeem_address,
@ -530,7 +532,7 @@ pub struct State1 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -548,7 +550,7 @@ impl State1 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -569,7 +571,7 @@ pub struct State2 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -580,7 +582,7 @@ pub struct State2 {
impl State2 {
pub fn next_message(&self) -> Message1 {
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.a.public(), self.B);
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B);
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address);
// Alice encsigns the refund transaction(bitcoin) digest with Bob's monero
@ -599,7 +601,7 @@ impl State2 {
pub fn receive(self, msg: bob::Message2) -> Result<State3> {
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.a.public(), self.B);
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B);
bitcoin::verify_sig(&self.B, &tx_cancel.digest(), &msg.tx_cancel_sig)?;
let tx_punish =
bitcoin::TxPunish::new(&tx_cancel, &self.punish_address, self.punish_timelock);
@ -615,7 +617,7 @@ impl State2 {
// TODO(Franck): Review if these amounts are actually needed
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -638,7 +640,7 @@ pub struct State3 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
pub btc: bitcoin::Amount,
pub xmr: monero::Amount,
pub refund_timelock: u32,
pub cancel_timelock: u32,
pub punish_timelock: u32,
pub refund_address: bitcoin::Address,
pub redeem_address: bitcoin::Address,
@ -669,7 +671,7 @@ impl State3 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -680,20 +682,25 @@ impl State3 {
})
}
pub async fn wait_for_t1<W>(&self, bitcoin_wallet: &W) -> Result<()>
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
wait_for_t1(bitcoin_wallet, self.refund_timelock, self.tx_lock.txid()).await
wait_for_cancel_timelock_to_expire(
bitcoin_wallet,
self.cancel_timelock,
self.tx_lock.txid(),
)
.await
}
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<Epoch>
pub async fn expired_timelocks<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
current_epoch(
bitcoin_wallet,
self.refund_timelock,
self.cancel_timelock,
self.punish_timelock,
self.tx_lock.txid(),
)
@ -712,7 +719,7 @@ pub struct State4 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -745,7 +752,7 @@ impl State4 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -763,7 +770,7 @@ impl State4 {
bitcoin_wallet: &W,
) -> Result<()> {
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.a.public(), self.B);
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B);
let tx_punish =
bitcoin::TxPunish::new(&tx_cancel, &self.punish_address, self.punish_timelock);
@ -809,7 +816,7 @@ pub struct State5 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -840,7 +847,7 @@ impl State5 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -859,7 +866,7 @@ impl State5 {
M: CreateWalletForOutput,
{
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.a.public(), self.B);
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.a.public(), self.B);
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address);
@ -898,7 +905,7 @@ pub struct State6 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,

View file

@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::str::FromStr;
use crate::Epoch;
use crate::ExpiredTimelocks;
pub use bitcoin::{util::psbt::PartiallySignedTransaction, *};
pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature};
pub use transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund};
@ -247,28 +247,31 @@ where
pub async fn current_epoch<W>(
bitcoin_wallet: &W,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
lock_tx_id: ::bitcoin::Txid,
) -> anyhow::Result<Epoch>
) -> anyhow::Result<ExpiredTimelocks>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
let current_block_height = bitcoin_wallet.block_height().await;
let t0 = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
let t1 = t0 + refund_timelock;
let t2 = t1 + punish_timelock;
let lock_tx_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
let cancel_timelock_height = lock_tx_height + cancel_timelock;
let punish_timelock_height = cancel_timelock_height + punish_timelock;
match (current_block_height < t1, current_block_height < t2) {
(true, _) => Ok(Epoch::T0),
(false, true) => Ok(Epoch::T1),
(false, false) => Ok(Epoch::T2),
match (
current_block_height < cancel_timelock_height,
current_block_height < punish_timelock_height,
) {
(true, _) => Ok(ExpiredTimelocks::None),
(false, true) => Ok(ExpiredTimelocks::Cancel),
(false, false) => Ok(ExpiredTimelocks::Punish),
}
}
pub async fn wait_for_t1<W>(
pub async fn wait_for_cancel_timelock_to_expire<W>(
bitcoin_wallet: &W,
refund_timelock: u32,
cancel_timelock: u32,
lock_tx_id: ::bitcoin::Txid,
) -> Result<()>
where
@ -276,8 +279,6 @@ where
{
let tx_lock_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
let t1_timeout =
poll_until_block_height_is_gte(bitcoin_wallet, tx_lock_height + refund_timelock);
t1_timeout.await;
poll_until_block_height_is_gte(bitcoin_wallet, tx_lock_height + cancel_timelock).await;
Ok(())
}

View file

@ -7,7 +7,7 @@ use crate::{
monero,
serde::monero_private_key,
transport::{ReceiveMessage, SendMessage},
Epoch,
ExpiredTimelocks,
};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
@ -35,7 +35,8 @@ use tracing::error;
pub mod message;
use crate::{
bitcoin::{
current_epoch, wait_for_t1, BlockHeight, GetRawTransaction, Network, TransactionBlockHeight,
current_epoch, wait_for_cancel_timelock_to_expire, BlockHeight, GetRawTransaction, Network,
TransactionBlockHeight,
},
monero::{CreateWalletForOutput, WatchForTransfer},
};
@ -81,7 +82,7 @@ pub fn action_generator<N, M, B>(
S_a_bitcoin,
v,
xmr,
refund_timelock,
cancel_timelock,
redeem_address,
refund_address,
tx_lock,
@ -142,7 +143,7 @@ where
.await;
let poll_until_btc_has_expired = poll_until_block_height_is_gte(
bitcoin_client.as_ref(),
tx_lock_height + refund_timelock,
tx_lock_height + cancel_timelock,
)
.shared();
pin_mut!(poll_until_btc_has_expired);
@ -224,7 +225,7 @@ where
}
if let Err(SwapFailed::AfterBtcLock(_)) = swap_result {
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, refund_timelock, A, b.public());
let tx_cancel = bitcoin::TxCancel::new(&tx_lock, cancel_timelock, A, b.public());
let tx_cancel_txid = tx_cancel.txid();
let signed_tx_cancel = {
let sig_a = tx_cancel_sig_a.clone();
@ -356,7 +357,7 @@ pub struct State0 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
}
@ -366,7 +367,7 @@ impl State0 {
rng: &mut R,
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
) -> Self {
@ -381,7 +382,7 @@ impl State0 {
v_b,
btc,
xmr,
refund_timelock,
cancel_timelock,
punish_timelock,
refund_address,
}
@ -426,7 +427,7 @@ impl State0 {
v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: msg.redeem_address,
@ -447,7 +448,7 @@ pub struct State1 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -463,7 +464,7 @@ impl State1 {
}
pub fn receive(self, msg: alice::Message1) -> Result<State2> {
let tx_cancel = TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public());
let tx_cancel = TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address);
bitcoin::verify_sig(&self.A, &tx_cancel.digest(), &msg.tx_cancel_sig)?;
@ -483,7 +484,7 @@ impl State1 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -506,7 +507,7 @@ pub struct State2 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
pub xmr: monero::Amount,
pub refund_timelock: u32,
pub cancel_timelock: u32,
pub punish_timelock: u32,
pub refund_address: bitcoin::Address,
pub redeem_address: bitcoin::Address,
@ -518,7 +519,7 @@ pub struct State2 {
impl State2 {
pub fn next_message(&self) -> Message2 {
let tx_cancel = TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public());
let tx_cancel = TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let tx_cancel_sig = self.b.sign(tx_cancel.digest());
let tx_punish =
bitcoin::TxPunish::new(&tx_cancel, &self.punish_address, self.punish_timelock);
@ -550,7 +551,7 @@ impl State2 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -573,7 +574,7 @@ pub struct State3 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
pub refund_timelock: u32,
pub cancel_timelock: u32,
punish_timelock: u32,
pub refund_address: bitcoin::Address,
redeem_address: bitcoin::Address,
@ -612,7 +613,7 @@ impl State3 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address,
redeem_address: self.redeem_address,
@ -623,14 +624,19 @@ impl State3 {
})
}
pub async fn wait_for_t1<W>(&self, bitcoin_wallet: &W) -> Result<()>
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
wait_for_t1(bitcoin_wallet, self.refund_timelock, self.tx_lock.txid()).await
wait_for_cancel_timelock_to_expire(
bitcoin_wallet,
self.cancel_timelock,
self.tx_lock.txid(),
)
.await
}
pub fn t1_expired(&self) -> State4 {
pub fn state4(&self) -> State4 {
State4 {
A: self.A,
b: self.b.clone(),
@ -640,7 +646,7 @@ impl State3 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address.clone(),
redeem_address: self.redeem_address.clone(),
@ -655,13 +661,13 @@ impl State3 {
self.tx_lock.txid()
}
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<Epoch>
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
current_epoch(
bitcoin_wallet,
self.refund_timelock,
self.cancel_timelock,
self.punish_timelock,
self.tx_lock.txid(),
)
@ -680,7 +686,7 @@ pub struct State4 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
pub refund_timelock: u32,
pub cancel_timelock: u32,
punish_timelock: u32,
pub refund_address: bitcoin::Address,
pub redeem_address: bitcoin::Address,
@ -708,7 +714,7 @@ impl State4 {
W: GetRawTransaction,
{
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public());
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let sig_a = self.tx_cancel_sig_a.clone();
let sig_b = self.b.sign(tx_cancel.digest());
@ -731,7 +737,7 @@ impl State4 {
W: BroadcastSignedTransaction,
{
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public());
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let sig_a = self.tx_cancel_sig_a.clone();
let sig_b = self.b.sign(tx_cancel.digest());
@ -776,7 +782,7 @@ impl State4 {
v: self.v,
btc: self.btc,
xmr: self.xmr,
refund_timelock: self.refund_timelock,
cancel_timelock: self.cancel_timelock,
punish_timelock: self.punish_timelock,
refund_address: self.refund_address.clone(),
redeem_address: self.redeem_address.clone(),
@ -787,20 +793,25 @@ impl State4 {
})
}
pub async fn wait_for_t1<W>(&self, bitcoin_wallet: &W) -> Result<()>
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
wait_for_t1(bitcoin_wallet, self.refund_timelock, self.tx_lock.txid()).await
wait_for_cancel_timelock_to_expire(
bitcoin_wallet,
self.cancel_timelock,
self.tx_lock.txid(),
)
.await
}
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<Epoch>
pub async fn expired_timelock<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
where
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
{
current_epoch(
bitcoin_wallet,
self.refund_timelock,
self.cancel_timelock,
self.punish_timelock,
self.tx_lock.txid(),
)
@ -812,7 +823,7 @@ impl State4 {
bitcoin_wallet: &W,
) -> Result<()> {
let tx_cancel =
bitcoin::TxCancel::new(&self.tx_lock, self.refund_timelock, self.A, self.b.public());
bitcoin::TxCancel::new(&self.tx_lock, self.cancel_timelock, self.A, self.b.public());
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &self.refund_address);
{
@ -868,7 +879,7 @@ pub struct State5 {
#[serde(with = "::bitcoin::util::amount::serde::as_sat")]
btc: bitcoin::Amount,
xmr: monero::Amount,
refund_timelock: u32,
cancel_timelock: u32,
punish_timelock: u32,
refund_address: bitcoin::Address,
pub redeem_address: bitcoin::Address,

View file

@ -7,7 +7,7 @@ pub struct Config {
pub bitcoin_finality_confirmations: u32,
pub bitcoin_avg_block_time: Duration,
pub monero_max_finality_time: Duration,
pub bitcoin_refund_timelock: u32,
pub bitcoin_cancel_timelock: u32,
pub bitcoin_punish_timelock: u32,
pub bitcoin_network: ::bitcoin::Network,
}
@ -22,7 +22,7 @@ impl Config {
// blockchain is slow
monero_max_finality_time: (*mainnet::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
* mainnet::MONERO_FINALITY_CONFIRMATIONS,
bitcoin_refund_timelock: mainnet::BITCOIN_REFUND_TIMELOCK,
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
bitcoin_network: ::bitcoin::Network::Bitcoin,
}
@ -37,7 +37,7 @@ impl Config {
// blockchain is slow
monero_max_finality_time: (*regtest::MONERO_AVG_BLOCK_TIME).mul_f64(1.5)
* regtest::MONERO_FINALITY_CONFIRMATIONS,
bitcoin_refund_timelock: regtest::BITCOIN_REFUND_TIMELOCK,
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
bitcoin_network: ::bitcoin::Network::Regtest,
}
@ -59,7 +59,7 @@ mod mainnet {
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(2 * 60));
// Set to 12 hours, arbitrary value to be reviewed properly
pub static BITCOIN_REFUND_TIMELOCK: u32 = 72;
pub static BITCOIN_CANCEL_TIMELOCK: u32 = 72;
pub static BITCOIN_PUNISH_TIMELOCK: u32 = 72;
}
@ -77,7 +77,7 @@ mod regtest {
pub static MONERO_AVG_BLOCK_TIME: Lazy<Duration> = Lazy::new(|| Duration::from_secs(60));
pub static BITCOIN_REFUND_TIMELOCK: u32 = 50;
pub static BITCOIN_CANCEL_TIMELOCK: u32 = 50;
pub static BITCOIN_PUNISH_TIMELOCK: u32 = 50;
}

View file

@ -15,10 +15,10 @@
#![allow(non_snake_case)]
#[derive(Debug, Clone, Copy)]
pub enum Epoch {
T0,
T1,
T2,
pub enum ExpiredTimelocks {
None,
Cancel,
Punish,
}
#[macro_use]