Skip to content

Commit

Permalink
Update to rust-lightning:0.0.117
Browse files Browse the repository at this point in the history
As part of this update `rust-lightning` introduced a `ChannelId`
struct, which motivated us to also introduce the `DlcChannelId` and
`SubChannelId` structs.
  • Loading branch information
luckysori committed Dec 20, 2023
1 parent 0f9ce7c commit 86e2000
Show file tree
Hide file tree
Showing 38 changed files with 657 additions and 482 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ members = [
resolver = "2"

[patch.crates-io]
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "a57281b" }
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "15c4ff6" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "15c4ff6" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "15c4ff6" }
2 changes: 1 addition & 1 deletion bitcoin-rpc-provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bitcoin = {version = "0.29.2"}
bitcoincore-rpc = {version = "0.16.0"}
bitcoincore-rpc-json = {version = "0.16.0"}
dlc-manager = {path = "../dlc-manager"}
lightning = {version = "0.0.116"}
lightning = {version = "0.0.117"}
log = "0.4.14"
rust-bitcoin-coin-selection = { rev = "23a6bf85", git = "https://github.com/p2pderivatives/rust-bitcoin-coin-selection", features = ["rand"]}
simple-wallet = {path = "../simple-wallet"}
6 changes: 3 additions & 3 deletions dlc-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bitcoin = {version = "0.29.2"}
dlc = {version = "0.4.0", path = "../dlc"}
dlc-messages = {version = "0.4.0", path = "../dlc-messages"}
dlc-trie = {version = "0.4.0", path = "../dlc-trie"}
lightning = {version = "0.0.116"}
lightning = {version = "0.0.117"}
log = "0.4.14"
rand_chacha = {version = "0.3.1", optional = true}
secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std"]}
Expand All @@ -37,8 +37,8 @@ dlc-manager = {path = ".", features = ["use-serde"]}
dlc-messages = {path = "../dlc-messages", features = ["serde"]}
electrs-blockchain-provider = {path = "../electrs-blockchain-provider"}
env_logger = "0.9.1"
lightning-persister = {version = "0.0.116"}
lightning-transaction-sync = {version = "0.0.116", features=["esplora-blocking"]}
lightning-persister = {version = "0.0.117"}
lightning-transaction-sync = {version = "0.0.117", features=["esplora-blocking"]}
mocks = {path = "../mocks"}
secp256k1-zkp = {version = "0.7.0", features = ["bitcoin_hashes", "rand", "rand-std", "global-context", "use-serde"]}
serde = "1.0"
Expand Down
9 changes: 4 additions & 5 deletions dlc-manager/src/chain_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use lightning::ln::msgs::DecodeError;
use lightning::util::ser::{Readable, Writeable, Writer};
use secp256k1_zkp::EcdsaAdaptorSignature;

use crate::ChannelId;

