From 057d28e156a9f093a066e914ed8b5b8c2a07244f Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 27 Apr 2023 12:26:23 +0300 Subject: [PATCH 1/3] add more logs --- modules/messages/src/lib.rs | 3 ++- modules/messages/src/mock.rs | 12 +----------- modules/relayers/src/lib.rs | 2 ++ primitives/messages/src/lib.rs | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/messages/src/lib.rs b/modules/messages/src/lib.rs index 8f4911b8d03..045015b7751 100644 --- a/modules/messages/src/lib.rs +++ b/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/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index 3d78ab562d2..8bdc2cd8392 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -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/modules/relayers/src/lib.rs b/modules/relayers/src/lib.rs index 14e44d30f89..1cf8133a752 100644 --- a/modules/relayers/src/lib.rs +++ b/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/primitives/messages/src/lib.rs b/primitives/messages/src/lib.rs index 2828d5af006..e485aa2f801 100644 --- a/primitives/messages/src/lib.rs +++ b/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 { From 62461e836f609976d6ff793a0fb813e327c379e7 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 27 Apr 2023 13:18:52 +0300 Subject: [PATCH 2/3] unused import --- modules/messages/src/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index 8bdc2cd8392..d7488fa9a3f 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -26,7 +26,7 @@ use bp_messages::{ DeliveryPayments, DispatchMessage, DispatchMessageData, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, }, - total_unrewarded_messages, DeliveredMessages, InboundLaneData, LaneId, Message, MessageKey, + DeliveredMessages, InboundLaneData, LaneId, Message, MessageKey, MessageNonce, MessagePayload, OutboundLaneData, UnrewardedRelayer, UnrewardedRelayersState, }; use bp_runtime::{messages::MessageDispatchResult, Size}; From 0a53c090c567e569aa2b72499c10988c8d3b8e45 Mon Sep 17 00:00:00 2001 From: Svyatoslav Nikolsky Date: Thu, 27 Apr 2023 14:04:48 +0300 Subject: [PATCH 3/3] fmt --- modules/messages/src/mock.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/messages/src/mock.rs b/modules/messages/src/mock.rs index d7488fa9a3f..2e45d5b601f 100644 --- a/modules/messages/src/mock.rs +++ b/modules/messages/src/mock.rs @@ -26,8 +26,8 @@ use bp_messages::{ DeliveryPayments, DispatchMessage, DispatchMessageData, MessageDispatch, ProvedLaneMessages, ProvedMessages, SourceHeaderChain, }, - 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};