Skip to content

Commit 6be1a03

Browse files
committed
wip
1 parent e508636 commit 6be1a03

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

lightning-macros/src/lib.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,18 @@ pub fn auto_span_methods(_attr: TokenStream, item: TokenStream) -> TokenStream {
408408

409409
for item in input.items.iter_mut() {
410410
if let ImplItem::Fn(method) = item {
411-
if let Visibility::Public(_) = method.vis {
412-
// Skip the method that sets the node_span
413-
if method.sig.ident == "set_node_id" {
414-
continue;
415-
}
411+
// Skip the method that sets the node_span
412+
if method.sig.ident == "set_node_id" {
413+
continue;
414+
}
416415

417-
if let Some(FnArg::Receiver(_)) = method.sig.inputs.first() {
418-
let block = &method.block;
419-
method.block = syn::parse_quote!({
420-
let _entered_span = self.node_span.enter();
421-
#block
422-
});
423-
}
416+
if let Some(FnArg::Receiver(_)) = method.sig.inputs.first() {
417+
let block = &method.block;
418+
let method_name = method.sig.ident.to_string();
419+
method.block = syn::parse_quote!({
420+
let _entered_span = tracing::span!(tracing::Level::INFO, #method_name, node_id = self.node_id).entered();
421+
#block
422+
});
424423
}
425424
}
426425
}

lightning/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ libm = { version = "0.2", default-features = false }
5252
inventory = { version = "0.3", optional = true }
5353
tracing = "0.1.41"
5454
tracing-subscriber = "0.3.20"
55+
tracing-tree = "0.4.1"
5556

5657
[dev-dependencies]
5758
regex = "1.5.6"

lightning/src/ln/channel.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13496,6 +13496,8 @@ where
1349613496
};
1349713497
let keys = self.funding.get_holder_pubkeys();
1349813498

13499+
log_trace!(_logger, "Channel opened");
13500+
1349913501
Some(msgs::OpenChannel {
1350013502
common_fields: msgs::CommonOpenChannelFields {
1350113503
chain_hash,

lightning/src/ln/channelmanager.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,7 +2928,7 @@ pub struct ChannelManager<
29282928

29292929
logger: L,
29302930

2931-
node_span: tracing::Span,
2931+
node_id: String,
29322932
}
29332933

29342934
/// Chain-related parameters used to construct a new `ChannelManager`.
@@ -4047,12 +4047,12 @@ where
40474047
#[cfg(feature = "_test_utils")]
40484048
testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
40494049

4050-
node_span: tracing::span!(tracing::Level::INFO, "node"),
4050+
node_id : "?".to_string(),
40514051
}
40524052
}
40534053

40544054
pub fn set_node_id(&mut self, id: String) {
4055-
self.node_span = tracing::span!(tracing::Level::INFO, "node", node_id = id);
4055+
self.node_id = id;
40564056
}
40574057

40584058
/// Gets the current [`UserConfig`] which controls some global behavior and includes the
@@ -4135,8 +4135,6 @@ where
41354135
/// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
41364136
#[rustfmt::skip]
41374137
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_channel_id: u128, temporary_channel_id: Option<ChannelId>, override_config: Option<UserConfig>) -> Result<ChannelId, APIError> {
4138-
tracing::info!("create_channel called");
4139-
41404138
if channel_value_satoshis < 1000 {
41414139
return Err(APIError::APIMisuseError { err: format!("Channel value must be at least 1000 satoshis. It was {}", channel_value_satoshis) });
41424140
}
@@ -12825,6 +12823,7 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
1282512823
}
1282612824
} }
1282712825

12826+
#[lightning_macros::auto_span_methods]
1282812827
impl<
1282912828
M: Deref,
1283012829
T: Deref,
@@ -13680,6 +13679,7 @@ where
1368013679
}
1368113680
}
1368213681

13682+
#[lightning_macros::auto_span_methods]
1368313683
impl<
1368413684
M: Deref,
1368513685
T: Deref,
@@ -14021,6 +14021,7 @@ where
1402114021
}
1402214022
}
1402314023

14024+
#[lightning_macros::auto_span_methods]
1402414025
impl<
1402514026
M: Deref,
1402614027
T: Deref,
@@ -14056,6 +14057,7 @@ where
1405614057
}
1405714058
}
1405814059

14060+
#[lightning_macros::auto_span_methods]
1405914061
impl<
1406014062
M: Deref,
1406114063
T: Deref,
@@ -14117,6 +14119,7 @@ where
1411714119
}
1411814120
}
1411914121

14122+
#[lightning_macros::auto_span_methods]
1412014123
impl<
1412114124
M: Deref,
1412214125
T: Deref,
@@ -14617,6 +14620,7 @@ where
1461714620
}
1461814621
}
1461914622

