Skip to content

Commit

Permalink
Get Ethereum Relay to Compile (paritytech#21)
Browse files Browse the repository at this point in the history
* Update dependencies

Upgrades Substrate based dependencies from v2.0.0 -> v2.0.0-alpha.1
and uses the `jsonrpsee`'s new feature flags. The actual code hasn't
been updated though, so this won't compile.

* Use `RawClient`s from `jsonrpsee`

* Update to use jsonrpsee's new API

* Hook up Ethereum Bridge Runtime, Relay, and Node Runtime

* Bump `parity-crypto` from v0.4 to v0.6

Fixes error when trying to compile tests. This was caused by
`parity-crypto` v0.4's use of `parity-secp256k1` over `secp256k1'.
Using the Parity fork meant multiple version of the same underlying
C library were being pulled in. `parity-crypto` v0.6 moved away from
this, only relying on `secp256k1` thus fixing the issue.
  • Loading branch information
HCastano authored and serban300 committed Apr 9, 2024
1 parent fc7e371 commit 2f255bd
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 48 deletions.
1 change: 1 addition & 0 deletions bridges/bin/node/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ futures = "0.3.1"
log = "0.4.8"
structopt = "0.3.8"
bridge-node-runtime = { version = "0.1.0", path = "../runtime" }
sp-bridge-eth-poa = { version = "0.1.0", path = "../../../primitives/ethereum-poa" }

[dependencies.sc-cli]
version = "0.8.0-alpha.2"
Expand Down
51 changes: 49 additions & 2 deletions bridges/bin/node/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

use sp_core::{Pair, Public, sr25519};
use bridge_node_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig,
SudoConfig, SystemConfig, WASM_BINARY, Signature
AccountId, AuraConfig, BalancesConfig, BridgeEthPoAConfig,
GenesisConfig, GrandpaConfig, SudoConfig, SystemConfig,
WASM_BINARY, Signature
};
use sp_consensus_aura::sr25519::{AuthorityId as AuraId};
use grandpa_primitives::{AuthorityId as GrandpaId};
Expand Down Expand Up @@ -112,6 +113,7 @@ fn testnet_genesis(initial_authorities: Vec<(AuraId, GrandpaId)>,
pallet_aura: Some(AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
}),
pallet_bridge_eth_poa: load_kovan_config(),
pallet_grandpa: Some(GrandpaConfig {
authorities: initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect(),
}),
Expand All @@ -127,3 +129,48 @@ pub fn load_spec(id: &str) -> Result<Option<ChainSpec>, String> {
None => None,
})
}

fn load_kovan_config() -> Option<BridgeEthPoAConfig> {
Some(BridgeEthPoAConfig {
initial_header: sp_bridge_eth_poa::Header {
parent_hash: Default::default(),
timestamp: 0,
number: 0,
author: Default::default(),
transactions_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".parse().unwrap(),
uncles_hash: "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".parse().unwrap(),
extra_data: vec![],
state_root: "2480155b48a1cea17d67dbfdfaafe821c1d19cdd478c5358e8ec56dec24502b2".parse().unwrap(),
receipts_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".parse().unwrap(),
log_bloom: Default::default(),
gas_used: Default::default(),
gas_limit: 6000000.into(),
difficulty: 131072.into(),
seal: vec![
vec![128].into(),
vec![184, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0].into(),
],
},
initial_difficulty: 0.into(),
initial_validators: vec![
[0x00, 0xD6, 0xCc, 0x1B, 0xA9, 0xcf, 0x89, 0xBD, 0x2e, 0x58,
0x00, 0x97, 0x41, 0xf4, 0xF7, 0x32, 0x5B, 0xAd, 0xc0, 0xED].into(),
[0x00, 0x42, 0x7f, 0xea, 0xe2, 0x41, 0x9c, 0x15, 0xb8, 0x9d,
0x1c, 0x21, 0xaf, 0x10, 0xd1, 0xb6, 0x65, 0x0a, 0x4d, 0x3d].into(),
[0x4E, 0xd9, 0xB0, 0x8e, 0x63, 0x54, 0xC7, 0x0f, 0xE6, 0xF8,
0xCB, 0x04, 0x11, 0xb0, 0xd3, 0x24, 0x6b, 0x42, 0x4d, 0x6c].into(),
[0x00, 0x20, 0xee, 0x4B, 0xe0, 0xe2, 0x02, 0x7d, 0x76, 0x60,
0x3c, 0xB7, 0x51, 0xeE, 0x06, 0x95, 0x19, 0xbA, 0x81, 0xA1].into(),
[0x00, 0x10, 0xf9, 0x4b, 0x29, 0x6a, 0x85, 0x2a, 0xaa, 0xc5,
0x2e, 0xa6, 0xc5, 0xac, 0x72, 0xe0, 0x3a, 0xfd, 0x03, 0x2d].into(),
[0x00, 0x77, 0x33, 0xa1, 0xFE, 0x69, 0xCF, 0x3f, 0x2C, 0xF9,
0x89, 0xF8, 0x1C, 0x7b, 0x4c, 0xAc, 0x16, 0x93, 0x38, 0x7A].into(),
[0x00, 0xE6, 0xd2, 0xb9, 0x31, 0xF5, 0x5a, 0x3f, 0x17, 0x01,
0xc7, 0x38, 0x9d, 0x59, 0x2a, 0x77, 0x78, 0x89, 0x78, 0x79].into(),
[0x00, 0xe4, 0xa1, 0x06, 0x50, 0xe5, 0xa6, 0xD6, 0x00, 0x1C,
0x38, 0xff, 0x8E, 0x64, 0xF9, 0x70, 0x16, 0xa1, 0x64, 0x5c].into(),
[0x00, 0xa0, 0xa2, 0x4b, 0x9f, 0x0e, 0x5e, 0xc7, 0xaa, 0x4c,
0x73, 0x89, 0xb8, 0x30, 0x2f, 0xd0, 0x12, 0x31, 0x94, 0xde].into(),
],
})
}
12 changes: 12 additions & 0 deletions bridges/bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate/"

