Skip to content

Commit bfc31ea

Browse files
committed
fix errors during handle_funding
1 parent 3249885 commit bfc31ea

3 files changed

Lines changed: 28 additions & 32 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ impl fmt::Display for ChannelError {
967967
}
968968

969969
impl ChannelError {
970-
pub(super) fn close(err: String) -> Self {
970+
pub(crate) fn close(err: String) -> Self {
971971
ChannelError::Close((err.clone(), ClosureReason::ProcessingError { err }))
972972
}
973973
}

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,14 +954,14 @@ impl Into<LocalHTLCFailureReason> for FailureCode {
954954
/// immediately (ie with no further calls on it made). Thus, this step happens inside a
955955
/// peer_state lock. We then return the set of things that need to be done outside the lock in
956956
/// this struct and call handle_error!() on it.
957-
pub(crate) struct MsgHandleErrInternal {
957+
struct MsgHandleErrInternal {
958958
err: msgs::LightningError,
959959
closes_channel: bool,
960960
shutdown_finish: Option<(ShutdownResult, Option<msgs::ChannelUpdate>)>,
961961
tx_abort: Option<msgs::TxAbort>,
962962
}
963963
impl MsgHandleErrInternal {
964-
pub(crate) fn send_err_msg_no_close(err: String, channel_id: ChannelId) -> Self {
964+
fn send_err_msg_no_close(err: String, channel_id: ChannelId) -> Self {
965965
Self {
966966
err: LightningError {
967967
err: err.clone(),
@@ -10453,7 +10453,16 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1045310453
Some(Ok(inbound_chan)) => {
1045410454
let logger = WithChannelContext::from(&self.logger, &inbound_chan.context, None);
1045510455
if let Some(consignment_endpoint) = &inbound_chan.funding.consignment_endpoint {
10456-
handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), &self.ldk_data_dir, consignment_endpoint.clone(), inbound_chan.funding.push_asset_amount)?;
10456+
match handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), &self.ldk_data_dir, consignment_endpoint.clone(), inbound_chan.funding.push_asset_amount) {
10457+
Ok(()) => (),
10458+
Err(e) => {
10459+
// at this point the channel initiator already transitioned its channel to the funded channel ID
10460+
let mut chan = Channel::from(inbound_chan);
10461+
let funding_txo = OutPoint { txid: msg.funding_txid, index: msg.funding_output_index };
10462+
chan.context_mut().channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
10463+
return Err(convert_channel_err!(self, peer_state, e, &mut chan).1);
10464+
},
10465+
}
1045710466
}
1045810467
match inbound_chan.funding_created(msg, best_block, &self.signer_provider, &&logger) {
1045910468
Ok(res) => res,

lightning/src/rgb_utils/mod.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::ln::chan_utils::{
66
};
77
use crate::ln::channel::{ChannelContext, ChannelError, FundingScope};
88
use crate::ln::channel_state::ChannelDetails;
9-
use crate::ln::channelmanager::MsgHandleErrInternal;
109
use crate::ln::types::ChannelId;
1110
use crate::sign::SignerProvider;
1211
use crate::types::features::ChannelTypeFeatures;
@@ -218,7 +217,7 @@ async fn _accept_transfer(
218217
account_xpub_colored,
219218
master_fingerprint,
220219
);
221-
wallet.go_online(true, indexer_url).unwrap();
220+
wallet.go_online(true, indexer_url)?;
222221
wallet.accept_transfer(
223222
funding_txid.clone(),
224223
funding_vout,
@@ -648,7 +647,7 @@ pub(crate) fn rename_rgb_files(
648647
pub(crate) fn handle_funding(
649648
temporary_channel_id: &ChannelId, funding_txid: String, ldk_data_dir: &Path,
650649
consignment_endpoint: RgbTransport, push_asset_amount: Option<u64>,
651-
) -> Result<(), MsgHandleErrInternal> {
650+
) -> Result<(), ChannelError> {
652651
let handle = Handle::current();
653652
let _ = handle.enter();
654653
let accept_res = futures::executor::block_on(_accept_transfer(
@@ -659,35 +658,23 @@ pub(crate) fn handle_funding(
659658
let (consignment, remote_rgb_assignments) = match accept_res {
660659
Ok(res) => res,
661660
Err(RgbLibError::InvalidConsignment) => {
662-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
663-
"Invalid RGB consignment for funding".to_owned(),
664-
*temporary_channel_id,
665-
))
661+
return Err(ChannelError::close("Invalid RGB consignment for funding".to_owned()))
666662
},
667663
Err(RgbLibError::NoConsignment) => {
668-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
669-
"Failed to find RGB consignment".to_owned(),
670-
*temporary_channel_id,
671-
))
664+
return Err(ChannelError::close("Failed to find RGB consignment".to_owned()))
672665
},
673666
Err(RgbLibError::UnknownRgbSchema { schema_id }) => {
674-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
675-
format!("Unknown RGB schema: {schema_id}"),
676-
*temporary_channel_id,
677-
))
667+
return Err(ChannelError::close(format!("Unknown RGB schema: {schema_id}")))
678668
},
679669
Err(RgbLibError::UnsupportedSchema { asset_schema }) => {
680-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
681-
format!("Unsupported RGB schema: {asset_schema}"),
682-
*temporary_channel_id,
683-
))
670+
return Err(ChannelError::close(format!("Unsupported RGB schema: {asset_schema}")))
684671
},
685-
Err(e) => {
686-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
687-
format!("Unexpected error: {e}"),
688-
*temporary_channel_id,
689-
))
672+
Err(RgbLibError::Indexer { details })
673+
| Err(RgbLibError::InvalidIndexer { details })
674+
| Err(RgbLibError::Network { details }) => {
675+
return Err(ChannelError::close(format!("Failed to connect to indexer: {details}")))
690676
},
677+
Err(e) => return Err(ChannelError::close(format!("Unexpected error: {e}"))),
691678
};
692679

693680
let consignment_path = ldk_data_dir.join(format!("consignment_{}", funding_txid));
@@ -697,10 +684,10 @@ pub(crate) fn handle_funding(
697684
consignment.save_file(consignment_path).expect("unable to write file");
698685

699686
if remote_rgb_assignments.len() != 1 {
700-
return Err(MsgHandleErrInternal::send_err_msg_no_close(
701-
format!("Unexpected number of RGB assignments: {}", remote_rgb_assignments.len()),
702-
*temporary_channel_id,
703-
));
687+
return Err(ChannelError::close(format!(
688+
"Unexpected number of RGB assignments: {}",
689+
remote_rgb_assignments.len()
690+
)));
704691
}
705692
let channel_rgb_amount = match remote_rgb_assignments[0] {
706693
Assignment::Fungible(amt) => amt,

0 commit comments

Comments
 (0)