Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom dependencies on parentchain runtimes to decode L1 Events #1528

Merged
merged 46 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
4f7d3b3
introduced parachain runtime, but won't work without upgrading toolch…
brenzi Dec 9, 2023
d325d62
new Cargo.lock and downgraded clap to 4.0.9
brenzi Dec 9, 2023
7ebea59
upgrading non-sgx workspace toolchain to rustc 1.70
brenzi Dec 9, 2023
a8e6e9e
just cleanly move runtime dep for solo. builds
brenzi Dec 12, 2023
b08f76e
minimal change causing trouble with build
brenzi Dec 13, 2023
9c9c57f
ita-parentchain-interface build works now with default fetures
brenzi Dec 13, 2023
a6b0029
propagate parentchain deps. only depend on parachain runtime now
brenzi Dec 13, 2023
0a67df4
make cli build work. cleanup deps versions
brenzi Dec 13, 2023
e48e565
WIP bump parachain dep to 1.6.3
brenzi Dec 18, 2023
a13bfc1
cargo update didn't work neither
brenzi Dec 18, 2023
99c412b
fix double deps on two branches of our pallets
brenzi Dec 18, 2023
18a84c3
patch ring to xous
brenzi Dec 18, 2023
7bab547
overwritten Cargo.lock from parachain
brenzi Dec 18, 2023
739627d
try enclave-runtime too. std collision
brenzi Dec 18, 2023
f8f9a69
copied litentry-worker lockfile
brenzi Dec 18, 2023
0a32169
prometheus may not use std!
brenzi Dec 18, 2023
3e00030
service builds
brenzi Dec 19, 2023
8d6977d
Merge remote-tracking branch 'origin/master' into ab/custom-parentcha…
brenzi Dec 19, 2023
cff2aac
lockfile copied from parachain to enclave-runtime
brenzi Dec 19, 2023
fff6036
everything builds
brenzi Dec 19, 2023
687f40a
set resolver explicitly
brenzi Dec 19, 2023
54845e3
re-add solochain types along parachain types
brenzi Dec 19, 2023
4a9d6e4
Events can be decoded for both integritee solo or parachains
brenzi Dec 19, 2023
bd3efb0
moved event printing to ita_parentchain_interface
brenzi Dec 19, 2023
9c88dfc
event subscription works for solo and two-para setup
brenzi Dec 19, 2023
30eed21
cleanup
brenzi Dec 19, 2023
123323d
taplo fmt
brenzi Dec 19, 2023
bfebc34
cleanup
brenzi Dec 19, 2023
8f24e2f
revert toolchain change as it breaks cargo test
brenzi Dec 19, 2023
a2cf395
taplo fmt
brenzi Dec 19, 2023
7a08551
fix clippy and teeracle cli build
brenzi Dec 19, 2023
433d988
fix event listener cli for solo and para
brenzi Dec 20, 2023
fb3477e
implement cli trustedoperation event handling for both para and solo …
brenzi Dec 20, 2023
9fcc81f
implement oracle update listeners for para and solo cases
brenzi Dec 20, 2023
ec14af8
taplo
brenzi Dec 20, 2023
87123ae
review comments
brenzi Dec 20, 2023
fb6f7cb
remove last remaining runtime dependency outside ita*
brenzi Dec 20, 2023
8bdde89
fix teeracle build
brenzi Dec 20, 2023
655ad3e
fmt
brenzi Dec 20, 2023
8fc6663
cli listen now decodes events from metadata without Runtime dependency
brenzi Dec 20, 2023
e1b7f21
cli: all event listeners use metadata now
brenzi Dec 20, 2023
6f5fdc3
taplo
brenzi Dec 20, 2023
cf8e821
unified parentchain event listeners
brenzi Dec 20, 2023
f66cb45
cargo fix
brenzi Dec 20, 2023
7ff438c
fmt
brenzi Dec 20, 2023
674e386
clippy
brenzi Dec 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9,633 changes: 7,580 additions & 2,053 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ members = [
"sidechain/state",
"sidechain/validateer-fetch",
]
resolver = "2"
brenzi marked this conversation as resolved.
Show resolved Hide resolved

