Skip to content

Commit ceab25c

Browse files
event: store the outpoint when is_manual_broadcast
With [1], it's possible to specify `manual_broadcast` for the channel funding transaction. When `is_manual_broadcast` is set to true, the transaction in the `DiscardFunding` event is replaced with a dummy empty transaction. This commit checks if `is_manual_broadcast` is true and stores the funding OutPoint in the DiscardFunding event instead. [1] #3024 Link: #3164 Suggested-by: TheBlueMatt Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
1 parent b2cdc2c commit ceab25c

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

lightning/src/events/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::blinded_path::message::OffersContext;
2222
use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext, PaymentContextRef};
2323
use crate::chain::transaction;
2424
use crate::ln::channelmanager::{InterceptId, PaymentId, RecipientOnionFields};
25-
use crate::ln::channel::FUNDING_CONF_DEADLINE_BLOCKS;
25+
use crate::ln::channel::{FundingInfo, FUNDING_CONF_DEADLINE_BLOCKS};
2626
use crate::ln::features::ChannelTypeFeatures;
2727
use crate::ln::msgs;
2828
use crate::ln::types::{ChannelId, PaymentPreimage, PaymentHash, PaymentSecret};
@@ -1257,7 +1257,7 @@ pub enum Event {
12571257
/// The channel_id of the channel which has been closed.
12581258
channel_id: ChannelId,
12591259
/// The full transaction received from the user
1260-
transaction: Transaction
1260+
funding_info: FundingInfo,
12611261
},
12621262
/// Indicates a request to open a new channel by a peer.
12631263
///
@@ -1541,7 +1541,7 @@ impl Writeable for Event {
15411541
(9, channel_funding_txo, option),
15421542
});
15431543
},
1544-
&Event::DiscardFunding { ref channel_id, ref transaction } => {
1544+
&Event::DiscardFunding { ref channel_id, funding_info: ref transaction } => {
15451545
11u8.write(writer)?;
15461546
write_tlv_fields!(writer, {
15471547
(0, channel_id, required),
@@ -1929,7 +1929,9 @@ impl MaybeReadable for Event {
19291929
(0, channel_id, required),
19301930
(2, transaction, required),
19311931
});
1932-
Ok(Some(Event::DiscardFunding { channel_id, transaction } ))
1932+
// FIXME: what it is going on here? we are sure taht we need an tx? or we can just create a simple
1933+
// outpoint?
1934+
Ok(Some(Event::DiscardFunding { channel_id, funding_info: transaction.into() } ))
19331935
};
19341936
f()
19351937
},

lightning/src/ln/channel.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,36 @@ pub(super) struct ReestablishResponses {
918918
pub shutdown_msg: Option<msgs::Shutdown>,
919919
}
920920

921+
// FIXME(vincenzopalazzo): There is a better plave where to expose this type?
922+
#[derive(Debug, PartialEq, Eq, Clone)]
923+
pub enum FundingInfo {
924+
Tx(Transaction),
925+
OutPoint(OutPoint),
926+
}
927+
928+
impl Writeable for FundingInfo {
929+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
930+
match self {
931+
Self::OutPoint(o) => o.write(writer),
932+
Self::Tx(tx) => tx.write(writer),
933+
}
934+
}
935+
}
936+
937+
impl From<Transaction> for FundingInfo {
938+
fn from(value: Transaction) -> Self {
939+
Self::Tx(value)
940+
}
941+
}
942+
943+
impl From<OutPoint> for FundingInfo {
944+
fn from(value: OutPoint) -> Self {
945+
Self::OutPoint(value)
946+
}
947+
}
948+
949+
950+
921951
/// The result of a shutdown that should be handled.
922952
#[must_use]
923953
pub(crate) struct ShutdownResult {

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::events::{Event, EventHandler, EventsProvider, MessageSendEvent, Messa
4747
// construct one themselves.
4848
use crate::ln::inbound_payment;
4949
use crate::ln::types::{ChannelId, PaymentHash, PaymentPreimage, PaymentSecret};
50-
use crate::ln::channel::{self, Channel, ChannelPhase, ChannelContext, ChannelError, ChannelUpdateStatus, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, OutboundV1Channel, InboundV1Channel, WithChannelContext};
50+
use crate::ln::channel::{self, Channel, ChannelContext, ChannelError, ChannelPhase, ChannelUpdateStatus, FundingInfo, InboundV1Channel, OutboundV1Channel, ShutdownResult, UnfundedChannelContext, UpdateFulfillCommitFetch, WithChannelContext};
5151
use crate::ln::channel_state::ChannelDetails;
5252
use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
5353
#[cfg(any(feature = "_test_utils", test))]
@@ -3509,6 +3509,7 @@ where
35093509
let _ = self.chain_monitor.update_channel(funding_txo, &monitor_update);
35103510
}
35113511
let mut shutdown_results = Vec::new();
3512+
let mut is_manual_broadcast = false;
35123513
if let Some(txid) = shutdown_res.unbroadcasted_batch_funding_txid {
35133514
let mut funding_batch_states = self.funding_batch_states.lock().unwrap();
35143515
let affected_channels = funding_batch_states.remove(&txid).into_iter().flatten();
@@ -3518,6 +3519,10 @@ where
35183519
if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) {
35193520
let mut peer_state = peer_state_mutex.lock().unwrap();
35203521
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
3522+
// We override the previous value, so we could change from true -> false,
3523+
// but this is fine because if a channel has manual_broadcast set to false
3524+
// we should choose the safier condition.
3525+
is_manual_broadcast = chan.context().is_manual_broadcast();
35213526
update_maps_on_chan_removal!(self, &chan.context());
35223527
shutdown_results.push(chan.context_mut().force_shutdown(false, ClosureReason::FundingBatchClosure));
35233528
}
@@ -3541,9 +3546,14 @@ where
35413546
channel_funding_txo: shutdown_res.channel_funding_txo,
35423547
}, None));
35433548

3544-
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
3549+
let funding_info = if is_manual_broadcast {
3550+
shutdown_res.channel_funding_txo.map(FundingInfo::from)
3551+
} else {
3552+
shutdown_res.unbroadcasted_funding_tx.map(FundingInfo::from)
3553+
};
3554+
if let Some(funding_info) = funding_info {
35453555
pending_events.push_back((events::Event::DiscardFunding {
3546-
channel_id: shutdown_res.channel_id, transaction
3556+
channel_id: shutdown_res.channel_id, funding_info
35473557
}, None));
35483558
}
35493559
}

0 commit comments

Comments
 (0)