/// A `ChainMonitor` keeps a list of transaction ids to watch for in the blockchain,
/// and some associated information used to apply an action when the id is seen.
#[derive(Debug, PartialEq, Eq)]
Expand All @@ -26,7 +24,8 @@ impl_dlc_writeable!(ChainMonitor, { (watched_tx, { cb_writeable, write_hash_map,

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct ChannelInfo {
pub channel_id: ChannelId,
/// The identifier for _either_ a Lightning channel or a DLC channel.
pub channel_id: [u8; 32],
pub tx_type: TxType,
}

Expand Down Expand Up @@ -111,7 +110,7 @@ impl ChainMonitor {
.insert(outpoint, WatchState::new(channel_info));
}

pub(crate) fn cleanup_channel(&mut self, channel_id: ChannelId) {
pub(crate) fn cleanup_channel(&mut self, channel_id: [u8; 32]) {
log::debug!("Cleaning up data related to channel {channel_id:?}");

self.watched_tx
Expand Down Expand Up @@ -220,7 +219,7 @@ impl WatchState {
}
}

fn channel_id(&self) -> ChannelId {
fn channel_id(&self) -> [u8; 32] {
self.channel_info().channel_id
}
}
7 changes: 4 additions & 3 deletions dlc-manager/src/channel/accepted_channel.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! # Structure and methods for channels that have been accepted.

use bitcoin::{Script, Transaction};
use dlc::DlcChannelId;
use dlc_messages::channel::AcceptChannel;
use secp256k1_zkp::{EcdsaAdaptorSignature, PublicKey};

use crate::{contract::accepted_contract::AcceptedContract, ChannelId, ContractId};
use crate::{contract::accepted_contract::AcceptedContract, ContractId};

use super::party_points::PartyBasePoints;

Expand All @@ -31,9 +32,9 @@ pub struct AcceptedChannel {
/// The script pubkey of the buffer transaction output.
pub buffer_script_pubkey: Script,
/// The temporary id of the channel.
pub temporary_channel_id: ChannelId,
pub temporary_channel_id: DlcChannelId,
/// The actual id of the channel.
pub channel_id: ChannelId,
pub channel_id: DlcChannelId,
/// The image of the per update seed used by the accept party.
pub accept_per_update_seed: PublicKey,
/// The accept party adaptor signature for the buffer transaction.
Expand Down
47 changes: 24 additions & 23 deletions dlc-manager/src/channel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! # Module containing structures and methods for working with DLC channels.

use bitcoin::{hashes::Hash, Transaction, Txid};
use dlc::DlcChannelId;
use dlc_messages::channel::{AcceptChannel, SignChannel};
use secp256k1_zkp::PublicKey;

use crate::{ChannelId, ContractId};
use crate::ContractId;

use self::{
accepted_channel::AcceptedChannel, offered_channel::OfferedChannel,
Expand Down Expand Up @@ -95,8 +96,8 @@ impl Channel {
pub struct FailedAccept {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// The temporary [`DlcChannelId`] of the channel.
pub temporary_channel_id: DlcChannelId,
/// An message describing the error encountered while validating the
/// [`dlc_messages::channel::AcceptChannel`] message.
pub error_message: String,
Expand All @@ -110,8 +111,8 @@ pub struct FailedAccept {
pub struct FailedSign {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The [`crate::ChannelId`] of the channel.
pub channel_id: ChannelId,
/// The [`DlcChannelId`] of the channel.
pub channel_id: DlcChannelId,
/// An message describing the error encountered while validating the
/// [`dlc_messages::channel::SignChannel`] message.
pub error_message: String,
Expand All @@ -124,10 +125,10 @@ pub struct FailedSign {
pub struct ClosingChannel {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// The [`crate::ChannelId`] for the channel.
pub channel_id: ChannelId,
/// The temporary [`DlcChannelId`] of the channel.
pub temporary_channel_id: DlcChannelId,
/// The [`DlcChannelId`] for the channel.
pub channel_id: DlcChannelId,
/// The previous state the channel was before being closed, if that state was the `Signed` one,
/// otherwise is `None`.
pub rollback_state: Option<SignedChannel>,
Expand All @@ -145,10 +146,10 @@ pub struct ClosingChannel {
pub struct ClosedChannel {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// The [`crate::ChannelId`] for the channel.
pub channel_id: ChannelId,
/// The temporary [`DlcChannelId`] of the channel.
pub temporary_channel_id: DlcChannelId,
/// The [`DlcChannelId`] for the channel.
pub channel_id: DlcChannelId,
}

#[derive(Clone)]
Expand All @@ -157,17 +158,17 @@ pub struct ClosedChannel {
pub struct ClosedPunishedChannel {
/// The [`secp256k1_zkp::PublicKey`] of the counter party.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// The [`crate::ChannelId`] for the channel.
pub channel_id: ChannelId,
/// The temporary [`DlcChannelId`] of the channel.
pub temporary_channel_id: DlcChannelId,
/// The [`DlcChannelId`] for the channel.
pub channel_id: DlcChannelId,
/// The transaction id of the punishment transaction that was broadcast.
pub punish_txid: Txid,
}

impl Channel {
/// Returns the temporary [`crate::ChannelId`] for the channel.
pub fn get_temporary_id(&self) -> ChannelId {
/// Returns the temporary [`DlcChannelId`] for the channel.
pub fn get_temporary_id(&self) -> DlcChannelId {
match self {
Channel::Offered(o) => o.temporary_channel_id,
Channel::Accepted(a) => a.temporary_channel_id,
Expand All @@ -181,8 +182,8 @@ impl Channel {
}
}

/// Returns the [`crate::ChannelId`] for the channel.
pub fn get_id(&self) -> ChannelId {
/// Returns the [`DlcChannelId`] for the channel.
pub fn get_id(&self) -> DlcChannelId {
match self {
Channel::Offered(o) => o.temporary_channel_id,
Channel::Accepted(a) => a.channel_id,
Expand Down Expand Up @@ -212,11 +213,11 @@ impl Channel {

/// Generate a temporary contract id for a DLC based on the channel id and the update index of the DLC channel.
pub fn generate_temporary_contract_id(
channel_id: ChannelId,
channel_id: DlcChannelId,
channel_update_idx: u64,
) -> ContractId {
let mut data = Vec::with_capacity(65);
data.extend_from_slice(&channel_id);
data.extend_from_slice(&channel_id.inner());
data.extend_from_slice(&channel_update_idx.to_be_bytes());
bitcoin::hashes::sha256::Hash::hash(&data).into_inner()
}
8 changes: 4 additions & 4 deletions dlc-manager/src/channel/offered_channel.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//! # A channel is offered when an offer was made or received. This module contains
//! the model for it and method for working with it.

use dlc::DlcChannelId;
use dlc::PartyParams;
use dlc_messages::channel::OfferChannel;
// use dlc_messages::channel::OfferChannel;
use secp256k1_zkp::PublicKey;

use crate::{
contract::offered_contract::OfferedContract, conversion_utils::get_tx_input_infos,
error::Error, ChannelId, ContractId,
error::Error, ContractId,
};

use super::party_points::PartyBasePoints;
Expand All @@ -25,8 +25,8 @@ pub struct OfferedChannel {
/// The temporary [`crate::ContractId`] of the contract that was offered for
/// channel setup.
pub offered_contract_id: ContractId,
/// The temporary [`crate::ChannelId`] of the channel.
pub temporary_channel_id: ChannelId,
/// The temporary [`DlcChannelId`] of the channel.
pub temporary_channel_id: DlcChannelId,
/// The set of base points that the offer party will use during the lifetime
/// of the channel.
pub party_points: PartyBasePoints,
Expand Down
14 changes: 8 additions & 6 deletions dlc-manager/src/channel/signed_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
//! the possible states in which it can be as well as methods to work with it.

use bitcoin::{Script, Transaction};
use dlc::DlcChannelId;
use dlc::PartyParams;
use dlc::SubChannelId;
use lightning::ln::chan_utils::CounterpartyCommitmentSecrets;
use secp256k1_zkp::{ecdsa::Signature, EcdsaAdaptorSignature, PublicKey};

use crate::{ChannelId, ContractId};
use crate::ContractId;

use super::party_points::PartyBasePoints;

Expand Down Expand Up @@ -346,12 +348,12 @@ impl SignedChannelState {
/// A channel that had a successful setup.
#[derive(Clone)]
pub struct SignedChannel {
/// The [`crate::ChannelId`] for the channel.
pub channel_id: ChannelId,
/// The [`DlcChannelId`] for the channel.
pub channel_id: DlcChannelId,
/// The [`secp256k1_zkp::PublicKey`] of the counter party's node.
pub counter_party: PublicKey,
/// The temporary [`crate::ChannelId`] for the channel.
pub temporary_channel_id: ChannelId,
/// The temporary [`DlcChannelId`] for the channel.
pub temporary_channel_id: DlcChannelId,
/// The contract setup parameters for the local party.
pub own_params: PartyParams,
/// The base points used for channel updates and revocation by the local party.
Expand Down Expand Up @@ -385,7 +387,7 @@ pub struct SignedChannel {
/// The current fee rate to be used to create transactions.
pub fee_rate_per_vb: u64,
/// Whether this channel is embedded within a Lightning Network channel.
pub sub_channel_id: Option<ChannelId>,
pub sub_channel_id: Option<SubChannelId>,
}

impl SignedChannel {
Expand Down
25 changes: 14 additions & 11 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ use crate::{
},
error::Error,
subchannel::{ClosingSubChannel, SubChannel},
Blockchain, ChannelId, ContractId, Signer, Time, Wallet,
Blockchain, ContractId, Signer, Time, Wallet,
};
use bitcoin::{OutPoint, Script, Sequence, Transaction};
use dlc::{
channel::{get_tx_adaptor_signature, verify_tx_adaptor_signature, DlcChannelTransactions},
PartyParams,
};
use dlc::{DlcChannelId, SubChannelId};
use dlc_messages::{
channel::{
AcceptChannel, CollaborativeCloseOffer, Reject, RenewAccept, RenewConfirm, RenewFinalize,
Expand Down Expand Up @@ -81,7 +82,7 @@ pub(crate) struct SubChannelSignVerifyInfo {
pub funding_info: FundingInfo,
pub own_adaptor_sk: SecretKey,
pub counter_adaptor_pk: PublicKey,
pub sub_channel_id: ChannelId,
pub sub_channel_id: SubChannelId,
}

pub(crate) struct SubChannelSignInfo {
Expand All @@ -92,7 +93,7 @@ pub(crate) struct SubChannelSignInfo {
pub(crate) struct SubChannelVerifyInfo {
pub funding_info: FundingInfo,
pub counter_adaptor_pk: PublicKey,
pub sub_channel_id: ChannelId,
pub sub_channel_id: SubChannelId,
}

/// Creates an [`OfferedChannel`] and an associated [`OfferedContract`] using
Expand All @@ -107,7 +108,7 @@ pub fn offer_channel<C: Signing, W: Deref, B: Deref, T: Deref>(
wallet: &W,
blockchain: &B,
time: &T,
temporary_channel_id: ContractId,
temporary_channel_id: DlcChannelId,
is_sub_channel: bool,
) -> Result<(OfferedChannel, OfferedContract), Error>
where
Expand Down Expand Up @@ -321,8 +322,9 @@ where
let channel_id = crate::utils::compute_id(
dlc_transactions.fund.txid(),
funding_vout as u16,
&offered_channel.temporary_channel_id,
&offered_channel.temporary_channel_id.inner(),
);
let channel_id = DlcChannelId::from_bytes(channel_id);

let buffer_adaptor_signature = get_tx_adaptor_signature(
secp,
Expand Down Expand Up @@ -534,8 +536,9 @@ where
let channel_id = crate::utils::compute_id(
dlc_transactions.fund.txid(),
fund_output_index as u16,
&offered_channel.temporary_channel_id,
&offered_channel.temporary_channel_id.inner(),
);
let channel_id = DlcChannelId::from_bytes(channel_id);

let accept_cet_adaptor_signatures: Vec<_> = (&accept_channel.cet_adaptor_signatures).into();

Expand Down Expand Up @@ -581,7 +584,7 @@ where
chain_monitor.lock().unwrap().add_tx(
buffer_transaction.txid(),
ChannelInfo {
channel_id,
channel_id: channel_id.inner(),
tx_type: TxType::BufferTx,
},
);
Expand Down Expand Up @@ -740,7 +743,7 @@ where
chain_monitor.lock().unwrap().add_tx(
accepted_channel.buffer_transaction.txid(),
ChannelInfo {
channel_id: accepted_channel.channel_id,
channel_id: accepted_channel.channel_id.inner(),
tx_type: TxType::BufferTx,
},
);
Expand Down Expand Up @@ -982,7 +985,7 @@ where
chain_monitor.lock().unwrap().add_tx(
settle_tx.txid(),
ChannelInfo {
channel_id: channel.channel_id,
channel_id: channel.channel_id.inner(),
tx_type: TxType::SettleTx,
},
);
Expand Down Expand Up @@ -1115,7 +1118,7 @@ where
chain_monitor.lock().unwrap().add_tx(
settle_tx.txid(),
ChannelInfo {
channel_id: channel.channel_id,
channel_id: channel.channel_id.inner(),
tx_type: TxType::SettleTx,
},
);
Expand Down Expand Up @@ -1960,7 +1963,7 @@ where
chain_monitor.lock().unwrap().add_tx(
buffer_transaction.txid(),
ChannelInfo {
channel_id: signed_channel.channel_id,
channel_id: signed_channel.channel_id.inner(),
tx_type: TxType::BufferTx,
},
);
Expand Down
Loading

0 comments on commit 86e2000

Please sign in to comment.