bark/exit/models/package.rs
1use bitcoin::{Amount, FeeRate, Transaction, Txid};
2
3use ark::VtxoId;
4
5use crate::exit::models::states::ExitTxOrigin;
6
7/// Describes an exit transaction that needs a CPFP child to be confirmed.
8///
9/// Returned by [crate::exit::Exit::exits_needing_cpfp]. The caller creates a child
10/// transaction spending the P2A anchor of [ExitCpfpRequest::exit_tx] and submits it
11/// via [crate::exit::Exit::provide_cpfp_tx].
12#[derive(Clone, Debug)]
13pub struct ExitCpfpRequest {
14 /// The VTXO being exited.
15 pub vtxo_id: VtxoId,
16 /// The exit transaction whose P2A anchor output must be spent by the CPFP child.
17 pub exit_tx: Transaction,
18 /// If set, a third-party CPFP is already in the mempool and the child must replace it
19 /// via RBF. `None` means no CPFP exists yet and any valid fee is acceptable.
20 pub rbf_requirement: Option<RbfRequirement>,
21}
22
23/// Constraints a CPFP replacement transaction must satisfy to evict an existing one via RBF.
24#[derive(Clone, Copy, Debug, Eq, PartialEq)]
25pub struct RbfRequirement {
26 /// The effective fee rate of the existing package. A replacement must exceed this.
27 pub min_fee_rate: FeeRate,
28 /// The total fee paid by the existing package. A replacement must pay strictly more.
29 pub current_package_fee: Amount,
30}
31
32#[derive(Clone, Debug, Eq, PartialEq)]
33pub struct ExitTransactionPackage {
34 /// The actual unilateral exit transaction containing an anchor output and a spendable amount
35 pub exit: TransactionInfo,
36 /// The child transaction used to spend, and thus confirm, the exit anchor output
37 pub child: Option<ChildTransactionInfo>,
38}
39
40/// An information struct used to pair the ID of a transaction with the full transaction for ease
41/// of use and readability for the user
42#[derive(Clone, Debug, Eq, PartialEq)]
43pub struct TransactionInfo {
44 pub txid: Txid,
45 pub tx: Transaction,
46}
47
48/// Represents a child transaction for an exit transaction package with information about the origin
49/// of the transaction
50#[derive(Clone, Debug, Eq, PartialEq)]
51pub struct ChildTransactionInfo {
52 pub info: TransactionInfo,
53 pub fee_info: Option<FeeInfo>,
54 pub origin: ExitTxOrigin,
55}
56
57/// Contains the data required to bump the fee for a given transaction (including ancestors).
58#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize, Serialize)]
59pub struct FeeInfo {
60 /// The effective fee rate of the transaction (including unconfirmed CPFP ancestors).
61 #[serde(rename = "fee_rate_kwu")]
62 pub fee_rate: FeeRate,
63 /// Sum of the transaction's own fee plus the fee of each of its unconfirmed ancestors.
64 /// To replace this transaction via RBF, a replacement must add `mintxrelayfee` (typically
65 /// 0.1 sat/vB) multiplied by the replacement weight on top of this amount.
66 #[serde(rename = "total_fee_sat", with = "bitcoin::amount::serde::as_sat")]
67 pub total_fee: Amount,
68}