diff --git a/Cargo.lock b/Cargo.lock index fcbc05b648..c82af6af6d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -886,6 +886,7 @@ version = "0.1.0" dependencies = [ "bp-messages", "bp-rialto", + "bp-runtime", "frame-support", "hex", "hex-literal", @@ -11690,6 +11691,7 @@ dependencies = [ "bp-millau", "bp-parachains", "bp-polkadot-core", + "bp-relayers", "bp-rialto", "bp-rococo", "bp-runtime", @@ -11700,6 +11702,7 @@ dependencies = [ "frame-support", "frame-system", "futures", + "hex", "log", "messages-relay", "num-traits", diff --git a/deployments/bridges/rialto-millau/dashboard/grafana/rialto-millau-maintenance-dashboard.json b/deployments/bridges/rialto-millau/dashboard/grafana/rialto-millau-maintenance-dashboard.json index ecb06074d7..4f134914f7 100644 --- a/deployments/bridges/rialto-millau/dashboard/grafana/rialto-millau-maintenance-dashboard.json +++ b/deployments/bridges/rialto-millau/dashboard/grafana/rialto-millau-maintenance-dashboard.json @@ -8,14 +8,22 @@ "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, "type": "dashboard" } ] }, "editable": true, + "fiscalYearStartMonth": 0, "gnetId": null, "graphTooltip": 0, "links": [], + "liveNow": false, "panels": [ { "alert": { @@ -66,29 +74,6 @@ "type": "last" }, "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "C", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" } ], "executionErrorState": "alerting", @@ -104,19 +89,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 0, - "y": 16 + "y": 0 }, "hiddenSeries": false, "id": 8, @@ -132,8 +111,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -161,7 +143,8 @@ "fill": true, "line": true, "op": "lt", - "value": 1000 + "value": 1000, + "visible": true } ], "timeFrom": null, @@ -253,29 +236,6 @@ "type": "last" }, "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "C", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" } ], "executionErrorState": "alerting", @@ -291,19 +251,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 12, - "y": 16 + "y": 0 }, "hiddenSeries": false, "id": 9, @@ -319,8 +273,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -348,7 +305,8 @@ "fill": true, "line": true, "op": "lt", - "value": 1000 + "value": 1000, + "visible": true } ], "timeFrom": null, @@ -432,19 +390,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 0, - "y": 24 + "y": 8 }, "hiddenSeries": false, "id": 11, @@ -460,8 +412,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -483,7 +438,8 @@ "fill": true, "line": true, "op": "gt", - "value": 0 + "value": 0, + "visible": true } ], "timeFrom": null, @@ -567,19 +523,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 12, - "y": 24 + "y": 8 }, "hiddenSeries": false, "id": 12, @@ -595,8 +545,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -618,7 +571,8 @@ "fill": true, "line": true, "op": "gt", - "value": 0 + "value": 0, + "visible": true } ], "timeFrom": null, @@ -660,108 +614,10 @@ "align": false, "alignLevel": null } - }, - { - "aliasColors": {}, - "bars": false, - "dashLength": 10, - "dashes": false, - "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, - "fill": 1, - "fillGradient": 0, - "gridPos": { - "h": 8, - "w": 12, - "x": 0, - "y": 32 - }, - "hiddenSeries": false, - "id": 14, - "legend": { - "avg": false, - "current": false, - "max": false, - "min": false, - "show": true, - "total": false, - "values": false - }, - "lines": true, - "linewidth": 1, - "nullPointMode": "null", - "percentage": false, - "pluginVersion": "7.1.3", - "pointradius": 2, - "points": false, - "renderer": "flot", - "seriesOverrides": [], - "spaceLength": 10, - "stack": false, - "steppedLine": false, - "targets": [ - { - "expr": "Millau_to_Rialto_MessageLane_00000000_unprofitable_delivery_transactions", - "interval": "", - "legendFormat": "Millau -> Rialto, lane 00000000", - "refId": "A" - }, - { - "expr": "Rialto_to_Millau_MessageLane_00000000_unprofitable_delivery_transactions", - "interval": "", - "legendFormat": "Rialto -> Millau, lane 00000000", - "refId": "B" - } - ], - "thresholds": [], - "timeFrom": null, - "timeRegions": [], - "timeShift": null, - "title": "Count of unprofitable message delivery transactions", - "tooltip": { - "shared": true, - "sort": 0, - "value_type": "individual" - }, - "type": "graph", - "xaxis": { - "buckets": null, - "mode": "time", - "name": null, - "show": true, - "values": [] - }, - "yaxes": [ - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - }, - { - "format": "short", - "label": null, - "logBase": 1, - "max": null, - "min": null, - "show": true - } - ], - "yaxis": { - "align": false, - "alignLevel": null - } } ], "refresh": "10s", - "schemaVersion": 26, + "schemaVersion": 32, "style": "dark", "tags": [], "templating": { diff --git a/deployments/bridges/rialto-parachain-millau/dashboard/grafana/rialto-parachain-millau-maintenance-dashboard.json b/deployments/bridges/rialto-parachain-millau/dashboard/grafana/rialto-parachain-millau-maintenance-dashboard.json index 0da5b8cb4d..b54bf1b48c 100644 --- a/deployments/bridges/rialto-parachain-millau/dashboard/grafana/rialto-parachain-millau-maintenance-dashboard.json +++ b/deployments/bridges/rialto-parachain-millau/dashboard/grafana/rialto-parachain-millau-maintenance-dashboard.json @@ -8,14 +8,22 @@ "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], + "type": "dashboard" + }, "type": "dashboard" } ] }, "editable": true, + "fiscalYearStartMonth": 0, "gnetId": null, "graphTooltip": 0, "links": [], + "liveNow": false, "panels": [ { "alert": { @@ -43,52 +51,6 @@ "type": "last" }, "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "B", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "C", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" } ], "executionErrorState": "alerting", @@ -104,19 +66,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 0, - "y": 16 + "y": 0 }, "hiddenSeries": false, "id": 10, @@ -132,8 +88,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -143,16 +102,29 @@ "steppedLine": false, "targets": [ { - "expr": "at_RialtoParachain_relay_MillauHeaders_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "exemplar": true, + "expr": "at_RialtoParachain_relay_MillauMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "instant": false, "interval": "", - "legendFormat": "With-Millau headers relay account balance", + "legendFormat": "With-Millau relay account balance", "refId": "A" }, { - "expr": "at_RialtoParachain_relay_MillauMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "exemplar": true, + "expr": "at_RialtoParachain_relay_MillauMessages_reward_for_lane_00000000_with_Millau{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "hide": false, + "instant": false, "interval": "", - "legendFormat": "With-Millau messages relay account balance", + "legendFormat": "With-Millau relay account reward", "refId": "B" + }, + { + "exemplar": true, + "expr": "at_RialtoParachain_relay_MillauMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"} + at_RialtoParachain_relay_MillauMessages_reward_for_lane_00000000_with_Millau{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "hide": false, + "interval": "", + "legendFormat": "With-Millau relay account total balance (balance + reward)", + "refId": "C" } ], "thresholds": [ @@ -161,7 +133,8 @@ "fill": true, "line": true, "op": "lt", - "value": 1000 + "value": 1000, + "visible": true } ], "timeFrom": null, @@ -230,52 +203,6 @@ "type": "last" }, "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "B", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" - }, - { - "evaluator": { - "params": [ - 1000 - ], - "type": "lt" - }, - "operator": { - "type": "or" - }, - "query": { - "params": [ - "C", - "5m", - "now" - ] - }, - "reducer": { - "params": [], - "type": "last" - }, - "type": "query" } ], "executionErrorState": "alerting", @@ -291,19 +218,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 12, - "y": 16 + "y": 0 }, "hiddenSeries": false, "id": 12, @@ -319,8 +240,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -330,21 +254,26 @@ "steppedLine": false, "targets": [ { - "expr": "at_Millau_relay_RialtoHeaders_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "exemplar": true, + "expr": "at_Millau_relay_RialtoParachainMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", "interval": "", - "legendFormat": "With-Rialto headers relay account balance", + "legendFormat": "With-Rialto relay account balance", "refId": "A" }, { - "expr": "at_Millau_relay_RialtoParachainMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "exemplar": true, + "expr": "at_Millau_relay_RialtoParachainMessages_reward_for_lane_00000000_with_RialtoParachain{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "hide": false, "interval": "", - "legendFormat": "With-RialtoParachain messages relay account balance", + "legendFormat": "With-Rialto relay account reward", "refId": "B" }, { - "expr": "at_Millau_relay_RialtoParachains_balance{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "exemplar": true, + "expr": "at_Millau_relay_RialtoParachainMessages_balance{instance=\"relay-millau-rialto-parachain-1:9616\"} + \nat_Millau_relay_RialtoParachainMessages_reward_for_lane_00000000_with_RialtoParachain{instance=\"relay-millau-rialto-parachain-1:9616\"}", + "hide": false, "interval": "", - "legendFormat": "With-Rialto parachains relay account balance", + "legendFormat": "With-Rialto relay account total balance (balance + reward)", "refId": "C" } ], @@ -354,7 +283,8 @@ "fill": true, "line": true, "op": "lt", - "value": 1000 + "value": 1000, + "visible": true } ], "timeFrom": null, @@ -438,19 +368,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 0, - "y": 24 + "y": 8 }, "hiddenSeries": false, "id": 14, @@ -466,8 +390,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -490,7 +417,8 @@ "fill": true, "line": true, "op": "gt", - "value": 0 + "value": 0, + "visible": true } ], "timeFrom": null, @@ -574,19 +502,13 @@ "dashLength": 10, "dashes": false, "datasource": "Prometheus", - "fieldConfig": { - "defaults": { - "custom": {} - }, - "overrides": [] - }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 8, "w": 12, "x": 12, - "y": 24 + "y": 8 }, "hiddenSeries": false, "id": 16, @@ -602,8 +524,11 @@ "lines": true, "linewidth": 1, "nullPointMode": "null", + "options": { + "alertThreshold": true + }, "percentage": false, - "pluginVersion": "7.1.3", + "pluginVersion": "8.2.6", "pointradius": 2, "points": false, "renderer": "flot", @@ -625,7 +550,8 @@ "fill": true, "line": true, "op": "gt", - "value": 0 + "value": 0, + "visible": true } ], "timeFrom": null, @@ -670,7 +596,7 @@ } ], "refresh": "5s", - "schemaVersion": 26, + "schemaVersion": 32, "style": "dark", "tags": [], "templating": { diff --git a/modules/relayers/Cargo.toml b/modules/relayers/Cargo.toml index 9c07123836..732adbf4fa 100644 --- a/modules/relayers/Cargo.toml +++ b/modules/relayers/Cargo.toml @@ -15,6 +15,7 @@ scale-info = { version = "2.1.1", default-features = false, features = ["derive" bp-messages = { path = "../../primitives/messages", default-features = false } bp-relayers = { path = "../../primitives/relayers", default-features = false } +bp-runtime = { path = "../../primitives/runtime", default-features = false } # Substrate Dependencies @@ -37,6 +38,7 @@ default = ["std"] std = [ "bp-messages/std", "bp-relayers/std", + "bp-runtime/std", "codec/std", "frame-support/std", "frame-system/std", diff --git a/modules/relayers/src/lib.rs b/modules/relayers/src/lib.rs index 27ffcaf1ea..c0fc181c83 100644 --- a/modules/relayers/src/lib.rs +++ b/modules/relayers/src/lib.rs @@ -21,7 +21,8 @@ #![warn(missing_docs)] use bp_messages::LaneId; -use bp_relayers::PaymentProcedure; +use bp_relayers::{PaymentProcedure, RelayerRewardsKeyProvider}; +use bp_runtime::StorageDoubleMapKeyProvider; use frame_support::sp_runtime::Saturating; use sp_arithmetic::traits::{AtLeast32BitUnsigned, Zero}; use sp_std::marker::PhantomData; @@ -46,6 +47,10 @@ pub mod pallet { use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; + /// `RelayerRewardsKeyProvider` for given configuration. + type RelayerRewardsKeyProviderOf = + RelayerRewardsKeyProvider<::AccountId, ::Reward>; + #[pallet::config] pub trait Config: frame_system::Config { /// The overarching event type. @@ -145,11 +150,11 @@ pub mod pallet { #[pallet::getter(fn relayer_reward)] pub type RelayerRewards = StorageDoubleMap< _, - Blake2_128Concat, - T::AccountId, - Identity, - LaneId, - T::Reward, + as StorageDoubleMapKeyProvider>::Hasher1, + as StorageDoubleMapKeyProvider>::Key1, + as StorageDoubleMapKeyProvider>::Hasher2, + as StorageDoubleMapKeyProvider>::Key2, + as StorageDoubleMapKeyProvider>::Value, OptionQuery, >; } diff --git a/primitives/relayers/Cargo.toml b/primitives/relayers/Cargo.toml index 4f893f9f83..acede81399 100644 --- a/primitives/relayers/Cargo.toml +++ b/primitives/relayers/Cargo.toml @@ -11,6 +11,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" # Bridge Dependencies bp-messages = { path = "../messages", default-features = false } +bp-runtime = { path = "../runtime", default-features = false } # Substrate Dependencies @@ -27,6 +28,7 @@ hex-literal = "0.3" default = ["std"] std = [ "bp-messages/std", + "bp-runtime/std", "frame-support/std", "sp-runtime/std", "sp-std/std", diff --git a/primitives/relayers/src/lib.rs b/primitives/relayers/src/lib.rs index d00b5f626e..207908296c 100644 --- a/primitives/relayers/src/lib.rs +++ b/primitives/relayers/src/lib.rs @@ -20,8 +20,10 @@ #![cfg_attr(not(feature = "std"), no_std)] use bp_messages::LaneId; +use bp_runtime::StorageDoubleMapKeyProvider; +use frame_support::{Blake2_128Concat, Identity}; use sp_runtime::{ - codec::{Decode, Encode}, + codec::{Codec, Decode, Encode, EncodeLike}, traits::AccountIdConversion, }; use sp_std::{fmt::Debug, marker::PhantomData}; @@ -65,6 +67,24 @@ where } } +/// Can be use to access the runtime storage key within the `RelayerRewards` map of the relayers +/// pallet. +pub struct RelayerRewardsKeyProvider(PhantomData<(AccountId, Reward)>); + +impl StorageDoubleMapKeyProvider for RelayerRewardsKeyProvider +where + AccountId: Codec + EncodeLike, + Reward: Codec + EncodeLike, +{ + const MAP_NAME: &'static str = "RelayerRewards"; + + type Hasher1 = Blake2_128Concat; + type Key1 = AccountId; + type Hasher2 = Identity; + type Key2 = LaneId; + type Value = Reward; +} + #[cfg(test)] mod tests { use super::*; diff --git a/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs b/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs index fd8a032066..d1249fca18 100644 --- a/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs +++ b/relays/bin-substrate/src/cli/relay_headers_and_messages/mod.rs @@ -61,8 +61,8 @@ use crate::{ use bp_messages::LaneId; use bp_runtime::BalanceOf; use relay_substrate_client::{ - AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithTransactions, Client, - Parachain, + AccountIdOf, AccountKeyPairOf, Chain, ChainWithBalances, ChainWithMessages, + ChainWithTransactions, Client, Parachain, }; use relay_utils::metrics::MetricsParams; use sp_core::Pair; @@ -259,9 +259,9 @@ where type Base: Full2WayBridgeBase; /// The left relay chain. - type Left: ChainWithTransactions + ChainWithBalances + CliChain; + type Left: ChainWithTransactions + ChainWithBalances + ChainWithMessages + CliChain; /// The right relay chain. - type Right: ChainWithTransactions + ChainWithBalances + CliChain; + type Right: ChainWithTransactions + ChainWithBalances + ChainWithMessages + CliChain; /// Left to Right bridge. type L2R: MessagesCliBridge; @@ -317,28 +317,36 @@ where self.mut_base().start_on_demand_headers_relayers().await?; // add balance-related metrics + let lanes = self + .base() + .common() + .shared + .lane + .iter() + .cloned() + .map(Into::into) + .collect::>(); { let common = self.mut_base().mut_common(); - substrate_relay_helper::messages_metrics::add_relay_balances_metrics( + substrate_relay_helper::messages_metrics::add_relay_balances_metrics::<_, Self::Right>( common.left.client.clone(), &mut common.metrics_params, &common.left.accounts, + &lanes, ) .await?; - substrate_relay_helper::messages_metrics::add_relay_balances_metrics( + substrate_relay_helper::messages_metrics::add_relay_balances_metrics::<_, Self::Left>( common.right.client.clone(), &mut common.metrics_params, &common.right.accounts, + &lanes, ) .await?; } - let lanes = self.base().common().shared.lane.clone(); // Need 2x capacity since we consider both directions for each lane let mut message_relays = Vec::with_capacity(lanes.len() * 2); for lane in lanes { - let lane = lane.into(); - let left_to_right_messages = substrate_relay_helper::messages_lane::run::< ::MessagesLane, >(self.left_to_right().messages_relay_params( diff --git a/relays/client-bridge-hub-rococo/src/lib.rs b/relays/client-bridge-hub-rococo/src/lib.rs index 7e9047e32c..77cb53ef42 100644 --- a/relays/client-bridge-hub-rococo/src/lib.rs +++ b/relays/client-bridge-hub-rococo/src/lib.rs @@ -109,6 +109,7 @@ impl ChainWithTransactions for BridgeHubRococo { impl ChainWithMessages for BridgeHubRococo { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_bridge_hub_rococo::WITH_BRIDGE_HUB_ROCOCO_MESSAGES_PALLET_NAME; + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = None; const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = bp_bridge_hub_rococo::TO_BRIDGE_HUB_ROCOCO_MESSAGE_DETAILS_METHOD; diff --git a/relays/client-bridge-hub-wococo/src/lib.rs b/relays/client-bridge-hub-wococo/src/lib.rs index 516f5d9fb8..a35108fdc3 100644 --- a/relays/client-bridge-hub-wococo/src/lib.rs +++ b/relays/client-bridge-hub-wococo/src/lib.rs @@ -109,6 +109,7 @@ impl ChainWithTransactions for BridgeHubWococo { impl ChainWithMessages for BridgeHubWococo { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_bridge_hub_wococo::WITH_BRIDGE_HUB_WOCOCO_MESSAGES_PALLET_NAME; + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = None; const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = bp_bridge_hub_wococo::TO_BRIDGE_HUB_WOCOCO_MESSAGE_DETAILS_METHOD; diff --git a/relays/client-millau/src/lib.rs b/relays/client-millau/src/lib.rs index fb901a4b2d..34bbea92d5 100644 --- a/relays/client-millau/src/lib.rs +++ b/relays/client-millau/src/lib.rs @@ -45,6 +45,8 @@ impl ChainWithGrandpa for Millau { impl ChainWithMessages for Millau { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_millau::WITH_MILLAU_MESSAGES_PALLET_NAME; + // TODO (https://github.com/paritytech/parity-bridges-common/issues/1692): change the name + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = Some("BridgeRelayers"); const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = bp_millau::TO_MILLAU_MESSAGE_DETAILS_METHOD; const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = diff --git a/relays/client-rialto-parachain/src/lib.rs b/relays/client-rialto-parachain/src/lib.rs index 16abd6e880..2bafe793f2 100644 --- a/relays/client-rialto-parachain/src/lib.rs +++ b/relays/client-rialto-parachain/src/lib.rs @@ -64,6 +64,8 @@ impl ChainWithBalances for RialtoParachain { impl ChainWithMessages for RialtoParachain { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_rialto_parachain::WITH_RIALTO_PARACHAIN_MESSAGES_PALLET_NAME; + // TODO (https://github.com/paritytech/parity-bridges-common/issues/1692): change the name + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = Some("BridgeRelayers"); const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = bp_rialto_parachain::TO_RIALTO_PARACHAIN_MESSAGE_DETAILS_METHOD; const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = diff --git a/relays/client-rialto/src/lib.rs b/relays/client-rialto/src/lib.rs index 4c3a9d1e18..8ad31de4d5 100644 --- a/relays/client-rialto/src/lib.rs +++ b/relays/client-rialto/src/lib.rs @@ -63,6 +63,8 @@ impl ChainWithGrandpa for Rialto { impl ChainWithMessages for Rialto { const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str = bp_rialto::WITH_RIALTO_MESSAGES_PALLET_NAME; + // TODO (https://github.com/paritytech/parity-bridges-common/issues/1692): change the name + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str> = Some("BridgeRelayers"); const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = bp_rialto::TO_RIALTO_MESSAGE_DETAILS_METHOD; const FROM_CHAIN_MESSAGE_DETAILS_METHOD: &'static str = diff --git a/relays/client-substrate/src/chain.rs b/relays/client-substrate/src/chain.rs index c199540cbf..da0d7c5f1f 100644 --- a/relays/client-substrate/src/chain.rs +++ b/relays/client-substrate/src/chain.rs @@ -101,6 +101,16 @@ pub trait ChainWithMessages: Chain { /// the same name. const WITH_CHAIN_MESSAGES_PALLET_NAME: &'static str; + // TODO (https://github.com/paritytech/parity-bridges-common/issues/1692): check all the names + // after the issue is fixed - all names must be changed + + /// Name of the bridge relayers pallet (used in `construct_runtime` macro call) that is deployed + /// at some other chain to bridge with this `ChainWithMessages`. + /// + /// We assume that all chains that are bridging with this `ChainWithMessages` are using + /// the same name. + const WITH_CHAIN_RELAYERS_PALLET_NAME: Option<&'static str>; + /// Name of the `ToOutboundLaneApi::message_details` runtime API method. /// The method is provided by the runtime that is bridged with this `ChainWithMessages`. const TO_CHAIN_MESSAGE_DETAILS_METHOD: &'static str; diff --git a/relays/lib-substrate-relay/Cargo.toml b/relays/lib-substrate-relay/Cargo.toml index 1dd7cb7b37..217642d833 100644 --- a/relays/lib-substrate-relay/Cargo.toml +++ b/relays/lib-substrate-relay/Cargo.toml @@ -12,6 +12,7 @@ async-std = "1.9.0" async-trait = "0.1" codec = { package = "parity-scale-codec", version = "3.1.5" } futures = "0.3.12" +hex = "0.4" num-traits = "0.2" log = "0.4.17" @@ -20,6 +21,7 @@ log = "0.4.17" bp-header-chain = { path = "../../primitives/header-chain" } bp-parachains = { path = "../../primitives/parachains" } bp-polkadot-core = { path = "../../primitives/polkadot-core" } +bp-relayers = { path = "../../primitives/relayers" } bridge-runtime-common = { path = "../../bin/runtime-common" } finality-grandpa = { version = "0.16.0" } diff --git a/relays/lib-substrate-relay/src/messages_metrics.rs b/relays/lib-substrate-relay/src/messages_metrics.rs index 37a6d67baa..943f3b7c36 100644 --- a/relays/lib-substrate-relay/src/messages_metrics.rs +++ b/relays/lib-substrate-relay/src/messages_metrics.rs @@ -18,12 +18,15 @@ use crate::TaggedAccount; +use bp_messages::LaneId; +use bp_runtime::StorageDoubleMapKeyProvider; use codec::Decode; use frame_system::AccountInfo; use pallet_balances::AccountData; use relay_substrate_client::{ metrics::{FloatStorageValue, FloatStorageValueMetric}, - AccountIdOf, BalanceOf, Chain, ChainWithBalances, Client, Error as SubstrateError, IndexOf, + AccountIdOf, BalanceOf, Chain, ChainWithBalances, ChainWithMessages, Client, + Error as SubstrateError, IndexOf, }; use relay_utils::metrics::{MetricsParams, StandaloneMetric}; use sp_core::storage::StorageData; @@ -31,10 +34,11 @@ use sp_runtime::{FixedPointNumber, FixedU128}; use std::{convert::TryFrom, fmt::Debug, marker::PhantomData}; /// Add relay accounts balance metrics. -pub async fn add_relay_balances_metrics( +pub async fn add_relay_balances_metrics( client: Client, metrics: &mut MetricsParams, relay_accounts: &Vec>>, + lanes: &[LaneId], ) -> anyhow::Result<()> where BalanceOf: Into + std::fmt::Debug, @@ -68,13 +72,30 @@ where for account in relay_accounts { let relay_account_balance_metric = FloatStorageValueMetric::new( - FreeAccountBalance:: { token_decimals, _phantom: Default::default() }, + AccountBalanceFromAccountInfo:: { token_decimals, _phantom: Default::default() }, client.clone(), C::account_info_storage_key(account.id()), format!("at_{}_relay_{}_balance", C::NAME, account.tag()), format!("Balance of the {} relay account at the {}", account.tag(), C::NAME), )?; relay_account_balance_metric.register_and_spawn(&metrics.registry)?; + + if let Some(relayers_pallet_name) = BC::WITH_CHAIN_RELAYERS_PALLET_NAME { + for lane in lanes { + let relay_account_reward_metric = FloatStorageValueMetric::new( + AccountBalance:: { token_decimals, _phantom: Default::default() }, + client.clone(), + bp_relayers::RelayerRewardsKeyProvider::, BalanceOf>::final_key( + relayers_pallet_name, + account.id(), + lane, + ), + format!("at_{}_relay_{}_reward_for_lane_{}_with_{}", C::NAME, account.tag(), hex::encode(lane.as_ref()), BC::NAME), + format!("Reward of the {} relay account for serving lane {:?} with {} at the {}", account.tag(), lane, BC::NAME, C::NAME), + )?; + relay_account_reward_metric.register_and_spawn(&metrics.registry)?; + } + } } Ok(()) @@ -82,12 +103,12 @@ where /// Adapter for `FloatStorageValueMetric` to decode account free balance. #[derive(Clone, Debug)] -struct FreeAccountBalance { +struct AccountBalanceFromAccountInfo { token_decimals: u32, _phantom: PhantomData, } -impl FloatStorageValue for FreeAccountBalance +impl FloatStorageValue for AccountBalanceFromAccountInfo where C: Chain, BalanceOf: Into, @@ -110,6 +131,34 @@ where } } +/// Adapter for `FloatStorageValueMetric` to decode account free balance. +#[derive(Clone, Debug)] +struct AccountBalance { + token_decimals: u32, + _phantom: PhantomData, +} + +impl FloatStorageValue for AccountBalance +where + C: Chain, + BalanceOf: Into, +{ + type Value = FixedU128; + + fn decode( + &self, + maybe_raw_value: Option, + ) -> Result, SubstrateError> { + maybe_raw_value + .map(|raw_value| { + BalanceOf::::decode(&mut &raw_value.0[..]) + .map_err(SubstrateError::ResponseParseFailed) + .map(|balance| convert_to_token_balance(balance.into(), self.token_decimals)) + }) + .transpose() + } +} + /// Convert from raw `u128` balance (nominated in smallest chain token units) to the float regular /// tokens value. fn convert_to_token_balance(balance: u128, token_decimals: u32) -> FixedU128 {