@@ -4480,7 +4480,7 @@ where
4480
4480
4481
4481
/// Handles the generation of a funding transaction, optionally (for tests) with a function
4482
4482
/// which checks the correctness of the funding transaction given the associated channel.
4483
- fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, APIError >>(
4483
+ fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>, &Transaction) -> Result<OutPoint, &'static str >>(
4484
4484
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, is_batch_funding: bool,
4485
4485
mut find_funding_output: FundingOutput,
4486
4486
) -> Result<(), APIError> {
@@ -4493,26 +4493,38 @@ where
4493
4493
let funding_txo;
4494
4494
let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(temporary_channel_id) {
4495
4495
Some(ChannelPhase::UnfundedOutboundV1(mut chan)) => {
4496
- funding_txo = find_funding_output(&chan, &funding_transaction)?;
4496
+ macro_rules! close_chan { ($err: expr, $api_err: expr, $chan: expr) => { {
4497
+ let counterparty;
4498
+ let err = if let ChannelError::Close(msg) = $err {
4499
+ let channel_id = $chan.context.channel_id();
4500
+ counterparty = chan.context.get_counterparty_node_id();
4501
+ let reason = ClosureReason::ProcessingError { err: msg.clone() };
4502
+ let shutdown_res = $chan.context.force_shutdown(false, reason);
4503
+ MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None)
4504
+ } else { unreachable!(); };
4505
+
4506
+ mem::drop(peer_state_lock);
4507
+ mem::drop(per_peer_state);
4508
+ let _: Result<(), _> = handle_error!(self, Err(err), counterparty);
4509
+ Err($api_err)
4510
+ } } }
4511
+ match find_funding_output(&chan, &funding_transaction) {
4512
+ Ok(found_funding_txo) => funding_txo = found_funding_txo,
4513
+ Err(err) => {
4514
+ let chan_err = ChannelError::Close(err.to_owned());
4515
+ let api_err = APIError::APIMisuseError { err: err.to_owned() };
4516
+ return close_chan!(chan_err, api_err, chan);
4517
+ },
4518
+ }
4497
4519
4498
4520
let logger = WithChannelContext::from(&self.logger, &chan.context);
4499
- let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger)
4500
- .map_err(|(mut chan, e)| if let ChannelError::Close(msg) = e {
4501
- let channel_id = chan.context.channel_id();
4502
- let reason = ClosureReason::ProcessingError { err: msg.clone() };
4503
- let shutdown_res = chan.context.force_shutdown(false, reason);
4504
- (chan, MsgHandleErrInternal::from_finish_shutdown(msg, channel_id, shutdown_res, None))
4505
- } else { unreachable!(); });
4521
+ let funding_res = chan.get_funding_created(funding_transaction, funding_txo, is_batch_funding, &&logger);
4506
4522
match funding_res {
4507
4523
Ok(funding_msg) => (chan, funding_msg),
4508
- Err((chan, err)) => {
4509
- mem::drop(peer_state_lock);
4510
- mem::drop(per_peer_state);
4511
- let _: Result<(), _> = handle_error!(self, Err(err), chan.context.get_counterparty_node_id());
4512
- return Err(APIError::ChannelUnavailable {
4513
- err: "Signer refused to sign the initial commitment transaction".to_owned()
4514
- });
4515
- },
4524
+ Err((mut chan, chan_err)) => {
4525
+ let api_err = APIError::ChannelUnavailable { err: "Signer refused to sign the initial commitment transaction".to_owned() };
4526
+ return close_chan!(chan_err, api_err, chan);
4527
+ }
4516
4528
}
4517
4529
},
4518
4530
Some(phase) => {
@@ -4677,17 +4689,13 @@ where
4677
4689
for (idx, outp) in tx.output.iter().enumerate() {
4678
4690
if outp.script_pubkey == expected_spk && outp.value == chan.context.get_value_satoshis() {
4679
4691
if output_index.is_some() {
4680
- return Err(APIError::APIMisuseError {
4681
- err: "Multiple outputs matched the expected script and value".to_owned()
4682
- });
4692
+ return Err("Multiple outputs matched the expected script and value");
4683
4693
}
4684
4694
output_index = Some(idx as u16);
4685
4695
}
4686
4696
}
4687
4697
if output_index.is_none() {
4688
- return Err(APIError::APIMisuseError {
4689
- err: "No output matched the script_pubkey and value in the FundingGenerationReady event".to_owned()
4690
- });
4698
+ return Err("No output matched the script_pubkey and value in the FundingGenerationReady event");
4691
4699
}
4692
4700
let outpoint = OutPoint { txid: tx.txid(), index: output_index.unwrap() };
4693
4701
if let Some(funding_batch_state) = funding_batch_state.as_mut() {
0 commit comments