14623+
#[lightning_macros::auto_span_methods]
1462014624
impl<
1462114625
M: Deref,
1462214626
T: Deref,
@@ -15192,6 +15196,7 @@ where
1519215196
}
1519315197
}
1519415198

15199+
#[lightning_macros::auto_span_methods]
1519515200
impl<
1519615201
M: Deref,
1519715202
T: Deref,
@@ -15411,6 +15416,7 @@ where
1541115416
}
1541215417
}
1541315418

15419+
#[lightning_macros::auto_span_methods]
1541415420
impl<
1541515421
M: Deref,
1541615422
T: Deref,
@@ -15681,6 +15687,7 @@ where
1568115687
}
1568215688
}
1568315689

15690+
#[lightning_macros::auto_span_methods]
1568415691
impl<
1568515692
M: Deref,
1568615693
T: Deref,
@@ -16196,6 +16203,7 @@ impl_writeable_tlv_based!(PendingInboundPayment, {
1619616203
(8, min_value_msat, required),
1619716204
});
1619816205

16206+
#[lightning_macros::auto_span_methods]
1619916207
impl<
1620016208
M: Deref,
1620116209
T: Deref,
@@ -18133,7 +18141,7 @@ where
1813318141

1813418142
#[cfg(feature = "_test_utils")]
1813518143
testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
18136-
node_span: tracing::span!(tracing::Level::INFO, "node"),
18144+
node_id: "?".to_string(),
1813718145
};
1813818146

1813918147
let mut processed_claims: HashSet<Vec<MPPClaimHTLCSource>> = new_hash_set();

lightning/src/ln/payment_tests.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ use crate::util::ser::Writeable;
5151
use crate::util::test_utils::{self, TestTracerLayer};
5252

5353
use tracing_subscriber::fmt::format::FmtSpan;
54-
use tracing_subscriber::{fmt, prelude::*};
54+
use tracing_subscriber::{fmt, prelude::*, Registry};
5555

5656
use bitcoin::hashes::sha256::Hash as Sha256;
5757
use bitcoin::hashes::Hash;
5858
use bitcoin::network::Network;
5959
use bitcoin::secp256k1::{Secp256k1, SecretKey};
60+
use tracing_tree::HierarchicalLayer;
6061

6162
use crate::prelude::*;
6263

@@ -433,9 +434,17 @@ fn mpp_receive_timeout() {
433434

434435
#[test]
435436
fn test_keysend_payments() {
436-
// tracing_subscriber::fmt().init();
437+
let layer = HierarchicalLayer::new(5) // indent by 2 spaces
438+
.with_ansi(true)
439+
.with_targets(true)
440+
.with_deferred_spans(true);
441+
//.with_indent_lines(true);
442+
443+
let subscriber = Registry::default().with(layer);
444+
tracing::subscriber::set_global_default(subscriber).unwrap();
445+
437446
// tracing_subscriber::fmt()
438-
// // .with_span_list(true) // <--- print parent span chain
447+
// .with_max_level(tracing::Level::TRACE)
439448
// .with_span_events(FmtSpan::FULL)
440449
// .init();
441450

@@ -444,14 +453,7 @@ fn test_keysend_payments() {
444453
}
445454

446455
fn do_test_keysend_payments(public_node: bool) {
447-
let layer = TestTracerLayer {};
448-
let subscriber = tracing_subscriber::registry().with(layer);
449-
let _guard = tracing::subscriber::set_default(subscriber);
450-
{
451-
let _enter = tracing::info_span!("hello").entered();
452-
tracing::info!("Hello from tracing!");
453-
}
454-
456+
let span = tracing::info_span!("node setup");
455457
let chanmon_cfgs = create_chanmon_cfgs(2);
456458
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
457459
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
@@ -465,19 +467,26 @@ fn do_test_keysend_payments(public_node: bool) {
465467
} else {
466468
create_chan_between_nodes(&nodes[0], &nodes[1]);
467469
}
470+
471+
drop(span);
472+
468473
let route_params = RouteParameters::from_payment_params_and_value(
469474
PaymentParameters::for_keysend(node_b_id, 40, false),
470475
10000,
471476
);
472477

473478
{
479+
let _span = tracing::info_span!("initiate payment").entered();
480+
474481
let preimage = Some(PaymentPreimage([42; 32]));
475482
let onion = RecipientOnionFields::spontaneous_empty();
476483
let retry = Retry::Attempts(1);
477484
let id = PaymentId([42; 32]);
478485
nodes[0].node.send_spontaneous_payment(preimage, onion, id, route_params, retry).unwrap();
479486
}
480487

488+
let _span = tracing::info_span!("propagate htlc and claim payment").entered();
489+
481490
check_added_monitors!(nodes[0], 1);
482491
let send_event = SendEvent::from_node(&nodes[0]);
483492
nodes[1].node.handle_update_add_htlc(node_a_id, &send_event.msgs[0]);

0 commit comments

Comments
 (0)