[dependencies.pallet-bridge-eth-poa]
version = "0.1.0"
default-features = false
path = "../../../modules/ethereum"

[dependencies.frame-support]
version = "2.0.0-alpha.2"
default-features = false
Expand Down Expand Up @@ -91,6 +96,11 @@ default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate/"

[dependencies.sp-bridge-eth-poa]
version = "0.1.0"
default-features = false
path = "../../../primitives/ethereum-poa"

[dependencies.sp-consensus-aura]
version = "0.8.0-alpha.2"
default-features = false
Expand Down Expand Up @@ -162,6 +172,7 @@ default = ["std"]
std = [
"pallet-aura/std",
"pallet-balances/std",
"pallet-bridge-eth-poa/std",
"codec/std",
"frame-executive/std",
"frame-support/std",
Expand All @@ -171,6 +182,7 @@ std = [
"serde",
"sp-api/std",
"sp-block-builder/std",
"sp-bridge-eth-poa/std",
"sp-consensus-aura/std",
"sp-core/std",
"sp-inherents/std",
Expand Down
22 changes: 22 additions & 0 deletions bridges/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub use frame_support::{
traits::Randomness,
weights::Weight,
};
pub use pallet_bridge_eth_poa::Call as BridgeEthPoACall;

/// An index to a block.
pub type BlockNumber = u32;
Expand Down Expand Up @@ -186,6 +187,10 @@ impl pallet_aura::Trait for Runtime {
type AuthorityId = AuraId;
}

impl pallet_bridge_eth_poa::Trait for Runtime {
type OnHeadersSubmitted = ();
}

impl pallet_grandpa::Trait for Runtime {
type Event = Event;
}
Expand Down Expand Up @@ -248,6 +253,7 @@ construct_runtime!(
Balances: pallet_balances::{Module, Call, Storage, Config<T>, Event<T>},
TransactionPayment: pallet_transaction_payment::{Module, Storage},
Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},
BridgeEthPoA: pallet_bridge_eth_poa::{Module, Call, Config, Storage},
}
);

Expand All @@ -270,6 +276,8 @@ pub type SignedExtra = (
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>
);
/// The payload being signed in transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
/// Extrinsic type that has already been checked.
Expand Down Expand Up @@ -327,6 +335,20 @@ impl_runtime_apis! {
}
}

impl sp_bridge_eth_poa::EthereumHeadersApi<Block> for Runtime {
fn best_block() -> (u64, sp_bridge_eth_poa::H256) {
BridgeEthPoA::best_block()
}

fn is_import_requires_receipts(header: sp_bridge_eth_poa::Header) -> bool {
BridgeEthPoA::is_import_requires_receipts(header)
}

fn is_known_block(hash: sp_bridge_eth_poa::H256) -> bool {
BridgeEthPoA::is_known_block(hash)
}
}

