From 0b0f42f583f3a616a88afe45fcd06d31e7d9a06f Mon Sep 17 00:00:00 2001 From: Nikhil Gupta <17176722+gupnik@users.noreply.github.com> Date: Tue, 11 Jul 2023 18:48:55 +0530 Subject: [PATCH] Fixes trait bounds --- bridges/primitives/header-chain/Cargo.toml | 1 + bridges/primitives/header-chain/src/justification.rs | 4 +++- bridges/primitives/header-chain/src/lib.rs | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bridges/primitives/header-chain/Cargo.toml b/bridges/primitives/header-chain/Cargo.toml index 962d262d571..d471908cf9c 100644 --- a/bridges/primitives/header-chain/Cargo.toml +++ b/bridges/primitives/header-chain/Cargo.toml @@ -9,6 +9,7 @@ license = "GPL-3.0-or-later WITH Classpath-exception-2.0" [dependencies] codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false } finality-grandpa = { version = "0.16.2", default-features = false } +num-traits = { version = "0.2", default-features = false } scale-info = { version = "2.9.0", default-features = false, features = ["derive"] } serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] } diff --git a/bridges/primitives/header-chain/src/justification.rs b/bridges/primitives/header-chain/src/justification.rs index 9cf4427bccf..2855de7c2ed 100644 --- a/bridges/primitives/header-chain/src/justification.rs +++ b/bridges/primitives/header-chain/src/justification.rs @@ -25,9 +25,10 @@ use bp_runtime::{BlockNumberOf, Chain, HashOf}; use codec::{Decode, Encode, MaxEncodedLen}; use finality_grandpa::voter_set::VoterSet; use frame_support::RuntimeDebug; +use num_traits::AsPrimitive; use scale_info::TypeInfo; use sp_consensus_grandpa::{AuthorityId, AuthoritySignature, SetId}; -use sp_runtime::{traits::Header as HeaderT, SaturatedConversion}; +use sp_runtime::{traits::{Block as BlockT, Header as HeaderT}, SaturatedConversion}; use sp_std::{ collections::{btree_map::BTreeMap, btree_set::BTreeSet}, prelude::*, @@ -76,6 +77,7 @@ impl GrandpaJustification { pub fn max_reasonable_size(required_precommits: u32) -> u32 where C: Chain + ChainWithGrandpa, + <<::Block as BlockT>::Header as HeaderT>::Number: AsPrimitive { // we don't need precise results here - just estimations, so some details // are removed from computations (e.g. bytes required to encode vector length) diff --git a/bridges/primitives/header-chain/src/lib.rs b/bridges/primitives/header-chain/src/lib.rs index cf08a936234..f75525d7099 100644 --- a/bridges/primitives/header-chain/src/lib.rs +++ b/bridges/primitives/header-chain/src/lib.rs @@ -29,8 +29,9 @@ use frame_support::PalletError; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_consensus_grandpa::{AuthorityList, ConsensusLog, SetId, GRANDPA_ENGINE_ID}; -use sp_runtime::{traits::Header as HeaderT, Digest, RuntimeDebug}; +use sp_runtime::{traits::{Block as BlockT, Header as HeaderT}, Digest, RuntimeDebug}; use sp_std::boxed::Box; +use num_traits::AsPrimitive; pub mod justification; pub mod storage_keys; @@ -69,7 +70,7 @@ impl StoredHeaderDataBuilder for H { } /// Substrate header chain, abstracted from the way it is stored. -pub trait HeaderChain { +pub trait HeaderChain where <<::Block as BlockT>::Header as HeaderT>::Number: AsPrimitive { /// Returns state (storage) root of given finalized header. fn finalized_header_state_root(header_hash: HashOf) -> Option>; /// Get storage proof checker using finalized header. @@ -181,7 +182,7 @@ pub type BridgeGrandpaCallOf = BridgeGrandpaCall>; /// /// Keep in mind that parachains are relying on relay chain GRANDPA, so they should not implement /// this trait. -pub trait ChainWithGrandpa: Chain { +pub trait ChainWithGrandpa: Chain where <<::Block as BlockT>::Header as HeaderT>::Number: AsPrimitive { /// Name of the bridge GRANDPA pallet (used in `construct_runtime` macro call) that is deployed /// at some other chain to bridge with this `ChainWithGrandpa`. ///