Skip to content

Commit

Permalink
update api-client to tag-0.14.0; fix parachain block import (#1452)
Browse files Browse the repository at this point in the history
* [itc-parentchain] test replace the wsrpc-client with the tungstenite client

* fix api-client feature flags in cli and service

* bump api-client to polkadot-v0.9.42-tag-v0.14.0; dependency resolution works, enclave compiles

* bump api client to fix some trait bound errors

* [api-client-types] fix import paths

* [node-metadata] fix deprecated methods

* fixes to make the service compile

* update api client to fix client-keystore compilation

* fix client build

* fix service build

* upgrade api-client to fix no-std compilation issue

* cargo lock

* add code annotations for api-client type update

* [cli] fix `register_tcb_info` after rebase on master

* [cli] minor code optimizations

* [ipt-api-client-extensions] optimize toml

* [api-client-extensions] remove unnecessary trait bounds

* [service] add more comments for clean up of the api-client types

* [service/account_funding] restore previous behaviour of waiting until in block only.

* [local-setup] fix node-log for `tmux_logger.sh`

* [service/parentchain_handler] fix clippy

* taplo fmt

* fix cargo test

* Fix: Don't panic if the extrinsic was not found while registering.

* fix teeracle mode compilation

* fix teeracle build

* fix warnings when not compiling with teeracle flag

* fix clippy again
  • Loading branch information
clangenb authored Sep 15, 2023
1 parent 3d257de commit b9c8016
Show file tree
Hide file tree
Showing 41 changed files with 900 additions and 706 deletions.
806 changes: 390 additions & 416 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ pallet-evm = { optional = true, git = "https://github.com/integritee-network/fro
pallet-teerex = { git = "https://github.com/integritee-network/pallets.git", branch = "sdk-v0.12.0-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.0-polkadot-v0.9.42" }
substrate-api-client = { default-features = false, features = ["std", "ws-client"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
substrate-client-keystore = { git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
# 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" }

# substrate dependencies
frame-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand Down
5 changes: 2 additions & 3 deletions cli/src/base_cli/commands/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api},
Cli, CliResult, CliResultOk,
};
use itp_node_api::api_client::ParentchainExtrinsicSigner;
use my_node_runtime::{BalancesCall, RuntimeCall};
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
use std::vec::Vec;
use substrate_api_client::{compose_extrinsic_offline, SubmitExtrinsic};
use substrate_api_client::{ac_compose_macros::compose_extrinsic_offline, SubmitExtrinsic};

const PREFUNDING_AMOUNT: u128 = 1_000_000_000;

Expand All @@ -38,7 +37,7 @@ pub struct FaucetCommand {
impl FaucetCommand {
pub(crate) fn run(&self, cli: &Cli) -> CliResult {
let mut api = get_chain_api(cli);
api.set_signer(ParentchainExtrinsicSigner::new(AccountKeyring::Alice.pair()));
api.set_signer(AccountKeyring::Alice.pair().into());
let mut nonce = api.get_nonce().unwrap();
for account in &self.accounts {
let to = get_accountid_from_str(account);
Expand Down
2 changes: 1 addition & 1 deletion cli/src/base_cli/commands/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl ListenCommand {
}
};

let event_results = subscription.next_event::<RuntimeEvent, Hash>().unwrap();
let event_results = subscription.next_events::<RuntimeEvent, Hash>().unwrap();
blocks += 1;
match event_results {
Ok(evts) =>
Expand Down
12 changes: 7 additions & 5 deletions cli/src/base_cli/commands/register_tcb_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ use crate::{
command_utils::{get_chain_api, *},
Cli, CliResult, CliResultOk,
};
use itp_node_api::api_client::{ParentchainExtrinsicSigner, TEEREX};
use itp_node_api::api_client::TEEREX;
use itp_types::{parentchain::Hash, OpaqueCall};
use itp_utils::ToHexPrefixed;
use log::*;
use regex::Regex;
use serde::Deserialize;
use sp_core::sr25519 as sr25519_core;
use substrate_api_client::{compose_call, compose_extrinsic_offline, SubmitAndWatchUntilSuccess};
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic_offline},
SubmitAndWatch, XtStatus,
};
use urlencoding;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -54,7 +56,7 @@ impl RegisterTcbInfoCommand {

// Get the sender.
let from = get_pair_from_str(&self.sender);
chain_api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(from)));
chain_api.set_signer(from.into());

let fmspcs = if self.all {
trace!("fetching all fmspc's from api.trustedservices.intel.com");
Expand Down Expand Up @@ -123,7 +125,7 @@ impl RegisterTcbInfoCommand {
chain_api.extrinsic_params(nonce)
);
nonce += 1;
match chain_api.submit_and_watch_extrinsic_until_success(xt, false) {
match chain_api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) {
Ok(xt_report) => {
println!(
"[+] register_tcb_info. extrinsic hash: {:?} / status: {:?}",
Expand Down
8 changes: 4 additions & 4 deletions cli/src/base_cli/commands/shield_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use crate::{
};
use base58::FromBase58;
use codec::{Decode, Encode};
use itp_node_api::api_client::{ParentchainExtrinsicSigner, ENCLAVE_BRIDGE};
use itp_node_api::api_client::ENCLAVE_BRIDGE;
use itp_sgx_crypto::ShieldingCryptoEncrypt;
use itp_stf_primitives::types::ShardIdentifier;
use log::*;
use my_node_runtime::Balance;
use sp_core::sr25519 as sr25519_core;
use substrate_api_client::{compose_extrinsic, SubmitAndWatchUntilSuccess};
use substrate_api_client::{ac_compose_macros::compose_extrinsic, SubmitAndWatch, XtStatus};

#[derive(Parser)]
pub struct ShieldFundsCommand {
Expand Down Expand Up @@ -57,7 +57,7 @@ impl ShieldFundsCommand {

// Get the sender.
let from = get_pair_from_str(&self.from);
chain_api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(from)));
chain_api.set_signer(sr25519_core::Pair::from(from).into());

// Get the recipient.
let to = get_accountid_from_str(&self.to);
Expand All @@ -75,7 +75,7 @@ impl ShieldFundsCommand {
self.amount
);

match chain_api.submit_and_watch_extrinsic_until_success(xt, true) {
match chain_api.submit_and_watch_extrinsic_until(xt, XtStatus::Finalized) {
Ok(xt_report) => {
println!(
"[+] shield funds success. extrinsic hash: {:?} / status: {:?} / block hash: {:?}",
Expand Down
11 changes: 5 additions & 6 deletions cli/src/base_cli/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ use crate::{
command_utils::{get_accountid_from_str, get_chain_api, *},
Cli, CliResult, CliResultOk,
};
use itp_node_api::api_client::{Address, ParentchainExtrinsicSigner};
use log::*;
use my_node_runtime::Balance;
use sp_core::{crypto::Ss58Codec, sr25519 as sr25519_core, Pair};
use sp_core::{crypto::Ss58Codec, Pair};
use substrate_api_client::{
extrinsic::BalancesExtrinsics, GetAccountInformation, SubmitAndWatchUntilSuccess,
extrinsic::BalancesExtrinsics, GetAccountInformation, SubmitAndWatch, XtStatus,
};

#[derive(Parser)]
Expand All @@ -46,9 +45,9 @@ impl TransferCommand {
info!("from ss58 is {}", from_account.public().to_ss58check());
info!("to ss58 is {}", to_account.to_ss58check());
let mut api = get_chain_api(cli);
api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(from_account)));
let xt = api.balance_transfer_allow_death(Address::Id(to_account.clone()), self.amount);
let tx_report = api.submit_and_watch_extrinsic_until_success(xt, false).unwrap();
api.set_signer(from_account.into());
let xt = api.balance_transfer_allow_death(to_account.clone().into(), self.amount);
let tx_report = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock).unwrap();
println!(
"[+] L1 extrinsic success. extrinsic hash: {:?} / status: {:?}",
tx_report.extrinsic_hash, tx_report.status
Expand Down
6 changes: 2 additions & 4 deletions cli/src/base_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use itp_node_api::api_client::PalletTeerexApi;
use sp_core::crypto::Ss58Codec;
use sp_keystore::Keystore;
use std::path::PathBuf;
use substrate_api_client::Metadata;
use substrate_client_keystore::LocalKeystore;

mod commands;
Expand Down Expand Up @@ -130,14 +129,13 @@ fn list_accounts() -> CliResult {
fn print_metadata(cli: &Cli) -> CliResult {
let api = get_chain_api(cli);
let meta = api.metadata();
println!("Metadata:\n {}", Metadata::pretty_format(&meta.runtime_metadata()).unwrap());
println!("Metadata:\n {}", &meta.pretty_format().unwrap());
Ok(CliResultOk::Metadata { metadata: meta.clone() })
}

fn print_sgx_metadata(cli: &Cli) -> CliResult {
let worker_api_direct = get_worker_api_direct(cli);
let metadata = worker_api_direct.get_state_metadata().unwrap();
println!("Metadata:\n {}", Metadata::pretty_format(metadata.runtime_metadata()).unwrap());
println!("Metadata:\n {}", metadata.pretty_format().unwrap());
Ok(CliResultOk::Metadata { metadata })
}

Expand Down
4 changes: 2 additions & 2 deletions cli/src/command_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use crate::Cli;
use base58::FromBase58;
use itc_rpc_client::direct_client::{DirectApi, DirectClient as DirectWorkerApi};
use itp_node_api::api_client::{ParentchainApi, WsRpcClient};
use itp_node_api::api_client::{ParentchainApi, TungsteniteRpcClient};
use log::*;
use my_node_runtime::{AccountId, Signature};
use sgx_crypto_helper::rsa3072::Rsa3072PubKey;
Expand All @@ -40,7 +40,7 @@ pub(crate) fn get_shielding_key(cli: &Cli) -> Result<Rsa3072PubKey, String> {
pub(crate) fn get_chain_api(cli: &Cli) -> ParentchainApi {
let url = format!("{}:{}", cli.node_url, cli.node_port);
info!("connecting to {}", url);
ParentchainApi::new(WsRpcClient::new(&url).unwrap()).unwrap()
ParentchainApi::new(TungsteniteRpcClient::new(&url, 5).unwrap()).unwrap()
}

pub(crate) fn get_accountid_from_str(account: &str) -> AccountId {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ pub mod commands;

use crate::commands::Commands;
use clap::Parser;
use itp_node_api::api_client::Metadata;
use sp_application_crypto::KeyTypeId;
use sp_core::{H160, H256};
use substrate_api_client::Metadata;
use thiserror::Error;

const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
9 changes: 6 additions & 3 deletions cli/src/oracle/commands/add_to_whitelist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ use crate::{
command_utils::{get_chain_api, get_pair_from_str, mrenclave_from_base58},
Cli,
};
use itp_node_api::api_client::{ParentchainExtrinsicSigner, ADD_TO_WHITELIST, TEERACLE};
use substrate_api_client::{compose_call, compose_extrinsic, SubmitAndWatch, XtStatus};
use itp_node_api::api_client::{ADD_TO_WHITELIST, TEERACLE};
use substrate_api_client::{
ac_compose_macros::{compose_call, compose_extrinsic},
SubmitAndWatch, XtStatus,
};

/// Add a trusted market data source to the on-chain whitelist.
#[derive(Debug, Clone, Parser)]
Expand All @@ -45,7 +48,7 @@ impl AddToWhitelistCmd {

let market_data_source = self.source.clone();

api.set_signer(ParentchainExtrinsicSigner::new(from.into()));
api.set_signer(from.into());

let call = compose_call!(
api.metadata(),
Expand Down
2 changes: 1 addition & 1 deletion cli/src/oracle/commands/listen_to_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub fn count_exchange_rate_update_events(api: &ParentchainApi, duration: Duratio
let mut count = 0;

while remaining_time(stop).unwrap_or_default() > Duration::ZERO {
let events_result = subscription.next_event::<RuntimeEvent, Hash>().unwrap();
let events_result = subscription.next_events::<RuntimeEvent, Hash>().unwrap();
if let Ok(events) = events_result {
for event_record in &events {
info!("received event {:?}", event_record.event);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/oracle/commands/listen_to_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use itp_time_utils::{duration_now, remaining_time};
use log::{debug, info};
use my_node_runtime::{Hash, RuntimeEvent};
use std::time::Duration;
use substrate_api_client::{EventRecord, SubscribeEvents};
use substrate_api_client::{ac_node_api::EventRecord, SubscribeEvents};

/// Listen to exchange rate events.
#[derive(Debug, Clone, Parser)]
Expand Down Expand Up @@ -51,7 +51,7 @@ fn count_oracle_update_events(api: &ParentchainApi, duration: Duration) -> Event
let mut count = 0;

while remaining_time(stop).unwrap_or_default() > Duration::ZERO {
let events_result = subscription.next_event::<RuntimeEvent, Hash>();
let events_result = subscription.next_events::<RuntimeEvent, Hash>();
let event_count = match events_result {
Some(Ok(event_records)) => {
debug!("Could not successfully decode event_bytes {:?}", event_records);
Expand Down
12 changes: 6 additions & 6 deletions cli/src/trusted_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use codec::{Decode, Encode};
use enclave_bridge_primitives::Request;
use ita_stf::{Getter, TrustedOperation};
use itc_rpc_client::direct_client::{DirectApi, DirectClient};
use itp_node_api::api_client::{ParentchainApi, ParentchainExtrinsicSigner, ENCLAVE_BRIDGE};
use itp_node_api::api_client::{ParentchainApi, ENCLAVE_BRIDGE};
use itp_rpc::{RpcRequest, RpcResponse, RpcReturnValue};
use itp_sgx_crypto::ShieldingCryptoEncrypt;
use itp_stf_primitives::types::ShardIdentifier;
Expand All @@ -35,14 +35,14 @@ use itp_utils::{FromHexPrefixed, ToHexPrefixed};
use log::*;
use my_node_runtime::{Hash, RuntimeEvent};
use pallet_enclave_bridge::Event as EnclaveBridgeEvent;
use sp_core::{sr25519 as sr25519_core, H256};
use sp_core::H256;
use std::{
result::Result as StdResult,
sync::mpsc::{channel, Receiver},
time::Instant,
};
use substrate_api_client::{
compose_extrinsic, GetHeader, SubmitAndWatchUntilSuccess, SubscribeEvents,
ac_compose_macros::compose_extrinsic, GetChainInfo, SubmitAndWatch, SubscribeEvents, XtStatus,
};
use thiserror::Error;

Expand Down Expand Up @@ -135,12 +135,12 @@ fn send_indirect_request(
);
let arg_signer = &trusted_args.xt_signer;
let signer = get_pair_from_str(arg_signer);
chain_api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(signer)));
chain_api.set_signer(signer.into());

let request = Request { shard, cyphertext: call_encrypted };
let xt = compose_extrinsic!(&chain_api, ENCLAVE_BRIDGE, "invoke", request);

let block_hash = match chain_api.submit_and_watch_extrinsic_until_success(xt, false) {
let block_hash = match chain_api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock) {
Ok(xt_report) => {
println!(
"[+] invoke TrustedOperation extrinsic success. extrinsic hash: {:?} / status: {:?} / block hash: {:?}",
Expand All @@ -161,7 +161,7 @@ fn send_indirect_request(
info!("Waiting for execution confirmation from enclave...");
let mut subscription = chain_api.subscribe_events().unwrap();
loop {
let event_records = subscription.next_event::<RuntimeEvent, Hash>().unwrap().unwrap();
let event_records = subscription.next_events::<RuntimeEvent, Hash>().unwrap().unwrap();
for event_record in event_records {
if let RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ProcessedParentchainBlock {
shard,
Expand Down
6 changes: 3 additions & 3 deletions core-primitives/enclave-api/src/sidechain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ use itp_enclave_api_ffi as ffi;
use itp_storage::StorageProof;
use itp_types::parentchain::ParentchainId;
use sgx_types::sgx_status_t;
use sp_runtime::{generic::SignedBlock, traits::Block as ParentchainBlockTrait};
use sp_runtime::generic::SignedBlock;

/// trait for handling blocks on the side chain
pub trait Sidechain: Send + Sync + 'static {
/// Sync parentchain blocks and events. Execute pending tops
/// and events proof in the enclave.
fn sync_parentchain<ParentchainBlock: ParentchainBlockTrait>(
fn sync_parentchain<ParentchainBlock: Encode>(
&self,
blocks: &[SignedBlock<ParentchainBlock>],
events: &[Vec<u8>],
Expand All @@ -41,7 +41,7 @@ pub trait Sidechain: Send + Sync + 'static {
}

impl Sidechain for Enclave {
fn sync_parentchain<ParentchainBlock: ParentchainBlockTrait>(
fn sync_parentchain<ParentchainBlock: Encode>(
&self,
blocks: &[SignedBlock<ParentchainBlock>],
events: &[Vec<u8>],
Expand Down
2 changes: 1 addition & 1 deletion core-primitives/extrinsics-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
# sgx dependencies
sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git", optional = true }
sgx_types = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sdk.git" }
substrate-api-client = { default-features = false, git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
substrate-api-client = { default-features = false, features = ["sync-api"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" }

# local dependencies
itp-node-api = { path = "../node-api", default-features = false }
Expand Down
6 changes: 4 additions & 2 deletions core-primitives/extrinsics-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ pub mod sgx_reexport_prelude {
use codec::Encode;
use error::Result;
use itp_node_api::{
api_client::{ParentchainAdditionalParams, ParentchainExtrinsicParams},
api_client::{
ExtrinsicParams, ParentchainAdditionalParams, ParentchainExtrinsicParams, SignExtrinsic,
},
metadata::{provider::AccessNodeMetadata, NodeMetadata},
};
use itp_nonce_cache::{MutateNonce, Nonce};
use itp_types::{parentchain::AccountId, OpaqueCall};
use sp_core::H256;
use sp_runtime::{generic::Era, OpaqueExtrinsic};
use std::{sync::Arc, vec::Vec};
use substrate_api_client::{compose_extrinsic_offline, ExtrinsicParams, SignExtrinsic};
use substrate_api_client::ac_compose_macros::compose_extrinsic_offline;

pub mod error;

Expand Down
3 changes: 2 additions & 1 deletion core-primitives/node-api/api-client-extensions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"] }
log = { version = "0.4" }
thiserror = { version = "1.0" }

# substrate
Expand All @@ -16,7 +17,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po

# scs
# `default-features = false` to remove the jsonrpsee dependency.
substrate-api-client = { default-features = false, features = ["std"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.10.0" }
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" }

# local deps
itp-api-client-types = { path = "../api-client-types" }
Expand Down
Loading

0 comments on commit b9c8016

Please sign in to comment.