Skip to content

Commit

Permalink
Fix channel reestablishment issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibo-lg committed Apr 19, 2023
1 parent 3ebb2d5 commit 293b26d
Show file tree
Hide file tree
Showing 33 changed files with 1,356 additions and 93 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 = [
]

[patch.crates-io]
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dff302382d04700f23d79fb3275c1798d775fef6" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dff302382d04700f23d79fb3275c1798d775fef6" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "dff302382d04700f23d79fb3275c1798d775fef6" }
lightning = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6df5761" }
lightning-net-tokio = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6df5761" }
lightning-persister = { git = "https://github.com/p2pderivatives/rust-lightning/", rev = "6df5761" }
2 changes: 1 addition & 1 deletion dlc-manager/src/channel/party_points.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use secp256k1_zkp::{All, PublicKey, Secp256k1, Signing, Verification};

/// Base points used by a party of a DLC channel to derive public and private
/// values necessary for state update throughout the lifetime of the channel.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(serde::Serialize, serde::Deserialize),
Expand Down
36 changes: 24 additions & 12 deletions dlc-manager/src/channel_updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ where
wallet,
blockchain,
None,
None,
)
}

Expand All @@ -193,23 +194,36 @@ pub(crate) fn accept_channel_offer_internal<W: Deref, B: Deref>(
wallet: &W,
blockchain: &B,
sub_channel_info: Option<SubChannelSignInfo>,
params: Option<(
PartyParams,
Vec<crate::contract::FundingInputInfo>,
PartyBasePoints,
PublicKey,
)>,
) -> Result<(AcceptedChannel, AcceptedContract, AcceptChannel), Error>
where
W::Target: Wallet,
B::Target: Blockchain,
{
assert_eq!(offered_channel.offered_contract_id, offered_contract.id);

let (accept_params, _, funding_inputs) = crate::utils::get_party_params(
secp,
offered_contract.total_collateral - offered_contract.offer_params.collateral,
offered_contract.fee_rate_per_vb,
wallet,
blockchain,
sub_channel_info.is_none(),
)?;

let per_update_seed = wallet.get_new_secret_key()?;
let (accept_params, funding_inputs, accept_points, per_update_seed) =
if let Some((params, funding_inputs_info, accept_points, per_update_seed_pk)) = params {
let per_update_seed = wallet.get_secret_key_for_pubkey(&per_update_seed_pk)?;
(params, funding_inputs_info, accept_points, per_update_seed)
} else {
let (params, _, funding_input_infos) = crate::utils::get_party_params(
secp,
offered_contract.total_collateral - offered_contract.offer_params.collateral,
offered_contract.fee_rate_per_vb,
wallet,
blockchain,
sub_channel_info.is_none(),
)?;
let accept_points = crate::utils::get_party_base_points(secp, wallet)?;
let per_update_seed = wallet.get_new_secret_key()?;
(params, funding_input_infos, accept_points, per_update_seed)
};

let first_per_update_point = PublicKey::from_secret_key(
secp,
Expand All @@ -220,8 +234,6 @@ where
.expect("to have generated a valid secret key."),
);

let accept_points = crate::utils::get_party_base_points(secp, wallet)?;

let accept_revoke_params = accept_points.get_revokable_params(
secp,
&offered_channel.party_points.revocation_basepoint,
Expand Down
2 changes: 1 addition & 1 deletion dlc-manager/src/contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl Contract {
}

/// Information about a funding input.
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down
5 changes: 5 additions & 0 deletions dlc-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use lightning::ln::msgs::DecodeError;
use lightning::util::ser::{Readable, Writeable, Writer};
use secp256k1_zkp::XOnlyPublicKey;
use secp256k1_zkp::{PublicKey, SecretKey};
use sub_channel_manager::Action;
use subchannel::SubChannel;

/// Type alias for a contract id.
Expand Down Expand Up @@ -177,6 +178,10 @@ pub trait Storage {
fn get_sub_channels(&self) -> Result<Vec<SubChannel>, Error>;
/// Returns all the [`SubChannel`] in the `Offered` state.
fn get_offered_sub_channels(&self) -> Result<Vec<SubChannel>, Error>;
/// Save sub channel actions
fn save_sub_channel_actions(&self, actions: &[Action]) -> Result<(), Error>;
/// Get saved sub channel actions
fn get_sub_channel_actions(&self) -> Result<Vec<Action>, Error>;
}

/// Oracle trait provides access to oracle information.
Expand Down
Loading

0 comments on commit 293b26d

Please sign in to comment.