Skip to content

Commit 3bd3109

Browse files
committed
fix: bug that key that was generated does not match the existing key.
1 parent bb7ba40 commit 3bd3109

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

lightning/src/color_ext/mod.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ use crate::ln::features::ChannelTypeFeatures;
99
use crate::ln::{ChannelId, PaymentHash};
1010
use crate::sign::SignerProvider;
1111

12-
use bitcoin::bip32::ExtendedPrivKey;
12+
use bitcoin::bip32::{ExtendedPrivKey, ExtendedPubKey};
1313
use bitcoin::blockdata::transaction::Transaction;
1414
use bitcoin::psbt::{PartiallySignedTransaction, Psbt};
1515
use bitcoin::secp256k1::PublicKey;
1616
use bitcoin::{TxOut, Txid};
1717
use database::{
18-
ColorDatabaseImpl, ConsignmentBinaryData, ConsignmentHandle, PaymentDirection, PaymentHashKey, ProxyIdKey, RgbInfoKey
18+
ColorDatabaseImpl, ConsignmentBinaryData, ConsignmentHandle, PaymentDirection, PaymentHashKey,
19+
ProxyIdKey, RgbInfoKey,
1920
};
2021
use hex::DisplayHex;
2122
use rgb_lib::wallet::rust_only::AssetBeneficiariesMap;
@@ -70,16 +71,14 @@ pub trait WalletProxy {
7071
fn consume_fascia(&self, fascia: Fascia, witness_txid: RgbTxid) -> Result<(), String>;
7172
}
7273

74+
#[derive(Debug)]
7375
pub struct WalletProxyImpl {
7476
network: BitcoinNetwork,
77+
xpub: ExtendedPubKey,
7578
xprv: ExtendedPrivKey,
7679
ldk_data_dir: PathBuf,
7780
}
78-
impl fmt::Debug for WalletProxyImpl {
79-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
80-
f.debug_struct("WalletProxyImpl").field("xpub_getter", &"Function").finish()
81-
}
82-
}
81+
8382
impl WalletProxy for WalletProxyImpl {
8483
fn consume_fascia(&self, fascia: Fascia, witness_txid: RgbTxid) -> Result<(), String> {
8584
println!("block_on consume_fascia");
@@ -89,8 +88,10 @@ impl WalletProxy for WalletProxyImpl {
8988
}
9089

9190
impl WalletProxyImpl {
92-
fn new(network: BitcoinNetwork, xprv: ExtendedPrivKey, ldk_data_dir: PathBuf) -> Self {
93-
Self { network, xprv, ldk_data_dir }
91+
fn new(
92+
network: BitcoinNetwork, xpub: ExtendedPubKey, xprv: ExtendedPrivKey, ldk_data_dir: PathBuf,
93+
) -> Self {
94+
Self { network, xpub, xprv, ldk_data_dir }
9495
}
9596

9697
pub fn color_psbt(
@@ -109,8 +110,7 @@ impl WalletProxyImpl {
109110
// }
110111

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

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

156156
impl ColorSourceImpl {
157-
pub fn new(ldk_data_dir: PathBuf, network: BitcoinNetwork, xprv: ExtendedPrivKey) -> Self {
157+
pub fn new(
158+
ldk_data_dir: PathBuf, network: BitcoinNetwork, xpub: ExtendedPubKey, xprv: ExtendedPrivKey,
159+
) -> Self {
158160
let ldk_data_dir = Arc::new(ldk_data_dir);
159161

160162
let instance = Self {
161163
ldk_data_dir: Arc::clone(&ldk_data_dir).to_path_buf(),
162164
network,
163165
wallet_proxy: WalletProxyImpl::new(
164166
network,
167+
xpub,
165168
xprv,
166169
Arc::clone(&ldk_data_dir).to_path_buf(),
167170
),
@@ -624,7 +627,10 @@ impl ColorSourceImpl {
624627
) -> Result<(), MsgHandleErrInternal> {
625628
let handle = Handle::current();
626629
let _ = handle.enter();
627-
println!("block_on handle_funding");
630+
println!(
631+
"block_on handle_funding txid: {}, temporary_channel_id {}",
632+
funding_txid, temporary_channel_id
633+
);
628634
let accept_res = futures::executor::block_on(
629635
self._accept_transfer(funding_txid.clone(), consignment_endpoint),
630636
);
@@ -656,6 +662,8 @@ impl ColorSourceImpl {
656662
},
657663
};
658664

665+
println!("accept consignment with contract id {}", consignment.contract_id());
666+
659667
let funding_txid = Txid::from_str(&funding_txid).unwrap();
660668
let mut consignment_data = ConsignmentBinaryData::default();
661669
let ret = consignment.save(&mut consignment_data);
@@ -680,7 +688,8 @@ impl ColorSourceImpl {
680688
pub fn get_consignment_by_funding_txid(
681689
&self, funding_txid: &Txid,
682690
) -> Option<ConsignmentBinaryData> {
683-
let handle = self.database.consignment().lock().unwrap().get_by_funding_txid(funding_txid)?;
691+
let handle =
692+
self.database.consignment().lock().unwrap().get_by_funding_txid(funding_txid)?;
684693
self.database.consignment().lock().unwrap().resolve(handle).cloned()
685694
}
686695

lightning/src/ln/channelmanager.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7337,6 +7337,7 @@ where
73377337
}
73387338

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

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

73497350
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
73507351
let peer_state = &mut *peer_state_lock;
7352+
println!("internal_funding_created remove channel_id {}", msg.temporary_channel_id);
7353+
73517354
let (mut chan, funding_msg_opt, monitor) =
73527355
match peer_state.channel_by_id.remove(&msg.temporary_channel_id) {
73537356
Some(ChannelPhase::UnfundedInboundV1(inbound_chan)) => {
73547357
let logger = WithChannelContext::from(&self.logger, &inbound_chan.context);
73557358
if let Some(consignment_endpoint) = &inbound_chan.context.consignment_endpoint {
7359+
println!("internal_funding_created call handle_funding");
7360+
73567361
self.color_source.lock().unwrap().handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), consignment_endpoint.clone())?;
7362+
} else {
7363+
println!("internal_funding_created no consignment_endpoint");
73577364
}
73587365
match inbound_chan.funding_created(msg, best_block, &self.signer_provider, &&logger) {
73597366
Ok(res) => res,
@@ -12248,7 +12255,7 @@ where
1224812255
};
1224912256
if let Some(network_pubkey) = received_network_pubkey {
1225012257
if network_pubkey != our_network_pubkey {
12251-
log_error!(args.logger, "Key that was generated does not match the existing key.");
12258+
log_error!(args.logger, "Key that was generated does not match the existing key. left: {}, right: {}", network_pubkey, our_network_pubkey);
1225212259
return Err(DecodeError::InvalidValue);
1225312260
}
1225412261
}

0 commit comments

Comments
 (0)