impl sp_transaction_pool::runtime_api::TaggedTransactionQueue<Block> for Runtime {
fn validate_transaction(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity {
Executive::validate_transaction(tx)
Expand Down
2 changes: 1 addition & 1 deletion bridges/modules/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ git = "https://github.com/paritytech/substrate/"
[dev-dependencies]
# TODO: Stop renaming this on import
primitives = { package = "sp-bridge-eth-poa", path = "../../primitives/ethereum-poa", features = ["std", "test-helpers"] }
parity-crypto = { version = "0.4", features = ["publickey"] }
parity-crypto = { version = "0.6", features = ["publickey"] }

[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion bridges/modules/substrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate/"


[dependencies.pallet-session]
version = "2.0.0-alpha.2"
default-features = false
Expand Down
31 changes: 25 additions & 6 deletions bridges/primitives/ethereum-poa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,35 @@ impl-rlp = { version = "0.2", default-features = false }
impl-serde = { version = "0.2.3", optional = true }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false }
rlp = { version = "0.4", default-features = false }

sp-std = { version = "2.0.0-alpha.2", git = "https://github.com/paritytech/substrate.git", default-features = false, rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31" }
sp-runtime = { version = "2.0.0-alpha.2", git = "https://github.com/paritytech/substrate.git", default-features = false, rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31" }
sp-api = { version = "2.0.0-alpha.2", git = "https://github.com/paritytech/substrate.git", default-features = false, rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31" }
sp-io = { version = "2.0.0-alpha.2", git = "https://github.com/paritytech/substrate.git", default-features = false, rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31" }

hash-db = { version = "0.15.2", default-features = false }
triehash = { version = "0.8.2", default-features = false }
plain_hasher = { version = "0.2.2", default-features = false }

# Substrate Based Dependencies
[dependencies.sp-api]
version = "2.0.0-alpha.2"
default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[dependencies.sp-std]
version = "2.0.0-alpha.2"
default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[dependencies.sp-runtime]
version = "2.0.0-alpha.2"
default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[dependencies.sp-io]
version = "2.0.0-alpha.2"
default-features = false
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[features]
default = ["std"]
test-helpers = []
Expand Down
54 changes: 43 additions & 11 deletions bridges/relays/ethereum/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "async-bridge"
name = "ethereum-poa-relay"
version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
Expand All @@ -11,22 +11,54 @@ async-stream = "0.2.0"
clap = { version = "2.33.0", features = ["yaml"] }
codec = { package = "parity-scale-codec", version = "1.0.0" }
env_logger = "0.7.0"
frame-system = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
futures = "0.3.1"
jsonrpsee-core = { git = "https://github.com/paritytech/jsonrpsee.git" }
jsonrpsee-http = { git = "https://github.com/paritytech/jsonrpsee.git" }
jsonrpsee = { git = "https://github.com/paritytech/jsonrpsee.git", default-features = false, features = ["http"] }
linked-hash-map = "0.5.2"
log = "0.4.8"
node-primitives = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
node-runtime = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
pallet-transaction-payment = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
parking_lot = "0.9.0"
rustc-hex = "2.0.1"
serde = { version = "1.0.40", features = ["derive"] }
serde_json = "1.0.40"
sp-bridge-eth-poa = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
sp-core = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
sp-keyring = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
sp-runtime = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
sp-bridge-eth-poa = { path = "../../primitives/ethereum-poa" }
time = "0.1"
web3 = { git = "https://github.com/svyatonik/rust-web3.git", branch = "fix_receipt" }

# Substrate Based Dependencies
[dependencies.frame-system]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate/"

[dependencies.pallet-transaction-payment]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

# I think this is used for sr-io and stuff
[dependencies.node-primitives]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

# Branch used for keccack256 hasher code
# Could probably move the keccack hasher stuff to our own primitives
[dependencies.sp-core]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[dependencies.sp-keyring]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

[dependencies.sp-runtime]
version = "2.0.0-alpha.2"
rev = "2afecf81ee19b8a6edb364b419190ea47c4a4a31"
git = "https://github.com/paritytech/substrate.git"

# This should get moved to our `bin` folder
[dependencies.bridge-node-runtime]
version = "0.1.0"
path = "../../bin/node/runtime"
# node-runtime = { git = "https://github.com/svyatonik/substrate.git", branch = "bridge_runtime" }
17 changes: 12 additions & 5 deletions bridges/relays/ethereum/src/ethereum_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
// You should have received a copy of the GNU General Public License
// along with Parity-Bridge. If not, see <http://www.gnu.org/licenses/>.

use jsonrpsee_core::{client::ClientError, common::Params};
use jsonrpsee_http::{HttpClient, RequestError, http_client};
use jsonrpsee::common::Params;
use jsonrpsee::raw::{
RawClient,
RawClientError,
};
use jsonrpsee::transport::http::{
HttpTransportClient, RequestError
};
use serde::de::DeserializeOwned;
use serde_json::{from_value, to_value};
use crate::ethereum_sync_loop::MaybeConnectionError;
Expand All @@ -45,7 +51,7 @@ const INT_SERIALIZATION_PROOF: &'static str = "integer serialization never fails
const BOOL_SERIALIZATION_PROOF: &'static str = "bool serialization never fails; qed";

/// Ethereum client type.
pub type Client = HttpClient;
pub type Client = RawClient<HttpTransportClient>;

/// All possible errors that can occur during interacting with Ethereum node.
#[derive(Debug)]
Expand All @@ -55,7 +61,7 @@ pub enum Error {
/// Request not found (should never occur?).
RequestNotFound,
/// Failed to receive response.
ResponseRetrievalFailed(ClientError<RequestError>),
ResponseRetrievalFailed(RawClientError<RequestError>),
/// Failed to parse response.
ResponseParseFailed(serde_json::Error),
/// We have received header with missing number and hash fields.
Expand All @@ -75,7 +81,8 @@ impl MaybeConnectionError for Error {

/// Returns client that is able to call RPCs on Ethereum node.
pub fn client(uri: &str) -> Client {
http_client(uri)
let transport = HttpTransportClient::new(uri);
RawClient::new(transport)
}

/// Retrieve best known block number from Ethereum node.
Expand Down
Loading

0 comments on commit 2f255bd

Please sign in to comment.