Skip to content

Commit

Permalink
fix: bug that key that was generated does not match the existing key.
Browse files Browse the repository at this point in the history
  • Loading branch information
k0k0ne committed Oct 17, 2024
1 parent bb7ba40 commit 3bd3109
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
37 changes: 23 additions & 14 deletions lightning/src/color_ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use crate::ln::features::ChannelTypeFeatures;
use crate::ln::{ChannelId, PaymentHash};
use crate::sign::SignerProvider;

use bitcoin::bip32::ExtendedPrivKey;
use bitcoin::bip32::{ExtendedPrivKey, ExtendedPubKey};
use bitcoin::blockdata::transaction::Transaction;
use bitcoin::psbt::{PartiallySignedTransaction, Psbt};
use bitcoin::secp256k1::PublicKey;
use bitcoin::{TxOut, Txid};
use database::{
ColorDatabaseImpl, ConsignmentBinaryData, ConsignmentHandle, PaymentDirection, PaymentHashKey, ProxyIdKey, RgbInfoKey
ColorDatabaseImpl, ConsignmentBinaryData, ConsignmentHandle, PaymentDirection, PaymentHashKey,
ProxyIdKey, RgbInfoKey,
};
use hex::DisplayHex;
use rgb_lib::wallet::rust_only::AssetBeneficiariesMap;
Expand Down Expand Up @@ -70,16 +71,14 @@ pub trait WalletProxy {
fn consume_fascia(&self, fascia: Fascia, witness_txid: RgbTxid) -> Result<(), String>;
}

#[derive(Debug)]
pub struct WalletProxyImpl {
network: BitcoinNetwork,
xpub: ExtendedPubKey,
xprv: ExtendedPrivKey,
ldk_data_dir: PathBuf,
}
impl fmt::Debug for WalletProxyImpl {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("WalletProxyImpl").field("xpub_getter", &"Function").finish()
}
}

impl WalletProxy for WalletProxyImpl {
fn consume_fascia(&self, fascia: Fascia, witness_txid: RgbTxid) -> Result<(), String> {
println!("block_on consume_fascia");
Expand All @@ -89,8 +88,10 @@ impl WalletProxy for WalletProxyImpl {
}

impl WalletProxyImpl {
fn new(network: BitcoinNetwork, xprv: ExtendedPrivKey, ldk_data_dir: PathBuf) -> Self {
Self { network, xprv, ldk_data_dir }
fn new(
network: BitcoinNetwork, xpub: ExtendedPubKey, xprv: ExtendedPrivKey, ldk_data_dir: PathBuf,
) -> Self {
Self { network, xpub, xprv, ldk_data_dir }
}

pub fn color_psbt(
Expand All @@ -109,8 +110,7 @@ impl WalletProxyImpl {
// }

pub fn xpub(&self) -> String {
bitcoin::bip32::ExtendedPubKey::from_priv(&bitcoin::key::Secp256k1::new(), &self.xprv)
.to_string()
self.xpub.to_string()
}

async fn _get_rgb_wallet(&self, ldk_data_dir: &Path) -> Wallet {
Expand Down Expand Up @@ -154,14 +154,17 @@ impl ColorSource for ColorSourceImpl {
}

impl ColorSourceImpl {
pub fn new(ldk_data_dir: PathBuf, network: BitcoinNetwork, xprv: ExtendedPrivKey) -> Self {
pub fn new(
ldk_data_dir: PathBuf, network: BitcoinNetwork, xpub: ExtendedPubKey, xprv: ExtendedPrivKey,
) -> Self {
let ldk_data_dir = Arc::new(ldk_data_dir);

let instance = Self {
ldk_data_dir: Arc::clone(&ldk_data_dir).to_path_buf(),
network,
wallet_proxy: WalletProxyImpl::new(
network,
xpub,
xprv,
Arc::clone(&ldk_data_dir).to_path_buf(),
),
Expand Down Expand Up @@ -624,7 +627,10 @@ impl ColorSourceImpl {
) -> Result<(), MsgHandleErrInternal> {
let handle = Handle::current();
let _ = handle.enter();
println!("block_on handle_funding");
println!(
"block_on handle_funding txid: {}, temporary_channel_id {}",
funding_txid, temporary_channel_id
);
let accept_res = futures::executor::block_on(
self._accept_transfer(funding_txid.clone(), consignment_endpoint),
);
Expand Down Expand Up @@ -656,6 +662,8 @@ impl ColorSourceImpl {
},
};

println!("accept consignment with contract id {}", consignment.contract_id());

let funding_txid = Txid::from_str(&funding_txid).unwrap();
let mut consignment_data = ConsignmentBinaryData::default();
let ret = consignment.save(&mut consignment_data);
Expand All @@ -680,7 +688,8 @@ impl ColorSourceImpl {
pub fn get_consignment_by_funding_txid(
&self, funding_txid: &Txid,
) -> Option<ConsignmentBinaryData> {
let handle = self.database.consignment().lock().unwrap().get_by_funding_txid(funding_txid)?;
let handle =
self.database.consignment().lock().unwrap().get_by_funding_txid(funding_txid)?;
self.database.consignment().lock().unwrap().resolve(handle).cloned()
}

Expand Down
9 changes: 8 additions & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7337,6 +7337,7 @@ where
}

fn internal_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) -> Result<(), MsgHandleErrInternal> {
println!("internal_funding_created msg txid {}", msg.funding_txid.to_string());
let best_block = *self.best_block.read().unwrap();

let per_peer_state = self.per_peer_state.read().unwrap();
Expand All @@ -7348,12 +7349,18 @@ where

let mut peer_state_lock = peer_state_mutex.lock().unwrap();
let peer_state = &mut *peer_state_lock;
println!("internal_funding_created remove channel_id {}", msg.temporary_channel_id);

let (mut chan, funding_msg_opt, monitor) =
match peer_state.channel_by_id.remove(&msg.temporary_channel_id) {
Some(ChannelPhase::UnfundedInboundV1(inbound_chan)) => {
let logger = WithChannelContext::from(&self.logger, &inbound_chan.context);
if let Some(consignment_endpoint) = &inbound_chan.context.consignment_endpoint {
println!("internal_funding_created call handle_funding");

self.color_source.lock().unwrap().handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), consignment_endpoint.clone())?;
} else {
println!("internal_funding_created no consignment_endpoint");
}
match inbound_chan.funding_created(msg, best_block, &self.signer_provider, &&logger) {
Ok(res) => res,
Expand Down Expand Up @@ -12248,7 +12255,7 @@ where
};
if let Some(network_pubkey) = received_network_pubkey {
if network_pubkey != our_network_pubkey {
log_error!(args.logger, "Key that was generated does not match the existing key.");
log_error!(args.logger, "Key that was generated does not match the existing key. left: {}, right: {}", network_pubkey, our_network_pubkey);
return Err(DecodeError::InvalidValue);
}
}
Expand Down

0 comments on commit 3bd3109

Please sign in to comment.