Skip to content

Commit 0698671

Browse files
committed
improve testping, remove rpc delay from pings
1 parent 51d5451 commit 0698671

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
- new boolean option to leak the reason in the reject message: ``clnrod-leakreason``, defaults to `false`
88
- method usage returned by ``lightning-cli help``
99
- defaults for options returned by ``lightning-cli listconfigs``
10+
- ``clnrod-testping`` also returns the median ping
1011

1112
### Changed
1213
- empty ``clnrod-denymessage`` no longer allowed, please let your peer know it's not a lightning bug
14+
- ``clnrod-testping`` now connects automatically to the peer
15+
- ``clnrod-testping`` length argument now defaults to ``clnrod-pinglength``
16+
- all ping measurements were subtracted by a rpc delay amount but after pings started working properly in 25.09 it turns out this would lead to unrealistically low pings, so i removed that and as a result pings might be slightly higher now
1317

1418
### Fixed
15-
- cache invalidation bug: multiple quick opening attempts with different opening specific data like ``their_funding_sat`` would use the first value from cache
19+
- cache invalidation bug: multiple quick (within 1 hour) opening attempts with different opening specific data like ``their_funding_sat`` would use the first value from cache
1620

1721
## [0.4.3] - 2025-10-16
1822

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ New rpc methods with this plugin:
102102
* **clnrod-testmail**
103103
* send a test mail to check your email config
104104
* **clnrod-testping** *pubkey* [*count*] [*length*]
105-
* measure the time it takes in ms to send a *length* (Default: 256) bytes message to the node with *pubkey* and back. Pings *count* (Default: 3) times. You must connect to the node first!
105+
* measure the time it takes in ms to send a *length* (Defaults to ``clnrod-pinglength``) bytes message to the node with *pubkey* and back. Pings *count* (Default: 3) times.
106106

107107

108108
## Blockmode: allow

src/collect.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ use anyhow::{anyhow, Error};
88
use cln_plugin::Plugin;
99
use cln_rpc::{
1010
model::{
11-
requests::{
12-
GetinfoRequest, ListchannelsRequest, ListnodesRequest, ListpeerchannelsRequest,
13-
PingRequest,
14-
},
11+
requests::{ListchannelsRequest, ListnodesRequest, ListpeerchannelsRequest, PingRequest},
1512
responses::ListnodesNodesAddressesType,
1613
},
1714
primitives::{Amount, ChannelState, PublicKey},
@@ -461,13 +458,6 @@ pub async fn ln_ping(
461458
let rpc_path =
462459
Path::new(&plugin.configuration().lightning_dir).join(plugin.configuration().rpc_file);
463460
let mut rpc = ClnRpc::new(rpc_path).await?;
464-
let now_delay = Instant::now();
465-
let _dummy_rpc = rpc.call_typed(&GetinfoRequest {}).await;
466-
let rpc_delay = now_delay.elapsed().as_millis() as u16;
467-
log::info!(
468-
"Rpc delay that will be subtracted from ping: {}ms",
469-
rpc_delay
470-
);
471461
let mut results = Vec::new();
472462
let mut c = 0;
473463
while c < count {
@@ -514,7 +504,7 @@ pub async fn ln_ping(
514504
if ping_response.totlen < ping_length {
515505
log::info!("Did not receive the full length ping back");
516506
}
517-
let ping = (now.elapsed().as_millis() as u16).saturating_sub(rpc_delay);
507+
let ping = now.elapsed().as_millis() as u16;
518508
log::info!(
519509
"Pinged {} {}/{} times with {} bytes in {}ms",
520510
pubkey,
@@ -527,5 +517,6 @@ pub async fn ln_ping(
527517
time::sleep(Duration::from_millis(250)).await;
528518
}
529519

520+
results.sort();
530521
Ok(results)
531522
}

src/rpc.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ use std::{path::Path, str::FromStr};
22

33
use anyhow::{anyhow, Context, Error};
44
use cln_plugin::Plugin;
5-
use cln_rpc::primitives::{Amount, PublicKey};
5+
use cln_rpc::{
6+
model::requests::ConnectRequest,
7+
primitives::{Amount, PublicKey},
8+
ClnRpc,
9+
};
610
use serde_json::json;
711

812
use crate::{
@@ -152,7 +156,7 @@ pub async fn clnrod_testping(
152156
let length = if let Some(pk) = o.get("length") {
153157
u16::try_from(pk.as_u64().ok_or_else(|| anyhow!("bad length number"))?)?
154158
} else {
155-
256
159+
plugin.state().config.lock().ping_length
156160
};
157161
(pubkey_str, count, length)
158162
}
@@ -178,7 +182,7 @@ pub async fn clnrod_testping(
178182
u16::try_from(c.as_u64().ok_or_else(|| anyhow!("bad length number"))?)
179183
.context("length out of valid range")?
180184
} else {
181-
256
185+
plugin.state().config.lock().ping_length
182186
};
183187
(pubkey_str, count, length)
184188
}
@@ -199,9 +203,22 @@ pub async fn clnrod_testping(
199203
}
200204
let pubkey = PublicKey::from_str(pubkey_str).context("invalid pubkey")?;
201205

206+
let rpc_path =
207+
Path::new(&plugin.configuration().lightning_dir).join(plugin.configuration().rpc_file);
208+
let mut rpc = ClnRpc::new(rpc_path).await?;
209+
210+
rpc.call_typed(&ConnectRequest {
211+
host: None,
212+
port: None,
213+
id: pubkey.to_string(),
214+
})
215+
.await?;
216+
202217
let pings = ln_ping(plugin, pubkey, count, length).await?;
203218
let sum_pings = pings.iter().map(|y| *y as u64).sum::<u64>();
219+
let median = pings.iter().nth(pings.len() / 2).unwrap_or(&0);
204220
Ok(json!({"min":pings.iter().min(),
205221
"avg":sum_pings/(pings.len() as u64),
222+
"median":median,
206223
"max":pings.iter().max()}))
207224
}

0 commit comments

Comments
 (0)