Skip to content

Commit d805c6f

Browse files
committed
Add last_tip_block_time to the peer info returned via node RPC. The "New peer accepted" log line now also includes the user agent and its version.
1 parent 250a35c commit d805c6f

File tree

7 files changed

+36
-14
lines changed

7 files changed

+36
-14
lines changed

chainstate/src/detail/mod.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,13 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
261261
Ok(())
262262
}
263263

264-
fn broadcast_new_tip_event(&mut self, new_block_index: &Option<BlockIndex>) {
265-
if let Some(new_block_index) = new_block_index {
266-
let new_height = new_block_index.block_height();
267-
let new_id = *new_block_index.block_id();
268-
let event = ChainstateEvent::NewTip(new_id, new_height);
269-
270-
self.rpc_events.broadcast(&event);
271-
self.subsystem_events.broadcast(event);
272-
}
264+
fn broadcast_new_tip_event(&mut self, new_block_index: &BlockIndex) {
265+
let new_height = new_block_index.block_height();
266+
let new_id = *new_block_index.block_id();
267+
let event = ChainstateEvent::NewTip(new_id, new_height);
268+
269+
self.rpc_events.broadcast(&event);
270+
self.subsystem_events.broadcast(event);
273271
}
274272

275273
/// Create a read-write transaction, call `main_action` on it and commit.
@@ -609,7 +607,11 @@ impl<S: BlockchainStorage, V: TransactionVerificationStrategy> Chainstate<S, V>
609607
None => result,
610608
};
611609

612-
self.broadcast_new_tip_event(&result);
610+
if let Some(new_block_index) = &result {
611+
self.broadcast_new_tip_event(new_block_index);
612+
} else {
613+
log::debug!("Stale block received: {block_id:x}");
614+
}
613615

614616
if let Some(ref bi) = result {
615617
let compact_target = match bi.block_header().consensus_data() {

node-daemon/docs/RPC.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,9 @@ Returns:
10891089
"ping_min": EITHER OF
10901090
1) number
10911091
2) null,
1092+
"last_tip_block_time": EITHER OF
1093+
1) number
1094+
2) null,
10921095
}, .. ]
10931096
```
10941097

p2p/src/disconnection_reason.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use crate::{
2828
///
2929
/// Note: we derive `thiserror::Error` here just for the convenience of implementing `Display`.
3030
/// But conceptually this enum is not an error and it's not supposed to be used with `Result`.
31+
// TODO: use `derive_more::Display` instead of `thiserror::Error`.
3132
#[derive(Error, Debug, Clone, PartialEq, Eq)]
3233
pub enum DisconnectionReason {
3334
#[error("Your address is banned")]
@@ -57,7 +58,7 @@ pub enum DisconnectionReason {
5758
remote_time: Time,
5859
accepted_peer_time: std::ops::RangeInclusive<Time>,
5960
},
60-
#[error("Wrong network; out network is '{our_network}'")]
61+
#[error("Wrong network; our network is '{our_network}'")]
6162
DifferentNetwork { our_network: MagicBytes },
6263
#[error("No common services")]
6364
NoCommonServices,

p2p/src/interface/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
use p2p_types::socket_address::SocketAddress;
1716
use serde::{Deserialize, Serialize};
1817

18+
use p2p_types::socket_address::SocketAddress;
19+
1920
use crate::{net::types::PeerRole, types::peer_id::PeerId};
2021

2122
/// Helper type used to return information about a connected peer from RPC.
@@ -43,4 +44,7 @@ pub struct ConnectedPeer {
4344

4445
/// Min time for a ping roundtrip, in milliseconds
4546
pub ping_min: Option<u64>,
47+
48+
/// Last time the peer has sent us a block that became our tip, in seconds since UNIX epoch
49+
pub last_tip_block_time: Option<u64>,
4650
}

p2p/src/peer_manager/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,13 @@ where
976976
self.peer_connectivity_handle.accept(peer_id)?;
977977

978978
log::info!(
979-
"New peer accepted, peer_id: {peer_id}, address: {peer_address:?}, role: {peer_role:?}, protocol_version: {:?}",
980-
info.protocol_version
979+
"New peer accepted, peer_id: {}, address: {:?}, role: {:?}, protocol_version: {:?}, user agent: {} v{}",
980+
peer_id,
981+
peer_address,
982+
peer_role,
983+
info.protocol_version,
984+
info.user_agent,
985+
info.software_version
981986
);
982987

983988
if info.common_services.has_service(Service::PeerAddresses) {
@@ -1816,6 +1821,9 @@ where
18161821
ping_min: context.ping_min.map(|time| {
18171822
duration_to_int(&time).expect("valid timestamp expected (ping_min)")
18181823
}),
1824+
last_tip_block_time: context
1825+
.last_tip_block_time
1826+
.map(|time| time.as_secs_since_epoch()),
18191827
})
18201828
.collect()
18211829
}

p2p/src/peer_manager/peer_context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub struct PeerContext {
7373
/// Can be set for outbound connections only.
7474
pub discovered_own_address: Option<SocketAddress>,
7575

76+
/// Last time the peer has sent us a block that became our tip.
7677
pub last_tip_block_time: Option<Time>,
7778

7879
pub last_tx_time: Option<Time>,

wallet/wallet-rpc-daemon/docs/RPC.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,6 +2777,9 @@ Returns:
27772777
"ping_min": EITHER OF
27782778
1) number
27792779
2) null,
2780+
"last_tip_block_time": EITHER OF
2781+
1) number
2782+
2) null,
27802783
}, .. ]
27812784
```
27822785

0 commit comments

Comments
 (0)