Skip to content

Commit

Permalink
add polygon client to runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizdave97 committed Dec 26, 2023
1 parent 3de3a08 commit d128eeb
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 224 deletions.
284 changes: 76 additions & 208 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions parachain/modules/consensus/polygon-pos/verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ edition = "2021"
authors = ["Polytope Labs"]

[dependencies]
log = { version = "0.4.17", default-features = false }
anyhow = { version = "1.0.75", default-features = false }
sp-core = {version = "27.0.0", default-features = false }
alloy-rlp = { version = "0.3.2", default-features = false }
alloy-primitives = { version = "0.5.3", default-features = false, features = ["rlp"] }
alloy-primitives = { version = "0.3.1", default-features = false, features = ["rlp"] }
alloy-rlp-derive = "0.3.2"
codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false }
ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false }
ismp = { path = "../../../ismp/core", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
sp-io = { version = "27.0.0", default-features = false }
ethers = { version = "2.0.8", default-features = false }
sp-io = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0" }
ethers = { version = "2.0.11", optional = true }

[features]
default = ["std"]
std = [
"log/std",
"anyhow/std",
"sp-core/std",
"codec/std",
Expand All @@ -30,5 +28,6 @@ std = [
"alloy-rlp/std",
"ethabi/std",
"scale-info/std",
"sp-io/std"
"sp-io/std",
"ethers"
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloy_primitives::{Address, FixedBytes, B256};
use alloy_rlp_derive::{RlpDecodable, RlpEncodable};
use anyhow::anyhow;
use ethabi::ethereum_types::{Bloom, H160, H256, H64, U256};
#[cfg(feature = "std")]
use ethers::types::Block;
use ismp::util::Keccak256;

Expand Down Expand Up @@ -55,6 +56,7 @@ pub struct CodecHeader {
pub excess_data_gas: Option<U256>,
}

#[cfg(feature = "std")]
impl From<Block<H256>> for CodecHeader {
fn from(block: Block<H256>) -> Self {
CodecHeader {
Expand Down
11 changes: 4 additions & 7 deletions parachain/modules/ismp/polygon-pos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ authors = ["Polytope Labs"]
log = { version = "0.4.17", default-features = false }
anyhow = { version = "1.0.75", default-features = false }
sp-core = {version = "27.0.0", default-features = false }
alloy-rlp = { version = "0.3.2", default-features = false }
alloy-primitives = { version = "0.5.3", default-features = false, features = ["rlp"] }
alloy-rlp-derive = "0.3.2"
codec = { package = "parity-scale-codec", version = "3.1.3", default-features = false }
ethabi = { version = "18.0.0", features = ["rlp", "parity-codec"], default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }

ismp = { path = "../core", default-features = false }
Expand All @@ -22,7 +18,6 @@ ismp-sync-committee = {path = "../sync-committee", default-features = false}

frame-support = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0" }
frame-system = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0" }
sp-io = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.4.0" }

[features]
Expand All @@ -32,10 +27,12 @@ std = [
"anyhow/std",
"sp-core/std",
"codec/std",
"scale-info/std",
"polygon-pos-verifier/std",
"frame-system/std",
"frame-support/std",
"sp-io/std",
"sp-runtime/std",
"ismp-sync-committee/std"
"ismp-sync-committee/std",
"pallet-ismp/std",
"ismp/std"
]
25 changes: 22 additions & 3 deletions parachain/modules/ismp/polygon-pos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ extern crate alloc;
pub mod pallet;
use core::marker::PhantomData;

use alloc::collections::{BTreeMap, BTreeSet};
use alloc::{
boxed::Box,
collections::{BTreeMap, BTreeSet},
string::ToString,
vec,
vec::Vec,
};
use codec::{Decode, Encode};
use ismp::{
consensus::{ConsensusClient, StateCommitment, StateMachineClient},
consensus::{ConsensusClient, ConsensusStateId, StateCommitment, StateMachineClient},
error::Error,
host::{IsmpHost, StateMachine},
messaging::StateCommitmentHeight,
Expand All @@ -23,6 +29,7 @@ use polygon_pos_verifier::{
use sp_core::{ConstU32, H160, H256, U256};
use sp_runtime::BoundedVec;

pub const POLYGON_CONSENSUS_ID: ConsensusStateId = *b"POLY";
#[derive(Encode, Decode, Debug, Clone, PartialEq)]
pub struct Chain {
/// Block hash of this chain head
Expand All @@ -47,7 +54,7 @@ impl Chain {
}
}

#[derive(Debug, Encode, Decode, Clone)]
#[derive(Debug, Encode, Decode, Clone, Default)]
pub struct ConsensusState {
pub frozen_height: Option<u64>,
pub finalized_hash: H256,
Expand All @@ -63,6 +70,18 @@ pub struct PolygonClientUpdate {

pub struct PolygonClient<T: Config, H: IsmpHost>(PhantomData<(T, H)>);

impl<T: Config, H: IsmpHost> Default for PolygonClient<T, H> {
fn default() -> Self {
Self(PhantomData)
}
}

impl<T: Config, H: IsmpHost> Clone for PolygonClient<T, H> {
fn clone(&self) -> Self {
Self(PhantomData)
}
}

impl<T: Config, H: IsmpHost + Send + Sync + Default + 'static> ConsensusClient
for PolygonClient<T, H>
{
Expand Down
2 changes: 2 additions & 0 deletions parachain/runtimes/messier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pallet-ismp = { path = "../../modules/ismp/pallet", default-features = false }
ismp-demo = { path = "../../modules/ismp/demo", default-features = false }
ismp-runtime-api = { path = "../../modules/ismp/runtime-api", default-features = false }
ismp-sync-committee = { path = "../../modules/ismp/sync-committee", default-features = false }
ismp-polygon-pos = { path = "../../modules/ismp/polygon-pos", default-features = false }

[features]
default = [
Expand Down Expand Up @@ -134,6 +135,7 @@ std = [
"pallet-message-queue/std",
"ismp-sync-committee/std",
"parachains-common/std",
"ismp-polygon-pos/std"
]

runtime-benchmarks = [
Expand Down
9 changes: 9 additions & 0 deletions parachain/runtimes/messier/src/ismp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ impl ConsensusClientProvider for ConsensusProvider {
ismp_sync_committee::SyncCommitteeConsensusClient::<Host<Runtime>>::default();
Ok(Box::new(sync_committee))
},

ismp_polygon_pos::POLYGON_CONSENSUS_ID => {
let polygon_client =
ismp_polygon_pos::PolygonClient::<Runtime, Host<Runtime>>::default();
Ok(Box::new(polygon_client))
},

id => Err(Error::ImplementationSpecific(format!("Unknown consensus client: {id:?}")))?,
}
}
Expand Down Expand Up @@ -83,6 +90,8 @@ impl ismp_demo::Config for Runtime {
type IsmpDispatcher = pallet_ismp::dispatcher::Dispatcher<Runtime>;
}

impl ismp_polygon_pos::pallet::Config for Runtime {}

impl IsmpModule for ProxyModule {
fn on_accept(&self, request: Post) -> Result<(), Error> {
if request.dest != StateMachineProvider::get() {
Expand Down
1 change: 1 addition & 0 deletions parachain/runtimes/messier/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ construct_runtime!(
Ismp: pallet_ismp = 40,
IsmpSyncCommittee: ismp_sync_committee::pallet::{Pallet, Call} = 41,
IsmpDemo: ismp_demo = 42,
IsmpPolygonPos: ismp_polygon_pos::pallet = 43,
}
);

Expand Down

0 comments on commit d128eeb

Please sign in to comment.