From 0fde4f955ef9d2c228dba36706e58ca9f00c0c7c Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 27 Apr 2023 15:04:57 +0300 Subject: [PATCH] Add more logs to relayer and message pallets (#2082) * add more logs * unused import * fmt --- bridges/modules/messages/src/lib.rs | 3 ++- bridges/modules/messages/src/mock.rs | 16 +++------------- bridges/modules/relayers/src/lib.rs | 2 ++ bridges/primitives/messages/src/lib.rs | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/bridges/modules/messages/src/lib.rs b/bridges/modules/messages/src/lib.rs index 8f4911b8d0..045015b775 100644 --- a/bridges/modules/messages/src/lib.rs +++ b/bridges/modules/messages/src/lib.rs @@ -329,9 +329,10 @@ pub mod pallet { if let Some(updated_latest_confirmed_nonce) = updated_latest_confirmed_nonce { log::trace!( target: LOG_TARGET, - "Received lane {:?} state update: latest_confirmed_nonce={}", + "Received lane {:?} state update: latest_confirmed_nonce={}. Unrewarded relayers: {:?}", lane_id, updated_latest_confirmed_nonce, + UnrewardedRelayersState::from(&lane.storage().data()), ); } } diff --git a/bridges/modules/messages/src/mock.rs b/bridges/modules/messages/src/mock.rs index 3d78ab562d..2e45d5b601 100644 --- a/bridges/modules/messages/src/mock.rs +++ b/bridges/modules/messages/src/mock.rs @@ -26,8 +26,8 @@ use bp_messages::{ DeliveryPayments, DispatchMessage, DispatchMessageData, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, }, - total_unrewarded_messages, DeliveredMessages, InboundLaneData, LaneId, Message, MessageKey, - MessageNonce, MessagePayload, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, + DeliveredMessages, InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, + OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, }; use bp_runtime::{messages::MessageDispatchResult, Size}; use codec::{Decode, Encode}; @@ -485,17 +485,7 @@ pub fn unrewarded_relayer( /// Returns unrewarded relayers state at given lane. pub fn inbound_unrewarded_relayers_state(lane: bp_messages::LaneId) -> UnrewardedRelayersState { let inbound_lane_data = crate::InboundLanes::::get(lane).0; - let last_delivered_nonce = inbound_lane_data.last_delivered_nonce(); - let relayers = inbound_lane_data.relayers; - UnrewardedRelayersState { - unrewarded_relayer_entries: relayers.len() as _, - messages_in_oldest_entry: relayers - .front() - .map(|entry| 1 + entry.messages.end - entry.messages.begin) - .unwrap_or(0), - total_messages: total_unrewarded_messages(&relayers).unwrap_or(MessageNonce::MAX), - last_delivered_nonce, - } + UnrewardedRelayersState::from(&inbound_lane_data) } /// Return test externalities to use in tests. diff --git a/bridges/modules/relayers/src/lib.rs b/bridges/modules/relayers/src/lib.rs index fd0e82aab8..008c487836 100644 --- a/bridges/modules/relayers/src/lib.rs +++ b/bridges/modules/relayers/src/lib.rs @@ -159,6 +159,7 @@ pub mod pallet { } registration.stake = required_stake; + log::trace!(target: LOG_TARGET, "Successfully registered relayer: {:?}", relayer); Self::deposit_event(Event::::RegistrationUpdated { relayer: relayer.clone(), registration, @@ -196,6 +197,7 @@ pub mod pallet { Self::do_unreserve(&relayer, registration.stake)?; } + log::trace!(target: LOG_TARGET, "Successfully deregistered relayer: {:?}", relayer); Self::deposit_event(Event::::Deregistered { relayer: relayer.clone() }); *maybe_registration = None; diff --git a/bridges/primitives/messages/src/lib.rs b/bridges/primitives/messages/src/lib.rs index 2828d5af00..e485aa2f80 100644 --- a/bridges/primitives/messages/src/lib.rs +++ b/bridges/primitives/messages/src/lib.rs @@ -316,6 +316,21 @@ pub struct UnrewardedRelayersState { pub last_delivered_nonce: MessageNonce, } +impl From<&InboundLaneData> for UnrewardedRelayersState { + fn from(lane: &InboundLaneData) -> UnrewardedRelayersState { + UnrewardedRelayersState { + unrewarded_relayer_entries: lane.relayers.len() as _, + messages_in_oldest_entry: lane + .relayers + .front() + .and_then(|entry| (entry.messages.begin..=entry.messages.end).checked_len()) + .unwrap_or(0), + total_messages: total_unrewarded_messages(&lane.relayers).unwrap_or(MessageNonce::MAX), + last_delivered_nonce: lane.last_delivered_nonce(), + } + } +} + /// Outbound lane data. #[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct OutboundLaneData {