Skip to content

Commit

Permalink
feat: Add closing txid to channel
Browse files Browse the repository at this point in the history
  • Loading branch information
holzeis committed Feb 26, 2024
1 parent 8724365 commit 28ab526
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 13 deletions.
2 changes: 2 additions & 0 deletions dlc-manager/src/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ pub struct ClosedChannel {
pub channel_id: DlcChannelId,
/// The reference id set by the api user.
pub reference_id: Option<ReferenceId>,
/// The txid that closed that channel
pub closing_txid: Txid,
}

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/src/channel/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ impl_dlc_writeable!(ClosingChannel, {
(is_closer, writeable),
(reference_id, option)
});
impl_dlc_writeable!(ClosedChannel, {(channel_id, writeable), (counter_party, writeable), (temporary_channel_id, writeable), (reference_id, option)});
impl_dlc_writeable!(ClosedChannel, {(channel_id, writeable), (counter_party, writeable), (temporary_channel_id, writeable), (reference_id, option), (closing_txid, writeable)});
impl_dlc_writeable!(ClosedPunishedChannel, {(channel_id, writeable), (counter_party, writeable), (temporary_channel_id, writeable), (punish_txid, writeable), (reference_id, option)});
12 changes: 8 additions & 4 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,8 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: close_tx.txid()
});
Ok((close_tx, channel))
}
Expand Down Expand Up @@ -2694,7 +2695,8 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: cet.txid()
};
let channel = if is_initiator {
Channel::Closed(closed_channel)
Expand Down Expand Up @@ -2830,14 +2832,16 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: settle_tx.txid()
})
} else {
Channel::CounterClosed(ClosedChannel {
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: settle_tx.txid()
})
};
Ok((settle_tx, channel))
Expand Down
22 changes: 16 additions & 6 deletions dlc-manager/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::subchannel::{ClosingSubChannel, SubChannel, SubChannelState};
use crate::utils::get_object_in_state;
use crate::{ContractId, DlcChannelId, ReferenceId, Signer};
use bitcoin::consensus::encode::serialize_hex;
use bitcoin::{Address, OutPoint};
use bitcoin::{Address, OutPoint, Txid};
use bitcoin::Transaction;
use bitcoin::hashes::hex::ToHex;
use dlc_messages::channel::{
Expand All @@ -41,6 +41,7 @@ use secp256k1_zkp::{ecdsa::Signature, All, PublicKey, Secp256k1, SecretKey};
use secp256k1_zkp::{EcdsaAdaptorSignature, XOnlyPublicKey};
use std::collections::HashMap;
use std::ops::Deref;
use std::str::FromStr;
use std::string::ToString;
use std::sync::Mutex;
use bitcoin::consensus::Decodable;
Expand Down Expand Up @@ -2324,7 +2325,8 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: tx.txid()
});
self.chain_monitor
.lock()
Expand All @@ -2339,6 +2341,7 @@ where
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: None,
closing_txid: tx.txid(),
});
self.chain_monitor
.lock()
Expand All @@ -2357,14 +2360,16 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: tx.txid()
})
} else {
Channel::CounterClosed(ClosedChannel {
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: signed_channel.reference_id
reference_id: signed_channel.reference_id,
closing_txid: tx.txid()
})
}
}
Expand All @@ -2374,7 +2379,8 @@ where
counter_party: signed_channel.counter_party,
temporary_channel_id: signed_channel.temporary_channel_id,
channel_id: signed_channel.channel_id,
reference_id: None
reference_id: None,
closing_txid: tx.txid()
})
}
}
Expand Down Expand Up @@ -2614,7 +2620,11 @@ where
counter_party: channel.counter_party,
temporary_channel_id: channel.temporary_channel_id,
channel_id,
reference_id: None
reference_id: None,
// TODO(holzeis): This is not correct, but we don't care about sub dlc channels, so it doesn't really matter.
closing_txid: Txid::from_str(
"83266d6b22a9babf6ee469b88fd0d3a0c690525f7c903aff22ec8ee44214604f",
).unwrap()
});

Ok((closed_channel, contract))
Expand Down
9 changes: 7 additions & 2 deletions dlc-manager/src/sub_channel_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
//! Lightning Network channels.

use std::{collections::HashMap, marker::PhantomData, ops::Deref, sync::Mutex};
use std::str::FromStr;

use bitcoin::{hashes::hex::ToHex, OutPoint, PackedLockTime, Script, Sequence, Transaction};
use bitcoin::{hashes::hex::ToHex, OutPoint, PackedLockTime, Script, Sequence, Transaction, Txid};
use dlc::{channel::sub_channel::LN_GLUE_TX_WEIGHT, PartyParams};
use dlc_messages::{
channel::{AcceptChannel, OfferChannel},
Expand Down Expand Up @@ -3703,11 +3704,15 @@ where
"No such channel {:?}",
channel_id
)))?;

let closed_channel_data = ClosedChannel {
counter_party: channel.get_counter_party_id(),
temporary_channel_id: channel.get_temporary_id(),
channel_id: channel.get_id(),
reference_id: None
reference_id: None,
closing_txid: Txid::from_str(
"83266d6b22a9babf6ee469b88fd0d3a0c690525f7c903aff22ec8ee44214604f",
).unwrap()
};
let closed_channel = if counter_closed {
Channel::CounterClosed(closed_channel_data)
Expand Down

0 comments on commit 28ab526

Please sign in to comment.