Skip to content

Commit

Permalink
Upgrade to Polkadot-v1.1.0 (#27)
Browse files Browse the repository at this point in the history
* merge beefy prover

* change git imports

* chore

* subxt codegen

* cargo lock update

* some initial work

* relay between multiple chains

* consensus updates working

* test fixes

* integration tests passing

* cargo fmt

---------

Co-authored-by: David Salami <[email protected]>
  • Loading branch information
seunlanlege and Wizdave97 authored Sep 26, 2023
1 parent 03bb3da commit e048524
Show file tree
Hide file tree
Showing 17 changed files with 2,910 additions and 1,442 deletions.
1,452 changes: 1,080 additions & 372 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ members = [
"substrate/common",
"substrate/parachain",
# "substrate/grandpa",
"substrate/beefy",
"substrate/beefy/host",
"substrate/beefy/primitives",
"substrate/beefy/prover",
"relayer",
"integration-tests",
"ethereum/sync-committee",
Expand Down
2 changes: 0 additions & 2 deletions consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ where
result = consensus_a.next() => {
match result {
None => {
println!("A Returned None");
break
}
Some(Ok(consensus_message)) => {
Expand All @@ -57,7 +56,6 @@ where
result = consensus_b.next() => {
match result {
None => {
println!("B Returned None");
break
},
Some(Ok(consensus_message)) => {
Expand Down
2 changes: 1 addition & 1 deletion ethereum/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tokio-stream = "0.1.14"
pallet-ismp = { git = "https://github.com/polytope-labs/substrate-ismp", branch = "main" }
ismp = { git = "https://github.com/polytope-labs/ismp-rs", branch = "main" }
ismp-primitives = { git = "https://github.com/polytope-labs/substrate-ismp", branch = "main" }
beefy-verifier-primitives = { git = "ssh://[email protected]/polytope-labs/beefy-rs", branch = "seun/polkadot-v0.9.42" }
beefy-verifier-primitives = { path = "../../substrate/beefy/primitives" }
consensus-client = { package = "ismp-sync-committee", git = "ssh://[email protected]/polytope-labs/hyperbridge", branch = "main" }

tesseract-primitives = { path = "../../primitives" }
Expand Down
2,586 changes: 1,604 additions & 982 deletions ethereum/evm/abis/MockModule.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions ethereum/evm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl From<BeefyNextAuthoritySet<H256>> for AuthoritySetCommitment {
AuthoritySetCommitment {
id: value.id.into(),
len: value.len.into(),
root: value.root.into(),
root: value.keyset_commitment.into(),
}
}
}
Expand All @@ -196,7 +196,7 @@ impl From<ConsensusState> for BeefyConsensusState {
fn from(value: ConsensusState) -> Self {
BeefyConsensusState {
latest_height: value.latest_beefy_height.into(),
beefy_activation_block: Default::default(),
beefy_activation_block: value.beefy_activation_block.into(),
current_authority_set: value.current_authorities.into(),
next_authority_set: value.next_authorities.into(),
}
Expand All @@ -206,17 +206,18 @@ impl From<ConsensusState> for BeefyConsensusState {
impl From<BeefyConsensusState> for ConsensusState {
fn from(value: BeefyConsensusState) -> Self {
ConsensusState {
beefy_activation_block: value.beefy_activation_block.as_u32(),
latest_beefy_height: value.latest_height.as_u32(),
mmr_root_hash: Default::default(),
current_authorities: BeefyNextAuthoritySet {
id: value.current_authority_set.id.as_u64(),
len: value.current_authority_set.len.as_u32(),
root: value.current_authority_set.root.into(),
keyset_commitment: value.current_authority_set.root.into(),
},
next_authorities: BeefyNextAuthoritySet {
id: value.next_authority_set.id.as_u64(),
len: value.next_authority_set.len.as_u32(),
root: value.next_authority_set.root.into(),
keyset_commitment: value.next_authority_set.root.into(),
},
}
}
Expand Down
100 changes: 77 additions & 23 deletions ethereum/evm/src/abi/mock_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,13 @@ pub mod mock_module {
fn __abi() -> ::ethers::core::abi::Abi {
::ethers::core::abi::ethabi::Contract {
constructor: ::core::option::Option::Some(::ethers::core::abi::ethabi::Constructor {
inputs: ::std::vec![
::ethers::core::abi::ethabi::Param {
name: ::std::borrow::ToOwned::to_owned("host"),
kind: ::ethers::core::abi::ethabi::ParamType::Address,
internal_type: ::core::option::Option::Some(
::std::borrow::ToOwned::to_owned("address"),
),
},
::ethers::core::abi::ethabi::Param {
name: ::std::borrow::ToOwned::to_owned("paraId"),
kind: ::ethers::core::abi::ethabi::ParamType::Uint(256usize),
internal_type: ::core::option::Option::Some(
::std::borrow::ToOwned::to_owned("uint256"),
),
},
],
inputs: ::std::vec![::ethers::core::abi::ethabi::Param {
name: ::std::borrow::ToOwned::to_owned("host"),
kind: ::ethers::core::abi::ethabi::ParamType::Address,
internal_type: ::core::option::Option::Some(::std::borrow::ToOwned::to_owned(
"address"
),),
},],
}),
functions: ::core::convert::From::from([
(
Expand Down Expand Up @@ -104,7 +95,13 @@ pub mod mock_module {
::std::borrow::ToOwned::to_owned("dispatchToParachain"),
::std::vec![::ethers::core::abi::ethabi::Function {
name: ::std::borrow::ToOwned::to_owned("dispatchToParachain",),
inputs: ::std::vec![],
inputs: ::std::vec![::ethers::core::abi::ethabi::Param {
name: ::std::borrow::ToOwned::to_owned("_paraId"),
kind: ::ethers::core::abi::ethabi::ParamType::Uint(256usize,),
internal_type: ::core::option::Option::Some(
::std::borrow::ToOwned::to_owned("uint256"),
),
},],
outputs: ::std::vec![],
constant: ::core::option::Option::None,
state_mutability: ::ethers::core::abi::ethabi::StateMutability::NonPayable,
Expand Down Expand Up @@ -256,6 +253,22 @@ pub mod mock_module {
state_mutability: ::ethers::core::abi::ethabi::StateMutability::NonPayable,
},],
),
(
::std::borrow::ToOwned::to_owned("ping"),
::std::vec![::ethers::core::abi::ethabi::Function {
name: ::std::borrow::ToOwned::to_owned("ping"),
inputs: ::std::vec![::ethers::core::abi::ethabi::Param {
name: ::std::borrow::ToOwned::to_owned("dest"),
kind: ::ethers::core::abi::ethabi::ParamType::Bytes,
internal_type: ::core::option::Option::Some(
::std::borrow::ToOwned::to_owned("bytes"),
),
},],
outputs: ::std::vec![],
constant: ::core::option::Option::None,
state_mutability: ::ethers::core::abi::ethabi::StateMutability::NonPayable,
},],
),
]),
events: ::core::convert::From::from([
(
Expand Down Expand Up @@ -383,10 +396,13 @@ pub mod mock_module {
.method_hash([209, 171, 70, 207], (request,))
.expect("method not found (this should never happen)")
}
///Calls the contract's `dispatchToParachain` (0x667f320a) function
pub fn dispatch_to_parachain(&self) -> ::ethers::contract::builders::ContractCall<M, ()> {
///Calls the contract's `dispatchToParachain` (0x72354e9b) function
pub fn dispatch_to_parachain(
&self,
para_id: ::ethers::core::types::U256,
) -> ::ethers::contract::builders::ContractCall<M, ()> {
self.0
.method_hash([102, 127, 50, 10], ())
.method_hash([114, 53, 78, 155], para_id)
.expect("method not found (this should never happen)")
}
///Calls the contract's `onAccept` (0x4e87ba19) function
Expand Down Expand Up @@ -434,6 +450,15 @@ pub mod mock_module {
.method_hash([199, 21, 245, 43], (request,))
.expect("method not found (this should never happen)")
}
///Calls the contract's `ping` (0x1f40dc8b) function
pub fn ping(
&self,
dest: ::ethers::core::types::Bytes,
) -> ::ethers::contract::builders::ContractCall<M, ()> {
self.0
.method_hash([31, 64, 220, 139], dest)
.expect("method not found (this should never happen)")
}
///Gets the contract's `GetResponseReceived` event
pub fn get_response_received_filter(
&self,
Expand Down Expand Up @@ -779,7 +804,7 @@ pub mod mock_module {
pub request: GetRequest,
}
///Container type for all input parameters for the `dispatchToParachain` function with
/// signature `dispatchToParachain()` and selector `0x667f320a`
/// signature `dispatchToParachain(uint256)` and selector `0x72354e9b`
#[derive(
Clone,
::ethers::contract::EthCall,
Expand All @@ -790,8 +815,10 @@ pub mod mock_module {
Eq,
Hash,
)]
#[ethcall(name = "dispatchToParachain", abi = "dispatchToParachain()")]
pub struct DispatchToParachainCall;
#[ethcall(name = "dispatchToParachain", abi = "dispatchToParachain(uint256)")]
pub struct DispatchToParachainCall {
pub para_id: ::ethers::core::types::U256,
}
///Container type for all input parameters for the `onAccept` function with signature
/// `onAccept((bytes,bytes,uint64,bytes,bytes,uint64,bytes,uint64))` and selector `0x4e87ba19`
#[derive(
Expand Down Expand Up @@ -891,6 +918,22 @@ pub mod mock_module {
pub struct OnPostTimeoutCall {
pub request: PostRequest,
}
///Container type for all input parameters for the `ping` function with signature `ping(bytes)`
/// and selector `0x1f40dc8b`
#[derive(
Clone,
::ethers::contract::EthCall,
::ethers::contract::EthDisplay,
Default,
Debug,
PartialEq,
Eq,
Hash,
)]
#[ethcall(name = "ping", abi = "ping(bytes)")]
pub struct PingCall {
pub dest: ::ethers::core::types::Bytes,
}
///Container type for all of the contract's call
#[derive(Clone, ::ethers::contract::EthAbiType, Debug, PartialEq, Eq, Hash)]
pub enum MockModuleCalls {
Expand All @@ -902,6 +945,7 @@ pub mod mock_module {
OnGetTimeout(OnGetTimeoutCall),
OnPostResponse(OnPostResponseCall),
OnPostTimeout(OnPostTimeoutCall),
Ping(PingCall),
}
impl ::ethers::core::abi::AbiDecode for MockModuleCalls {
fn decode(
Expand Down Expand Up @@ -941,6 +985,9 @@ pub mod mock_module {
{
return Ok(Self::OnPostTimeout(decoded))
}
if let Ok(decoded) = <PingCall as ::ethers::core::abi::AbiDecode>::decode(data) {
return Ok(Self::Ping(decoded))
}
Err(::ethers::core::abi::Error::InvalidData.into())
}
}
Expand All @@ -959,6 +1006,7 @@ pub mod mock_module {
Self::OnGetTimeout(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::OnPostResponse(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::OnPostTimeout(element) => ::ethers::core::abi::AbiEncode::encode(element),
Self::Ping(element) => ::ethers::core::abi::AbiEncode::encode(element),
}
}
}
Expand All @@ -973,6 +1021,7 @@ pub mod mock_module {
Self::OnGetTimeout(element) => ::core::fmt::Display::fmt(element, f),
Self::OnPostResponse(element) => ::core::fmt::Display::fmt(element, f),
Self::OnPostTimeout(element) => ::core::fmt::Display::fmt(element, f),
Self::Ping(element) => ::core::fmt::Display::fmt(element, f),
}
}
}
Expand Down Expand Up @@ -1016,6 +1065,11 @@ pub mod mock_module {
Self::OnPostTimeout(value)
}
}
impl ::core::convert::From<PingCall> for MockModuleCalls {
fn from(value: PingCall) -> Self {
Self::Ping(value)
}
}
///Container type for all return fields from the `dispatch` function with signature
/// `dispatch((bytes,bytes,uint64,bytes,bytes,uint64,bytes,uint64))` and selector `0x31267dee`
#[derive(
Expand Down
9 changes: 5 additions & 4 deletions ethereum/evm/src/arbitrum/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub struct ArbConfig {
/// RollupCore contract address on L1
pub rollup_core: H160,
/// General evm config
pub evm_config: Option<EvmConfig>,
#[serde[flatten]]
pub evm_config: EvmConfig,
}

#[derive(Clone)]
Expand All @@ -39,9 +40,9 @@ pub struct ArbHost {
}

impl ArbHost {
pub async fn new(config: ArbConfig) -> Result<Self, anyhow::Error> {
let provider = Provider::<Ws>::connect(config.arb_execution).await?;
let beacon_client = Provider::<Ws>::connect(config.beacon_execution_client).await?;
pub async fn new(config: &ArbConfig) -> Result<Self, anyhow::Error> {
let provider = Provider::<Ws>::connect(&config.arb_execution).await?;
let beacon_client = Provider::<Ws>::connect(&config.beacon_execution_client).await?;
Ok(Self {
arb_execution_client: Arc::new(provider),
beacon_execution_client: Arc::new(beacon_client),
Expand Down
4 changes: 2 additions & 2 deletions ethereum/evm/src/arbitrum/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ async fn test_payload_proof_verification() {
beacon_execution_client: "wss://rpc.ankr.com/eth/ws/6875dedefed4afb05996bc795f89f9cd6f245f5117302f2c9214376ec1d96513".to_string(),
arb_execution: "wss://rpc.ankr.com/arbitrum/ws/6875dedefed4afb05996bc795f89f9cd6f245f5117302f2c9214376ec1d96513".to_string(),
rollup_core: H160::from_slice(&ROLLUP_CORE),
evm_config: None
evm_config: Default::default()
};

let arb_client = ArbHost::new(config).await.expect("Host creation failed");
let arb_client = ArbHost::new(&config).await.expect("Host creation failed");

let event = arb_client
.latest_event(18026004, 18026004)
Expand Down
29 changes: 26 additions & 3 deletions ethereum/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ use ethers::{
providers::{Provider, Ws},
signers::Signer,
};
use ismp::{consensus::ConsensusStateId, events::Event, host::StateMachine};
use ismp::{
consensus::ConsensusStateId,
events::Event,
host::{Ethereum, StateMachine},
};
use parking_lot::Mutex;
use serde::{Deserialize, Serialize};
use sp_core::{bytes::from_hex, keccak_256, Pair, H160};
Expand Down Expand Up @@ -45,6 +49,21 @@ pub struct EvmConfig {
pub gas_limit: u64,
}

impl Default for EvmConfig {
fn default() -> Self {
Self {
execution: Default::default(),
state_machine: StateMachine::Ethereum(Ethereum::ExecutionLayer),
consensus_state_id: Default::default(),
ismp_host_address: Default::default(),
handler_address: Default::default(),
signer: Default::default(),
latest_state_machine_height: Default::default(),
gas_limit: Default::default(),
}
}
}

/// Core EVM client.
pub struct EvmClient<I> {
/// Ismp host implementation
Expand Down Expand Up @@ -134,9 +153,13 @@ where
}

/// Dispatch a test request to the parachain.
pub async fn dispatch_to_parachain(&self, address: H160) -> Result<(), anyhow::Error> {
pub async fn dispatch_to_parachain(
&self,
address: H160,
para_id: u32,
) -> Result<(), anyhow::Error> {
let contract = MockModule::new(address, self.signer.clone());
let call = contract.dispatch_to_parachain();
let call = contract.dispatch_to_parachain(para_id.into());

// let gas = call.estimate_gas().await?; // todo: fix estimate gas
// dbg!(gas);
Expand Down
8 changes: 4 additions & 4 deletions ethereum/evm/src/optimism/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct OpConfig {
/// Withdrawals Message Passer contract address on L2
pub message_parser: H160,
/// General Evm client config
pub evm_config: Option<EvmConfig>,
pub evm_config: EvmConfig,
}

#[derive(Clone)]
Expand Down Expand Up @@ -56,9 +56,9 @@ pub fn derive_array_item_key(index_in_array: u64, offset: u64) -> H256 {
}

impl OpHost {
pub async fn new(config: OpConfig) -> Result<Self, anyhow::Error> {
let provider = Provider::<Ws>::connect(config.op_execution).await?;
let beacon_client = Provider::<Ws>::connect(config.beacon_execution_client).await?;
pub async fn new(config: &OpConfig) -> Result<Self, anyhow::Error> {
let provider = Provider::<Ws>::connect(&config.op_execution).await?;
let beacon_client = Provider::<Ws>::connect(&config.beacon_execution_client).await?;
Ok(Self {
op_execution_client: Arc::new(provider),
beacon_execution_client: Arc::new(beacon_client),
Expand Down
4 changes: 2 additions & 2 deletions ethereum/evm/src/optimism/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ async fn test_payload_proof_verification() {
op_execution: "wss://rpc.ankr.com/optimism/ws/6875dedefed4afb05996bc795f89f9cd6f245f5117302f2c9214376ec1d96513".to_string(),
l2_oracle: H160::from(L2_ORACLE),
message_parser: H160::from(MESSAGE_PARSER),
evm_config: None
evm_config: Default::default()
};

let op_client = OpHost::new(config).await.expect("Host creation failed");
let op_client = OpHost::new(&config).await.expect("Host creation failed");

let event = op_client
.latest_event(18022470, 18022470)
Expand Down
Loading

0 comments on commit e048524

Please sign in to comment.