Skip to content

Commit 6363249

Browse files
committed
Fix logger
1 parent 1a8f945 commit 6363249

6 files changed

Lines changed: 69 additions & 8 deletions

File tree

.github/workflows/rust.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ concurrency:
77
cancel-in-progress: true
88

99
jobs:
10+
probing-tests:
11+
name: Probing Tests
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout source code
15+
uses: actions/checkout@v6
16+
- name: Install Rust stable toolchain
17+
run: |
18+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile=minimal --default-toolchain stable
19+
- name: Enable caching for bitcoind
20+
id: cache-bitcoind
21+
uses: actions/cache@v5
22+
with:
23+
path: bin/bitcoind-${{ runner.os }}-${{ runner.arch }}
24+
key: bitcoind-29.0-${{ runner.os }}-${{ runner.arch }}
25+
- name: Enable caching for electrs
26+
id: cache-electrs
27+
uses: actions/cache@v5
28+
with:
29+
path: bin/electrs-${{ runner.os }}-${{ runner.arch }}
30+
key: electrs-${{ runner.os }}-${{ runner.arch }}
31+
- name: Download bitcoind/electrs
32+
if: "steps.cache-bitcoind.outputs.cache-hit != 'true' || steps.cache-electrs.outputs.cache-hit != 'true'"
33+
run: |
34+
source ./scripts/download_bitcoind_electrs.sh
35+
mkdir -p bin
36+
mv "$BITCOIND_EXE" bin/bitcoind-${{ runner.os }}-${{ runner.arch }}
37+
mv "$ELECTRS_EXE" bin/electrs-${{ runner.os }}-${{ runner.arch }}
38+
- name: Set bitcoind/electrs environment variables
39+
run: |
40+
echo "BITCOIND_EXE=$( pwd )/bin/bitcoind-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
41+
echo "ELECTRS_EXE=$( pwd )/bin/electrs-${{ runner.os }}-${{ runner.arch }}" >> "$GITHUB_ENV"
42+
- name: Build
43+
run: cargo build --verbose --color always
44+
- name: Probing tests
45+
run: |
46+
RUSTFLAGS="--cfg no_download --cfg cycle_tests" cargo test --test probing_tests -- --nocapture
47+
1048
build:
1149
strategy:
1250
matrix:

src/logger.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use chrono::Utc;
1818
use lightning::ln::types::ChannelId;
1919
use lightning::types::payment::PaymentHash;
2020
pub use lightning::util::logger::Level as LogLevel;
21+
22+
use crate::config::DEFAULT_LOG_LEVEL;
2123
pub(crate) use lightning::util::logger::{Logger as LdkLogger, Record as LdkRecord};
2224
pub(crate) use lightning::{log_bytes, log_debug, log_error, log_info, log_trace};
2325
use log::{Level as LogFacadeLevel, Record as LogFacadeRecord};
@@ -181,7 +183,7 @@ pub(crate) enum Writer {
181183
/// Forwards logs to the `log` facade.
182184
LogFacadeWriter,
183185
/// Forwards logs to a custom writer.
184-
CustomWriter(Arc<dyn LogWriter>),
186+
CustomWriter(Arc<dyn LogWriter>, LogLevel),
185187
}
186188

187189
impl LogWriter for Writer {
@@ -246,7 +248,7 @@ impl LogWriter for Writer {
246248
.build(),
247249
);
248250
},
249-
Writer::CustomWriter(custom_logger) => custom_logger.log(record),
251+
Writer::CustomWriter(custom_logger, _) => custom_logger.log(record),
250252
}
251253
}
252254
}
@@ -280,7 +282,7 @@ impl Logger {
280282
}
281283

282284
pub fn new_custom_writer(log_writer: Arc<dyn LogWriter>) -> Self {
283-
Self { writer: Writer::CustomWriter(log_writer) }
285+
Self { writer: Writer::CustomWriter(log_writer, DEFAULT_LOG_LEVEL) }
284286
}
285287
}
286288

@@ -296,7 +298,10 @@ impl LdkLogger for Logger {
296298
Writer::LogFacadeWriter => {
297299
self.writer.log(record.into());
298300
},
299-
Writer::CustomWriter(_arc) => {
301+
Writer::CustomWriter(_arc, max_log_level) => {
302+
if record.level < *max_log_level {
303+
return;
304+
}
300305
self.writer.log(record.into());
301306
},
302307
}

tests/common/logging.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) enum TestLogWriter {
1515

1616
impl Default for TestLogWriter {
1717
fn default() -> Self {
18-
TestLogWriter::FileWriter
18+
TestLogWriter::LogFacade
1919
}
2020
}
2121

tests/common/mod.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,20 @@ pub(crate) fn random_config(anchor_channels: bool) -> TestConfig {
313313

314314
let alias = random_node_alias();
315315
println!("Setting random LDK node alias: {:?}", alias);
316+
317+
let alias_label = alias
318+
.as_ref()
319+
.map(|a| {
320+
let end = a.0.iter().position(|&b| b == 0).unwrap_or(a.0.len());
321+
String::from_utf8_lossy(&a.0[..end]).into_owned()
322+
})
323+
.unwrap_or_else(|| "node".to_string());
324+
316325
node_config.node_alias = alias;
317326

318-
TestConfig { node_config, ..Default::default() }
327+
let log_writer = TestLogWriter::Custom(Arc::new(logging::MultiNodeLogger::new(alias_label)));
328+
329+
TestConfig { node_config, log_writer, ..Default::default() }
319330
}
320331

321332
#[cfg(feature = "uniffi")]

tests/probing_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn build_probe_path(
9494
short_channel_id: ch_ab.short_channel_id.unwrap(),
9595
channel_features: ChannelFeatures::empty(),
9696
fee_msat: 1000,
97-
cltv_expiry_delta: 40,
97+
cltv_expiry_delta: 72,
9898
maybe_announced_channel: true,
9999
},
100100
RouteHop {
@@ -103,7 +103,7 @@ fn build_probe_path(
103103
short_channel_id: ch_bc.short_channel_id.unwrap(),
104104
channel_features: ChannelFeatures::empty(),
105105
fee_msat: amount_msat,
106-
cltv_expiry_delta: 0,
106+
cltv_expiry_delta: 72,
107107
maybe_announced_channel: true,
108108
},
109109
],
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Seeds for failure cases proptest has generated in the past. It is
2+
# automatically read and these particular cases re-run before any
3+
# novel cases are generated.
4+
#
5+
# It is recommended to check this file in to source control so that
6+
# everyone who runs the test benefits from these saved cases.
7+
cc 3e257659bd99fb83b1eccbca7fe71a3551fdd79e30095f3497971cd91e228ae1 # shrinks to reorg_depth = 1, force_close = true

0 commit comments

Comments
 (0)