Skip to content

Commit a2ea38d

Browse files
committed
Make funding_transaction_generated take a ChannelId by value
`ChannelId` is just a 32-byte array, so there's not a lot of value in passing it by reference to `funding_transaction_generated`, which we fix here. This is also nice for bindings as languages like Java can better analyze whether the `ChannelManager` ends up with a reference to the `ChannelId`.
1 parent 50d21b7 commit a2ea38d

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ where
14521452
/// channel_value_satoshis, output_script
14531453
/// );
14541454
/// match channel_manager.funding_transaction_generated(
1455-
/// &temporary_channel_id, &counterparty_node_id, funding_transaction
1455+
/// temporary_channel_id, counterparty_node_id, funding_transaction
14561456
/// ) {
14571457
/// Ok(()) => println!("Funding channel {}", temporary_channel_id),
14581458
/// Err(e) => println!("Error funding channel {}: {:?}", temporary_channel_id, e),
@@ -4444,17 +4444,17 @@ where
44444444
/// Handles the generation of a funding transaction, optionally (for tests) with a function
44454445
/// which checks the correctness of the funding transaction given the associated channel.
44464446
fn funding_transaction_generated_intern<FundingOutput: FnMut(&OutboundV1Channel<SP>) -> Result<OutPoint, &'static str>>(
4447-
&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, is_batch_funding: bool,
4447+
&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction, is_batch_funding: bool,
44484448
mut find_funding_output: FundingOutput, is_manual_broadcast: bool,
44494449
) -> Result<(), APIError> {
44504450
let per_peer_state = self.per_peer_state.read().unwrap();
4451-
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
4451+
let peer_state_mutex = per_peer_state.get(&counterparty_node_id)
44524452
.ok_or_else(|| APIError::ChannelUnavailable { err: format!("Can't find a peer matching the passed counterparty node_id {}", counterparty_node_id) })?;
44534453

44544454
let mut peer_state_lock = peer_state_mutex.lock().unwrap();
44554455
let peer_state = &mut *peer_state_lock;
44564456
let funding_txo;
4457-
let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(temporary_channel_id) {
4457+
let (mut chan, msg_opt) = match peer_state.channel_by_id.remove(&temporary_channel_id) {
44584458
Some(ChannelPhase::UnfundedOutboundV1(mut chan)) => {
44594459
macro_rules! close_chan { ($err: expr, $api_err: expr, $chan: expr) => { {
44604460
let counterparty;
@@ -4490,7 +4490,7 @@ where
44904490
}
44914491
},
44924492
Some(phase) => {
4493-
peer_state.channel_by_id.insert(*temporary_channel_id, phase);
4493+
peer_state.channel_by_id.insert(temporary_channel_id, phase);
44944494
return Err(APIError::APIMisuseError {
44954495
err: format!(
44964496
"Channel with id {} for the passed counterparty node_id {} is not an unfunded, outbound V1 channel",
@@ -4540,7 +4540,7 @@ where
45404540
}
45414541

45424542
#[cfg(test)]
4543-
pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> {
4543+
pub(crate) fn funding_transaction_generated_unchecked(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction, output_index: u16) -> Result<(), APIError> {
45444544
let txid = funding_transaction.txid();
45454545
self.funding_transaction_generated_intern(temporary_channel_id, counterparty_node_id, funding_transaction, false, |_| {
45464546
Ok(OutPoint { txid, index: output_index })
@@ -4577,8 +4577,8 @@ where
45774577
///
45784578
/// [`Event::FundingGenerationReady`]: crate::events::Event::FundingGenerationReady
45794579
/// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
4580-
pub fn funding_transaction_generated(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding_transaction: Transaction) -> Result<(), APIError> {
4581-
self.batch_funding_transaction_generated(&[(temporary_channel_id, counterparty_node_id)], funding_transaction)
4580+
pub fn funding_transaction_generated(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding_transaction: Transaction) -> Result<(), APIError> {
4581+
self.batch_funding_transaction_generated(&[(&temporary_channel_id, &counterparty_node_id)], funding_transaction)
45824582
}
45834583

45844584

@@ -4609,10 +4609,10 @@ where
46094609
/// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
46104610
/// [`Event::ChannelClosed`]: crate::events::Event::ChannelClosed
46114611
/// [`ChannelManager::funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::funding_transaction_generated
4612-
pub fn unsafe_manual_funding_transaction_generated(&self, temporary_channel_id: &ChannelId, counterparty_node_id: &PublicKey, funding: OutPoint) -> Result<(), APIError> {
4612+
pub fn unsafe_manual_funding_transaction_generated(&self, temporary_channel_id: ChannelId, counterparty_node_id: PublicKey, funding: OutPoint) -> Result<(), APIError> {
46134613
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
46144614

4615-
let temporary_channels = &[(temporary_channel_id, counterparty_node_id)];
4615+
let temporary_channels = &[(&temporary_channel_id, &counterparty_node_id)];
46164616
return self.batch_funding_transaction_generated_intern(temporary_channels, FundingType::Unchecked(funding));
46174617

46184618
}
@@ -4686,8 +4686,8 @@ where
46864686
let is_manual_broadcast = funding.is_manual_broadcast();
46874687
for &(temporary_channel_id, counterparty_node_id) in temporary_channels {
46884688
result = result.and_then(|_| self.funding_transaction_generated_intern(
4689-
temporary_channel_id,
4690-
counterparty_node_id,
4689+
*temporary_channel_id,
4690+
*counterparty_node_id,
46914691
funding.transaction_or_dummy(),
46924692
is_batch_funding,
46934693
|chan| {

0 commit comments

Comments
 (0)