@@ -6,17 +6,18 @@ use crate::{
66use crate :: logger:: { log_error, log_info, Logger } ;
77
88use lightning:: chain:: chaininterface:: { BroadcasterInterface , ConfirmationTarget , FeeEstimator } ;
9+ use lightning:: events:: Event as LdkEvent ;
10+ use lightning:: events:: EventHandler as LdkEventHandler ;
11+ use lightning:: events:: PaymentPurpose ;
912use lightning:: impl_writeable_tlv_based_enum;
1013use lightning:: ln:: PaymentHash ;
1114use lightning:: routing:: gossip:: NodeId ;
1215use lightning:: util:: errors:: APIError ;
13- use lightning:: util:: events:: Event as LdkEvent ;
14- use lightning:: util:: events:: EventHandler as LdkEventHandler ;
15- use lightning:: util:: events:: PaymentPurpose ;
1616use lightning:: util:: persist:: KVStorePersister ;
1717use lightning:: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
1818
19- use bitcoin:: secp256k1:: Secp256k1 ;
19+ use bitcoin:: secp256k1:: { PublicKey , Secp256k1 } ;
20+ use bitcoin:: OutPoint ;
2021use rand:: { thread_rng, Rng } ;
2122use std:: collections:: { hash_map, VecDeque } ;
2223use std:: ops:: Deref ;
@@ -48,6 +49,19 @@ pub enum Event {
4849 /// The value, in thousandths of a satoshi, that has been received.
4950 amount_msat : u64 ,
5051 } ,
52+ /// A channel has been created and is pending confirmation on-chain.
53+ ChannelPending {
54+ /// The `channel_id` of the channel.
55+ channel_id : [ u8 ; 32 ] ,
56+ /// The `user_channel_id` of the channel.
57+ user_channel_id : u128 ,
58+ /// The `temporary_channel_id` this channel used to be known by during channel establishment.
59+ former_temporary_channel_id : [ u8 ; 32 ] ,
60+ /// The `node_id` of the channel counterparty.
61+ counterparty_node_id : PublicKey ,
62+ /// The outpoint of the channel's funding transaction.
63+ funding_txo : OutPoint ,
64+ } ,
5165 /// A channel is ready to be used.
5266 ChannelReady {
5367 /// The `channel_id` of the channel.
@@ -79,7 +93,14 @@ impl_writeable_tlv_based_enum!(Event,
7993 ( 0 , channel_id, required) ,
8094 ( 1 , user_channel_id, required) ,
8195 } ,
82- ( 4 , ChannelClosed ) => {
96+ ( 4 , ChannelPending ) => {
97+ ( 0 , channel_id, required) ,
98+ ( 1 , user_channel_id, required) ,
99+ ( 2 , former_temporary_channel_id, required) ,
100+ ( 3 , counterparty_node_id, required) ,
101+ ( 4 , funding_txo, required) ,
102+ } ,
103+ ( 5 , ChannelClosed ) => {
83104 ( 0 , channel_id, required) ,
84105 ( 1 , user_channel_id, required) ,
85106 } ;
@@ -455,6 +476,7 @@ where
455476 next_channel_id,
456477 fee_earned_msat,
457478 claim_from_onchain_tx,
479+ outbound_amount_forwarded_msat,
458480 } => {
459481 let read_only_network_graph = self . network_graph . read_only ( ) ;
460482 let nodes = read_only_network_graph. nodes ( ) ;
@@ -474,6 +496,9 @@ where
474496 } )
475497 } )
476498 } ;
499+
500+ let outbound_amount_str =
501+ outbound_amount_forwarded_msat. unwrap_or_default ( ) . to_string ( ) ;
477502 let channel_str = |channel_id : & Option < [ u8 ; 32 ] > | {
478503 channel_id
479504 . map ( |channel_id| {
@@ -493,7 +518,8 @@ where
493518 if claim_from_onchain_tx {
494519 log_info ! (
495520 self . logger,
496- "Forwarded payment{}{}, earning {} msats in fees from claiming onchain." ,
521+ "Forwarded payment of {}msats{}{}, earning {} msats in fees from claiming onchain." ,
522+ outbound_amount_str,
497523 from_prev_str,
498524 to_next_str,
499525 fee_earned,
@@ -508,12 +534,35 @@ where
508534 ) ;
509535 }
510536 }
537+ LdkEvent :: ChannelPending {
538+ channel_id,
539+ user_channel_id,
540+ former_temporary_channel_id,
541+ counterparty_node_id,
542+ funding_txo,
543+ } => {
544+ log_info ! (
545+ self . logger,
546+ "New channel {} with counterparty {} has been created and is pending confirmation on chain." ,
547+ hex_utils:: to_string( & channel_id) ,
548+ counterparty_node_id,
549+ ) ;
550+ self . event_queue
551+ . add_event ( Event :: ChannelPending {
552+ channel_id,
553+ user_channel_id,
554+ former_temporary_channel_id : former_temporary_channel_id. unwrap ( ) ,
555+ counterparty_node_id,
556+ funding_txo,
557+ } )
558+ . expect ( "Failed to push to event queue" ) ;
559+ }
511560 LdkEvent :: ChannelReady {
512561 channel_id, user_channel_id, counterparty_node_id, ..
513562 } => {
514563 log_info ! (
515564 self . logger,
516- "Channel {} with {} ready to be used." ,
565+ "Channel {} with counterparty {} ready to be used." ,
517566 hex_utils:: to_string( & channel_id) ,
518567 counterparty_node_id,
519568 ) ;
0 commit comments