From 4b380c828b57190dd9156cc1dad01a9f2be9ea96 Mon Sep 17 00:00:00 2001 From: conduition Date: Thu, 14 Mar 2024 17:22:15 +0000 Subject: [PATCH] implement Clone on TicketedDLC (with documented stipulations) --- src/contract/outcome.rs | 1 + src/contract/split.rs | 1 + src/lib.rs | 18 ++++++++++++++++-- src/spend_info/funding.rs | 1 + src/spend_info/outcome.rs | 1 + src/spend_info/split.rs | 1 + 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/contract/outcome.rs b/src/contract/outcome.rs index 5b6ee60..aa04237 100644 --- a/src/contract/outcome.rs +++ b/src/contract/outcome.rs @@ -16,6 +16,7 @@ use crate::{ /// Represents the output of building the set of outcome transactions. /// This contains cached data used for constructing further transactions, /// or signing the outcome transactions themselves. +#[derive(Clone)] pub(crate) struct OutcomeTransactionBuildOutput { outcome_txs: BTreeMap, outcome_spend_infos: BTreeMap, diff --git a/src/contract/split.rs b/src/contract/split.rs index c5af0e8..b478524 100644 --- a/src/contract/split.rs +++ b/src/contract/split.rs @@ -17,6 +17,7 @@ use std::collections::{BTreeMap, BTreeSet}; /// Represents the output of building the set of split transactions. /// This contains cached data used for constructing further transactions, /// or signing the split transactions themselves. +#[derive(Clone)] pub(crate) struct SplitTransactionBuildOutput { split_txs: BTreeMap, split_spend_infos: BTreeMap, diff --git a/src/lib.rs b/src/lib.rs index 785e7f0..6d6d179 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,6 +33,20 @@ pub use parties::{MarketMaker, Player}; /// Represents the combined output of building all transactions and precomputing /// all necessary data for a ticketed DLC. +/// +/// This type does not have any serialization methods or trait implementations, because +/// each party in the DLC is expected to use the [`ContractParameters`] to independently +/// construct the [`TicketedDLC`] transactions which they will sign. This reduces the +/// amount of data each party must validate. Instead of minutely inspecting thousands of +/// transactions, they should validate the properties of the [`ContractParameters`], and +/// thus be assured that if others are using the same [`ContractParameters`], then they +/// will be constructing and signing the same set of transactions. +/// +/// [`TicketedDLC`] implements [`Clone`], but cloning should be done very sparingly, because +/// in real-world environments a [`TicketedDLC`] could easily encapsulate many thousands of +/// transactions involved, consuming megabytes of memory. Cloning it would be extremely +/// inefficient and potentially dangerous. +#[derive(Clone)] pub struct TicketedDLC { params: ContractParameters, funding_outpoint: OutPoint, @@ -52,13 +66,13 @@ impl TicketedDLC { let outcome_tx_build = contract::outcome::build_outcome_txs(¶ms, funding_outpoint)?; let split_tx_build = contract::split::build_split_txs(¶ms, &outcome_tx_build)?; - let txs = TicketedDLC { + let dlc = TicketedDLC { params, funding_outpoint, outcome_tx_build, split_tx_build, }; - Ok(txs) + Ok(dlc) } /// Returns the contract parameters used to construct the DLC. diff --git a/src/spend_info/funding.rs b/src/spend_info/funding.rs index 1c8b102..0770e35 100644 --- a/src/spend_info/funding.rs +++ b/src/spend_info/funding.rs @@ -10,6 +10,7 @@ use crate::{ parties::{MarketMaker, Player}, }; +#[derive(Clone)] pub(crate) struct FundingSpendInfo { key_agg_ctx: KeyAggContext, funding_value: Amount, diff --git a/src/spend_info/outcome.rs b/src/spend_info/outcome.rs index a286120..a4b8416 100644 --- a/src/spend_info/outcome.rs +++ b/src/spend_info/outcome.rs @@ -36,6 +36,7 @@ use std::{borrow::Borrow, collections::BTreeMap}; /// Once PTLCs are available, we can instead sign the split transaction once /// and distribute adaptor-signatures to each player, encrypted under the /// player's ticket point. +#[derive(Clone)] pub(crate) struct OutcomeSpendInfo { untweaked_ctx: KeyAggContext, tweaked_ctx: KeyAggContext, diff --git a/src/spend_info/split.rs b/src/spend_info/split.rs index bba4f42..a4c29e4 100644 --- a/src/spend_info/split.rs +++ b/src/spend_info/split.rs @@ -27,6 +27,7 @@ use crate::{ /// /// 3. A hash-lock which pays to the market maker immediately if they learn the // payout preimage from the player. +#[derive(Clone)] pub(crate) struct SplitSpendInfo { tweaked_ctx: KeyAggContext, payout_value: Amount,