mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 04:01:02 +00:00
Only store header state root (pallet-bridge-parachains) (#1701)
* store block number ++ state root in parachains pallet * fixed parachains finality APIs * (test commit) * removed test code * deduplicated code a bit * removed commented code * spelling * Update modules/parachains/src/lib.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update modules/parachains/src/lib.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * Update modules/parachains/src/mock.rs Co-authored-by: Adrian Catangiu <adrian@parity.io> * added comment Co-authored-by: Adrian Catangiu <adrian@parity.io>
This commit is contained in:
committed by
Bastian Köcher
parent
2c5e2f09eb
commit
d63a75697c
@@ -44,13 +44,10 @@ pub use crate::{
|
||||
transaction_tracker::TransactionTracker,
|
||||
};
|
||||
pub use bp_runtime::{
|
||||
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain as ChainBase, HashOf, HeaderOf,
|
||||
IndexOf, SignatureOf, TransactionEra, TransactionEraOf,
|
||||
AccountIdOf, AccountPublicOf, BalanceOf, BlockNumberOf, Chain as ChainBase, HashOf, HeaderIdOf,
|
||||
HeaderOf, IndexOf, SignatureOf, TransactionEra, TransactionEraOf,
|
||||
};
|
||||
|
||||
/// Header id used by the chain.
|
||||
pub type HeaderIdOf<C> = relay_utils::HeaderId<HashOf<C>, BlockNumberOf<C>>;
|
||||
|
||||
/// Substrate-over-websocket connection params.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ConnectionParams {
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
//! Metrics for headers synchronization relay loop.
|
||||
|
||||
use relay_utils::metrics::{metric_name, register, IntGauge, Metric, PrometheusError, Registry};
|
||||
use relay_utils::{
|
||||
metrics::{metric_name, register, IntGauge, Metric, PrometheusError, Registry},
|
||||
UniqueSaturatedInto,
|
||||
};
|
||||
|
||||
/// Headers sync metrics.
|
||||
#[derive(Clone)]
|
||||
@@ -61,13 +64,19 @@ impl SyncLoopMetrics {
|
||||
}
|
||||
|
||||
/// Update best block number at source.
|
||||
pub fn update_best_block_at_source<Number: Into<u64>>(&self, source_best_number: Number) {
|
||||
self.best_source_block_number.set(source_best_number.into());
|
||||
pub fn update_best_block_at_source<Number: UniqueSaturatedInto<u64>>(
|
||||
&self,
|
||||
source_best_number: Number,
|
||||
) {
|
||||
self.best_source_block_number.set(source_best_number.unique_saturated_into());
|
||||
}
|
||||
|
||||
/// Update best block number at target.
|
||||
pub fn update_best_block_at_target<Number: Into<u64>>(&self, target_best_number: Number) {
|
||||
self.best_target_block_number.set(target_best_number.into());
|
||||
pub fn update_best_block_at_target<Number: UniqueSaturatedInto<u64>>(
|
||||
&self,
|
||||
target_best_number: Number,
|
||||
) {
|
||||
self.best_target_block_number.set(target_best_number.unique_saturated_into());
|
||||
}
|
||||
|
||||
/// Update using-same-fork flag.
|
||||
|
||||
@@ -33,12 +33,10 @@ use parachains_relay::{
|
||||
};
|
||||
use relay_substrate_client::{
|
||||
AccountIdOf, AccountKeyPairOf, BlockNumberOf, Chain, Client, Error as SubstrateError, HashOf,
|
||||
HeaderIdOf, HeaderOf, RelayChain, SignParam, TransactionEra, TransactionTracker,
|
||||
UnsignedTransaction,
|
||||
HeaderIdOf, RelayChain, SignParam, TransactionEra, TransactionTracker, UnsignedTransaction,
|
||||
};
|
||||
use relay_utils::{relay_loop::Client as RelayClient, HeaderId};
|
||||
use sp_core::{Bytes, Pair};
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
|
||||
/// Substrate client as parachain heads source.
|
||||
pub struct ParachainsTarget<P: SubstrateParachainsPipeline> {
|
||||
@@ -132,7 +130,7 @@ where
|
||||
.map(|para_info| para_info.best_head_hash);
|
||||
|
||||
if let (Some(metrics), Some(best_para_head_hash)) = (metrics, &best_para_head_hash) {
|
||||
let imported_para_head = self
|
||||
let imported_para_head_number = self
|
||||
.client
|
||||
.storage_double_map_value::<ImportedParaHeadsKeyProvider>(
|
||||
P::SourceRelayChain::PARACHAINS_FINALITY_PALLET_NAME,
|
||||
@@ -142,10 +140,11 @@ where
|
||||
)
|
||||
.await
|
||||
.and_then(|maybe_encoded_head| match maybe_encoded_head {
|
||||
Some(encoded_head) =>
|
||||
HeaderOf::<P::SourceParachain>::decode(&mut &encoded_head.0[..])
|
||||
.map(Some)
|
||||
.map_err(Self::Error::ResponseParseFailed),
|
||||
Some(encoded_head) => encoded_head
|
||||
.decode_parachain_head_data::<P::SourceParachain>()
|
||||
.map(|head| head.number)
|
||||
.map(Some)
|
||||
.map_err(Self::Error::ResponseParseFailed),
|
||||
None => Ok(None),
|
||||
})
|
||||
.map_err(|e| {
|
||||
@@ -159,9 +158,8 @@ where
|
||||
e
|
||||
})
|
||||
.unwrap_or(None);
|
||||
if let Some(imported_para_head) = imported_para_head {
|
||||
metrics
|
||||
.update_best_parachain_block_at_target(para_id, *imported_para_head.number());
|
||||
if let Some(imported_para_head_number) = imported_para_head_number {
|
||||
metrics.update_best_parachain_block_at_target(para_id, imported_para_head_number);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,9 @@ impl MessageLaneLoopMetrics {
|
||||
/// Update source client state metrics.
|
||||
pub fn update_source_state<P: MessageLane>(&self, source_client_state: SourceClientState<P>) {
|
||||
self.source_to_target_finality_metrics
|
||||
.update_best_block_at_source(source_client_state.best_self.0.into());
|
||||
self.target_to_source_finality_metrics.update_best_block_at_target(
|
||||
source_client_state.best_finalized_peer_at_best_self.0.into(),
|
||||
);
|
||||
.update_best_block_at_source(source_client_state.best_self.0);
|
||||
self.target_to_source_finality_metrics
|
||||
.update_best_block_at_target(source_client_state.best_finalized_peer_at_best_self.0);
|
||||
self.target_to_source_finality_metrics.update_using_same_fork(
|
||||
source_client_state.best_finalized_peer_at_best_self.1 ==
|
||||
source_client_state.actual_best_finalized_peer_at_best_self.1,
|
||||
@@ -78,10 +77,9 @@ impl MessageLaneLoopMetrics {
|
||||
/// Update target client state metrics.
|
||||
pub fn update_target_state<P: MessageLane>(&self, target_client_state: TargetClientState<P>) {
|
||||
self.target_to_source_finality_metrics
|
||||
.update_best_block_at_source(target_client_state.best_self.0.into());
|
||||
self.source_to_target_finality_metrics.update_best_block_at_target(
|
||||
target_client_state.best_finalized_peer_at_best_self.0.into(),
|
||||
);
|
||||
.update_best_block_at_source(target_client_state.best_self.0);
|
||||
self.source_to_target_finality_metrics
|
||||
.update_best_block_at_target(target_client_state.best_finalized_peer_at_best_self.0);
|
||||
self.source_to_target_finality_metrics.update_using_same_fork(
|
||||
target_client_state.best_finalized_peer_at_best_self.1 ==
|
||||
target_client_state.actual_best_finalized_peer_at_best_self.1,
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use bp_polkadot_core::parachains::ParaId;
|
||||
use relay_utils::metrics::{
|
||||
metric_name, register, GaugeVec, Metric, Opts, PrometheusError, Registry, U64,
|
||||
use relay_utils::{
|
||||
metrics::{metric_name, register, GaugeVec, Metric, Opts, PrometheusError, Registry, U64},
|
||||
UniqueSaturatedInto,
|
||||
};
|
||||
|
||||
/// Parachains sync metrics.
|
||||
@@ -50,12 +51,12 @@ impl ParachainsLoopMetrics {
|
||||
}
|
||||
|
||||
/// Update best block number at source.
|
||||
pub fn update_best_parachain_block_at_source<Number: Into<u64>>(
|
||||
pub fn update_best_parachain_block_at_source<Number: UniqueSaturatedInto<u64>>(
|
||||
&self,
|
||||
parachain: ParaId,
|
||||
block_number: Number,
|
||||
) {
|
||||
let block_number = block_number.into();
|
||||
let block_number = block_number.unique_saturated_into();
|
||||
let label = parachain_label(¶chain);
|
||||
log::trace!(
|
||||
target: "bridge-metrics",
|
||||
@@ -67,12 +68,12 @@ impl ParachainsLoopMetrics {
|
||||
}
|
||||
|
||||
/// Update best block number at target.
|
||||
pub fn update_best_parachain_block_at_target<Number: Into<u64>>(
|
||||
pub fn update_best_parachain_block_at_target<Number: UniqueSaturatedInto<u64>>(
|
||||
&self,
|
||||
parachain: ParaId,
|
||||
block_number: Number,
|
||||
) {
|
||||
let block_number = block_number.into();
|
||||
let block_number = block_number.unique_saturated_into();
|
||||
let label = parachain_label(¶chain);
|
||||
log::trace!(
|
||||
target: "bridge-metrics",
|
||||
|
||||
@@ -29,4 +29,5 @@ bp-runtime = { path = "../../primitives/runtime" }
|
||||
|
||||
# Substrate dependencies
|
||||
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
pub use bp_runtime::HeaderId;
|
||||
pub use error::Error;
|
||||
pub use relay_loop::{relay_loop, relay_metrics};
|
||||
pub use sp_runtime::traits::UniqueSaturatedInto;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use backoff::{backoff::Backoff, ExponentialBackoff};
|
||||
@@ -51,7 +52,7 @@ pub mod relay_loop;
|
||||
pub trait BlockNumberBase:
|
||||
'static
|
||||
+ From<u32>
|
||||
+ Into<u64>
|
||||
+ UniqueSaturatedInto<u64>
|
||||
+ Ord
|
||||
+ Clone
|
||||
+ Copy
|
||||
@@ -73,7 +74,7 @@ pub trait BlockNumberBase:
|
||||
impl<T> BlockNumberBase for T where
|
||||
T: 'static
|
||||
+ From<u32>
|
||||
+ Into<u64>
|
||||
+ UniqueSaturatedInto<u64>
|
||||
+ Ord
|
||||
+ Clone
|
||||
+ Copy
|
||||
|
||||
Reference in New Issue
Block a user