-/// When ChannelMonitor discovers an onchain outpoint being a step of a channel and that it needs
-/// to generate a tx to push channel state forward, we cache outpoint-solving tx material to build
-/// a new bumped one in case of lenghty confirmation delay
-#[derive(Clone, PartialEq)]
-pub(crate) enum InputMaterial {
- Revoked {
- per_commitment_point: PublicKey,
- counterparty_delayed_payment_base_key: PublicKey,
- counterparty_htlc_base_key: PublicKey,
- per_commitment_key: SecretKey,
- input_descriptor: InputDescriptors,
- amount: u64,
- htlc: Option<HTLCOutputInCommitment>,
- on_counterparty_tx_csv: u16,
- },
- CounterpartyHTLC {
- per_commitment_point: PublicKey,
- counterparty_delayed_payment_base_key: PublicKey,
- counterparty_htlc_base_key: PublicKey,
- preimage: Option<PaymentPreimage>,
- htlc: HTLCOutputInCommitment
- },
- HolderHTLC {
- preimage: Option<PaymentPreimage>,
- amount: u64,
- },
- Funding {
- funding_redeemscript: Script,
- }
-}
-
-impl Writeable for InputMaterial {
- fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
- match self {
- &InputMaterial::Revoked { ref per_commitment_point, ref counterparty_delayed_payment_base_key, ref counterparty_htlc_base_key, ref per_commitment_key, ref input_descriptor, ref amount, ref htlc, ref on_counterparty_tx_csv} => {
- writer.write_all(&[0; 1])?;
- per_commitment_point.write(writer)?;
- counterparty_delayed_payment_base_key.write(writer)?;
- counterparty_htlc_base_key.write(writer)?;
- writer.write_all(&per_commitment_key[..])?;
- input_descriptor.write(writer)?;
- writer.write_all(&byte_utils::be64_to_array(*amount))?;
- htlc.write(writer)?;
- on_counterparty_tx_csv.write(writer)?;
- },
- &InputMaterial::CounterpartyHTLC { ref per_commitment_point, ref counterparty_delayed_payment_base_key, ref counterparty_htlc_base_key, ref preimage, ref htlc} => {
- writer.write_all(&[1; 1])?;
- per_commitment_point.write(writer)?;
- counterparty_delayed_payment_base_key.write(writer)?;
- counterparty_htlc_base_key.write(writer)?;
- preimage.write(writer)?;
- htlc.write(writer)?;
- },
- &InputMaterial::HolderHTLC { ref preimage, ref amount } => {
- writer.write_all(&[2; 1])?;
- preimage.write(writer)?;
- writer.write_all(&byte_utils::be64_to_array(*amount))?;
- },
- &InputMaterial::Funding { ref funding_redeemscript } => {
- writer.write_all(&[3; 1])?;
- funding_redeemscript.write(writer)?;
- }
- }
- Ok(())
- }
-}
-
-impl Readable for InputMaterial {
- fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
- let input_material = match <u8 as Readable>::read(reader)? {
- 0 => {
- let per_commitment_point = Readable::read(reader)?;
- let counterparty_delayed_payment_base_key = Readable::read(reader)?;
- let counterparty_htlc_base_key = Readable::read(reader)?;
- let per_commitment_key = Readable::read(reader)?;
- let input_descriptor = Readable::read(reader)?;
- let amount = Readable::read(reader)?;
- let htlc = Readable::read(reader)?;
- let on_counterparty_tx_csv = Readable::read(reader)?;
- InputMaterial::Revoked {
- per_commitment_point,
- counterparty_delayed_payment_base_key,
- counterparty_htlc_base_key,
- per_commitment_key,
- input_descriptor,
- amount,
- htlc,
- on_counterparty_tx_csv
- }
- },
- 1 => {
- let per_commitment_point = Readable::read(reader)?;
- let counterparty_delayed_payment_base_key = Readable::read(reader)?;
- let counterparty_htlc_base_key = Readable::read(reader)?;
- let preimage = Readable::read(reader)?;
- let htlc = Readable::read(reader)?;
- InputMaterial::CounterpartyHTLC {
- per_commitment_point,
- counterparty_delayed_payment_base_key,
- counterparty_htlc_base_key,
- preimage,
- htlc
- }
- },
- 2 => {
- let preimage = Readable::read(reader)?;
- let amount = Readable::read(reader)?;
- InputMaterial::HolderHTLC {
- preimage,
- amount,
- }
- },
- 3 => {
- InputMaterial::Funding {
- funding_redeemscript: Readable::read(reader)?,
- }
- }
- _ => return Err(DecodeError::InvalidValue),
- };
- Ok(input_material)
- }
-}
-
-/// ClaimRequest is a descriptor structure to communicate between detection
-/// and reaction module. They are generated by ChannelMonitor while parsing
-/// onchain txn leaked from a channel and handed over to OnchainTxHandler which
-/// is responsible for opportunistic aggregation, selecting and enforcing
-/// bumping logic, building and signing transactions.
-pub(crate) struct ClaimRequest {
- // Block height before which claiming is exclusive to one party,
- // after reaching it, claiming may be contentious.
- pub(crate) absolute_timelock: u32,
- // Timeout tx must have nLocktime set which means aggregating multiple
- // ones must take the higher nLocktime among them to satisfy all of them.
- // Sadly it has few pitfalls, a) it takes longuer to get fund back b) CLTV_DELTA
- // of a sooner-HTLC could be swallowed by the highest nLocktime of the HTLC set.
- // Do simplify we mark them as non-aggregable.
- pub(crate) aggregable: bool,
- // Basic bitcoin outpoint (txid, vout)
- pub(crate) outpoint: BitcoinOutPoint,
- // Following outpoint type, set of data needed to generate transaction digest
- // and satisfy witness program.
- pub(crate) witness_data: InputMaterial
-}
-