[patch."https://github.com/apache/teaclave-sgx-sdk.git"]
sgx_alloc = { version = "1.1.6", git = "https://github.com/apache/incubator-teaclave-sgx-sdk", branch = "master" }
Expand Down
14 changes: 13 additions & 1 deletion app-libs/parentchain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sd
# local dependencies
ita-sgx-runtime = { path = "../sgx-runtime", default-features = false }
ita-stf = { path = "../stf", default-features = false }
itc-parentchain = { path = "../../core/parentchain/parentchain-crate", default-features = false }
itc-parentchain-indirect-calls-executor = { path = "../../core/parentchain/indirect-calls-executor", default-features = false }
itp-api-client-types = { path = "../../core-primitives/node-api/api-client-types", default-features = false }
itp-node-api = { path = "../../core-primitives/node-api", default-features = false }
Expand All @@ -22,6 +23,13 @@ itp-utils = { path = "../../core-primitives/utils", default-features = false }
bs58 = { version = "0.4.0", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
log = { version = "0.4", default-features = false }
regex = { optional = true, version = "1.9.5" }

integritee-parachain-runtime = { package = "integritee-runtime", git = "https://github.com/integritee-network/parachain", branch = "sdk-v0.12.6-polkadot-v0.9.42", default-features = false, optional = true }
integritee-solochain-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network/integritee-node.git/", branch = "sdk-v0.12.6-polkadot-v0.9.42", default-features = false, optional = true }

substrate-api-client = { optional = true, default-features = false, features = ["std", "sync-api"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" }


# substrate dep
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand All @@ -44,6 +52,7 @@ std = [
"codec/std",
"ita-sgx-runtime/std",
"ita-stf/std",
"itc-parentchain/std",
"itc-parentchain-indirect-calls-executor/std",
"itp-api-client-types/std",
"itp-node-api/std",
Expand All @@ -54,9 +63,12 @@ std = [
"itp-types/std",
"itp-utils/std",
"log/std",
#substrate
"regex",
"sp-core/std",
"sp-runtime/std",
"substrate-api-client",
"integritee-parachain-runtime/std",
"integritee-solochain-runtime/std",
]
sgx = [
"sgx_tstd",
Expand Down
32 changes: 32 additions & 0 deletions app-libs/parentchain-interface/src/integritee/event_subscriber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::print_events;
use itc_parentchain::primitives::ParentchainInitParams;
use itp_api_client_types::ParentchainApi;
use substrate_api_client::SubscribeEvents;

const PARENTCHAIN_NAME: &str = "Integritee";
pub fn subscribe_to_parentchain_events(
api: &ParentchainApi,
parentchain_init_params: ParentchainInitParams,
) {
println!("[L1Event:{}] Subscribing to events", PARENTCHAIN_NAME);
let mut subscription = api.subscribe_events().unwrap();
loop {
if parentchain_init_params.is_parachain() {
if let Some(Ok(events)) =
subscription.next_events::<super::parachain::RuntimeEvent, super::parachain::Hash>()
{
print_events::<super::parachain::RuntimeEvent, super::parachain::Hash>(
events,
format!("[L1Event:{}Para]", PARENTCHAIN_NAME),
)
}
} else if let Some(Ok(events)) =
subscription.next_events::<super::solochain::RuntimeEvent, super::solochain::Hash>()
{
print_events::<super::solochain::RuntimeEvent, super::solochain::Hash>(
events,
format!("[L1Event:{}Solo]", PARENTCHAIN_NAME),
)
}
}
}
19 changes: 19 additions & 0 deletions app-libs/parentchain-interface/src/integritee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

mod event_filter;
mod event_handler;
#[cfg(feature = "std")]
pub mod event_subscriber;
mod extrinsic_parser;

use crate::{
decode_and_log_error,
indirect_calls::{invoke::InvokeArgs, shield_funds::ShieldFundsArgs},
Expand All @@ -37,6 +40,22 @@ use itc_parentchain_indirect_calls_executor::{
use itp_node_api::metadata::NodeMetadataTrait;
use itp_stf_primitives::traits::IndirectExecutor;
use log::trace;

#[cfg(feature = "std")]
pub mod parachain {
pub use integritee_parachain_runtime::{
pallet_teeracle, AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime,
RuntimeCall, RuntimeEvent, Signature, UncheckedExtrinsic,
};
}
#[cfg(feature = "std")]
pub mod solochain {
pub use integritee_solochain_runtime::{
pallet_teeracle, AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime,
RuntimeCall, RuntimeEvent, Signature, UncheckedExtrinsic,
};
}

/// The default indirect call (extrinsic-triggered) of the Integritee-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub enum IndirectCall {
Expand Down
24 changes: 24 additions & 0 deletions app-libs/parentchain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
extern crate sgx_tstd as std;

use codec::Decode;
#[cfg(feature = "std")]
use regex::Regex;
#[cfg(feature = "std")]
use substrate_api_client::ac_node_api::{EventRecord, Phase::ApplyExtrinsic};

pub mod indirect_calls;
pub mod integritee;
Expand All @@ -37,3 +41,23 @@ pub fn decode_and_log_error<V: Decode>(encoded: &mut &[u8]) -> Option<V> {
},
}
}

#[cfg(feature = "std")]
/// trims Debug fmt output for events to be easily readable on logs
pub fn trim_event(event: String) -> String {
let re = Regex::new(r"\s[0-9a-f]*\s\(").unwrap();
re.replace_all(&event, "(").replace("RuntimeEvent::", "").replace("Event::", "")
}
#[cfg(feature = "std")]
fn print_events<R, H>(events: Vec<EventRecord<R, H>>, prefix: String)
where
R: core::fmt::Debug,
{
for evr in &events {
if evr.phase == ApplyExtrinsic(0) {
// not interested in intrinsics
continue
}
println!("{} {}", prefix, trim_event(format!("{:?}", evr.event)));
}
}
32 changes: 32 additions & 0 deletions app-libs/parentchain-interface/src/target_a/event_subscriber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::print_events;
use itc_parentchain::primitives::ParentchainInitParams;
use itp_api_client_types::ParentchainApi;
use substrate_api_client::SubscribeEvents;

const PARENTCHAIN_NAME: &str = "TargetA";
pub fn subscribe_to_parentchain_events(
api: &ParentchainApi,
parentchain_init_params: ParentchainInitParams,
) {
println!("[L1Event:{}] Subscribing to events", PARENTCHAIN_NAME);
let mut subscription = api.subscribe_events().unwrap();
loop {
if parentchain_init_params.is_parachain() {
if let Some(Ok(events)) =
subscription.next_events::<super::parachain::RuntimeEvent, super::parachain::Hash>()
{
print_events::<super::parachain::RuntimeEvent, super::parachain::Hash>(
events,
format!("[L1Event:{}Para]", PARENTCHAIN_NAME),
)
}
} else if let Some(Ok(events)) =
subscription.next_events::<super::solochain::RuntimeEvent, super::solochain::Hash>()
{
print_events::<super::solochain::RuntimeEvent, super::solochain::Hash>(
events,
format!("[L1Event:{}Solo]", PARENTCHAIN_NAME),
)
}
}
}
23 changes: 23 additions & 0 deletions app-libs/parentchain-interface/src/target_a/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
mod event_filter;
mod event_handler;
mod extrinsic_parser;

#[cfg(feature = "std")]
pub mod event_subscriber;

use crate::{
decode_and_log_error,
indirect_calls::{
Expand All @@ -29,6 +33,10 @@ pub use event_filter::FilterableEvents;
pub use event_handler::ParentchainEventHandler;
pub use extrinsic_parser::ParentchainExtrinsicParser;
use extrinsic_parser::ParseExtrinsic;
#[cfg(feature = "std")]
pub use integritee_parachain_runtime::{
Block, Hash, Header, Runtime, RuntimeCall, RuntimeEvent, UncheckedExtrinsic,
};
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
Expand All @@ -39,6 +47,21 @@ use itp_node_api::metadata::pallet_balances::BalancesCallIndexes;
use itp_stf_primitives::traits::IndirectExecutor;
use log::{debug, trace};

#[cfg(feature = "std")]
pub mod parachain {
pub use integritee_parachain_runtime::{
AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime, RuntimeCall, RuntimeEvent,
Signature, UncheckedExtrinsic,
};
}
#[cfg(feature = "std")]
pub mod solochain {
pub use integritee_solochain_runtime::{
AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime, RuntimeCall, RuntimeEvent,
Signature, UncheckedExtrinsic,
};
}

/// The default indirect call (extrinsic-triggered) of the Target-A-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub enum IndirectCall {
Expand Down
32 changes: 32 additions & 0 deletions app-libs/parentchain-interface/src/target_b/event_subscriber.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::print_events;
use itc_parentchain::primitives::ParentchainInitParams;
use itp_api_client_types::ParentchainApi;
use substrate_api_client::SubscribeEvents;

const PARENTCHAIN_NAME: &str = "TargetB";
pub fn subscribe_to_parentchain_events(
api: &ParentchainApi,
parentchain_init_params: ParentchainInitParams,
) {
println!("[L1Event:{}] Subscribing to events", PARENTCHAIN_NAME);
let mut subscription = api.subscribe_events().unwrap();
loop {
if parentchain_init_params.is_parachain() {
if let Some(Ok(events)) =
subscription.next_events::<super::parachain::RuntimeEvent, super::parachain::Hash>()
{
print_events::<super::parachain::RuntimeEvent, super::parachain::Hash>(
events,
format!("[L1Event:{}Para]", PARENTCHAIN_NAME),
)
}
} else if let Some(Ok(events)) =
subscription.next_events::<super::solochain::RuntimeEvent, super::solochain::Hash>()
{
print_events::<super::solochain::RuntimeEvent, super::solochain::Hash>(
events,
format!("[L1Event:{}Solo]", PARENTCHAIN_NAME),
)
}
}
}
34 changes: 18 additions & 16 deletions app-libs/parentchain-interface/src/target_b/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,13 @@

*/

/*
Copyright 2021 Integritee AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*/
mod event_filter;
mod event_handler;
mod extrinsic_parser;

#[cfg(feature = "std")]
pub mod event_subscriber;

use codec::{Decode, Encode};
use core::marker::PhantomData;
pub use event_filter::FilterableEvents;
Expand All @@ -51,6 +38,21 @@ use itp_node_api::metadata::pallet_balances::BalancesCallIndexes;
use itp_stf_primitives::traits::IndirectExecutor;
use log::error;

#[cfg(feature = "std")]
pub mod parachain {
pub use integritee_parachain_runtime::{
AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime, RuntimeCall, RuntimeEvent,
Signature, UncheckedExtrinsic,
};
}
#[cfg(feature = "std")]
pub mod solochain {
pub use integritee_solochain_runtime::{
AccountId, Balance, BalancesCall, Block, Hash, Header, Runtime, RuntimeCall, RuntimeEvent,
Signature, UncheckedExtrinsic,
};
}

/// The default indirect call (extrinsic-triggered) of the Target-A-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub enum IndirectCall {}
Expand Down
1 change: 0 additions & 1 deletion app-libs/sgx-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ frame-system-benchmarking = { optional = true, default-features = false, git = "
frame-system-rpc-runtime-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-aura = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-balances = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-insecure-randomness-collective-flip = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-sudo = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
6 changes: 4 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ thiserror = "1.0"
urlencoding = "2.1.3"

# scs / integritee
my-node-runtime = { package = "integritee-node-runtime", git = "https://github.com/integritee-network/integritee-node.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }
enclave-bridge-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }
ita-parentchain-interface = { path = "../app-libs/parentchain-interface" }
pallet-enclave-bridge = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }
pallet-evm = { optional = true, git = "https://github.com/integritee-network/frontier.git", branch = "bar/polkadot-v0.9.42" }
pallet-sidechain = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }
pallet-teerex = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }

# `default-features = false` to remove the jsonrpsee dependency.
enclave-bridge-primitives = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.6-polkadot-v0.9.42" }
# disable unsupported jsonrpcsee
substrate-api-client = { default-features = false, features = ["std", "sync-api"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" }
Expand Down
2 changes: 1 addition & 1 deletion cli/src/base_cli/commands/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api},
Cli, CliResult, CliResultOk,
};
use my_node_runtime::{BalancesCall, RuntimeCall};
use ita_parentchain_interface::integritee::parachain::{BalancesCall, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
use std::vec::Vec;
Expand Down
Loading
Loading