implement Clone on TicketedDLC (with documented stipulations)

This commit is contained in:
conduition
2024-03-14 17:22:15 +00:00
parent e9096c1ef4
commit 4b380c828b
6 changed files with 21 additions and 2 deletions

View File

@@ -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, Transaction>,
outcome_spend_infos: BTreeMap<Outcome, OutcomeSpendInfo>,

View File

@@ -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<Outcome, Transaction>,
split_spend_infos: BTreeMap<WinCondition, SplitSpendInfo>,

View File

@@ -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(&params, funding_outpoint)?;
let split_tx_build = contract::split::build_split_txs(&params, &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.

View File

@@ -10,6 +10,7 @@ use crate::{
parties::{MarketMaker, Player},
};
#[derive(Clone)]
pub(crate) struct FundingSpendInfo {
key_agg_ctx: KeyAggContext,
funding_value: Amount,

View File

@@ -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,

View File

@@ -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,