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

support json rpc 2.0 with author_submitAndWatchExtrinsic trusted calls #1623

Merged
merged 25 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
426144d
add workaround to support json rpc 2.0 with `author_submitAndWatch` t…
clangenb Oct 25, 2024
8d70fb8
update trusted_op_direct_request
clangenb Oct 26, 2024
02466c8
fix obsolete imports in rpc_responder
clangenb Oct 26, 2024
1154741
make direct request no longer generic, it can only return the hash an…
clangenb Oct 26, 2024
1808e66
fix deserializing rpc response
clangenb Oct 26, 2024
bb0cefa
[cli/trusted_operation] remove unnecessary nesting
clangenb Oct 26, 2024
61d9cd3
fix clippy
clangenb Oct 26, 2024
da566a0
extract await status update
clangenb Oct 26, 2024
a2e4aae
[cli] fix correctly extract hash in benchmarks
clangenb Oct 26, 2024
ae68253
Merge branch 'master' into cl/proper-subscribe-interface
clangenb Oct 26, 2024
f311585
fmt
clangenb Oct 26, 2024
86fed6b
add check that we can only us direct_calls in send direct request
clangenb Oct 26, 2024
68e5da7
improve logs
clangenb Oct 26, 2024
876ffdd
add comment about storing initial top hash
clangenb Oct 26, 2024
477ed7f
add todos for rpc refactor.
clangenb Oct 26, 2024
9c36e74
better comment
clangenb Oct 26, 2024
8d6ce33
add more comments
clangenb Oct 26, 2024
f9cd82d
fix handling of indirect calls
clangenb Oct 27, 2024
1bed405
derive copy for trusted operation status
clangenb Oct 27, 2024
749ffb7
fix type inference in trusted transfer cmd
clangenb Oct 27, 2024
b519521
[cli] merge await status update from benchmark and send_direct_reques…
clangenb Oct 27, 2024
9f99f24
[cli] partially fix benchmarks
clangenb Oct 27, 2024
7e657bc
fix clippy
clangenb Oct 27, 2024
bc95fe9
fix local setup for two workers
clangenb Oct 27, 2024
0d2cade
[cli] fix: always close client in trusted_operation and return if the…
clangenb Oct 27, 2024
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
26 changes: 16 additions & 10 deletions cli/src/benchmark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_keystore_path, get_pair_from_str},
trusted_operation::{get_json_request, get_state, perform_trusted_operation, wait_until},
trusted_operation::{
await_status, await_subscription_response, get_json_request, get_state,
perform_trusted_operation,
},
Cli, CliResult, CliResultOk, SR25519_KEY_TYPE,
};
use codec::Decode;
Expand All @@ -35,7 +38,7 @@ use itp_stf_primitives::{
};
use itp_types::{
AccountInfo, Balance, ShardIdentifier, TrustedOperationStatus,
TrustedOperationStatus::{InSidechainBlock, Submitted},
TrustedOperationStatus::InSidechainBlock,
};
use log::*;
use rand::Rng;
Expand Down Expand Up @@ -337,15 +340,22 @@ fn wait_for_top_confirmation(
) -> BenchmarkTransaction {
let started = Instant::now();

let submitted = wait_until(&client.receiver, is_submitted);
// the first response of `submitAndWatch` is just the plain top hash
let submitted = match await_subscription_response(&client.receiver) {
Ok(hash) => Some((hash, Instant::now())),
Err(e) => {
error!("recv error: {e:?}");
None
},
};

let confirmed = if wait_for_sidechain_block {
// We wait for the transaction hash that actually matches the submitted hash
loop {
let transaction_information = wait_until(&client.receiver, is_sidechain_block);
if let Some((hash, _)) = transaction_information {
let transaction_information = await_status(&client.receiver, is_sidechain_block).ok();
if let Some((hash, _status)) = transaction_information {
if hash == submitted.unwrap().0 {
break transaction_information
break Some((hash, Instant::now()))
}
}
}
Expand All @@ -364,10 +374,6 @@ fn wait_for_top_confirmation(
}
}

fn is_submitted(s: TrustedOperationStatus) -> bool {
matches!(s, Submitted)
}

fn is_sidechain_block(s: TrustedOperationStatus) -> bool {
matches!(s, InSidechainBlock(_))
}
Expand Down
12 changes: 9 additions & 3 deletions cli/src/evm/commands/evm_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_evm_nonce, get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use ita_stf::{Index, TrustedCall, TrustedGetter};
Expand All @@ -31,6 +31,7 @@ use itp_types::AccountId;
use log::*;
use sp_core::{crypto::Ss58Codec, Pair, H160, U256};
use std::{boxed::Box, vec::Vec};

#[derive(Parser)]
pub struct EvmCallCommands {
/// Sender's incognito AccountId in ss58check format, mnemonic or hex seed
Expand Down Expand Up @@ -81,7 +82,12 @@ impl EvmCallCommands {
)
.sign(&KeyPair::Sr25519(Box::new(sender)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &function_call)
.map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &function_call).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &function_call)
.map(|_| CliResultOk::None)?)
}
}
}
9 changes: 7 additions & 2 deletions cli/src/evm/commands/evm_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_evm_nonce, get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use ita_stf::{evm_helpers::evm_create_address, Index, TrustedCall, TrustedGetter};
Expand All @@ -33,6 +33,7 @@ use pallet_evm::{AddressMapping, HashedAddressMapping};
use sp_core::{crypto::Ss58Codec, Pair, H160, U256};
use sp_runtime::traits::BlakeTwo256;
use std::vec::Vec;

#[derive(Parser)]
pub struct EvmCreateCommands {
/// Sender's incognito AccountId in ss58check format, mnemonic or hex seed
Expand Down Expand Up @@ -79,7 +80,11 @@ impl EvmCreateCommands {
.sign(&from.into(), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);

perform_trusted_operation::<()>(cli, trusted_args, &top)?;
if trusted_args.direct {
send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?;
} else {
perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?;
}

let execution_address = evm_create_address(sender_evm_acc, evm_account_nonce);
info!("trusted call evm_create executed");
Expand Down
9 changes: 8 additions & 1 deletion cli/src/guess_the_number/commands/guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
Cli, CliResult, CliResultOk,
};

use crate::trusted_operation::send_direct_request;
use ita_stf::{
guess_the_number::GuessTheNumberTrustedCall, Getter, Index, TrustedCall, TrustedCallSigned,
};
Expand Down Expand Up @@ -55,6 +56,12 @@ impl GuessCommand {
)
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
9 changes: 8 additions & 1 deletion cli/src/guess_the_number/commands/push_by_one_day.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use crate::{
Cli, CliResult, CliResultOk,
};

use crate::trusted_operation::send_direct_request;
use ita_stf::{
guess_the_number::GuessTheNumberTrustedCall, Getter, Index, TrustedCall, TrustedCallSigned,
};
Expand Down Expand Up @@ -53,6 +54,12 @@ impl PushByOneDayCommand {
)
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
10 changes: 8 additions & 2 deletions cli/src/guess_the_number/commands/set_winnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use ita_parentchain_interface::integritee::Balance;
Expand Down Expand Up @@ -59,6 +59,12 @@ impl SetWinningsCommand {
)
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
10 changes: 8 additions & 2 deletions cli/src/trusted_base_cli/commands/set_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use ita_parentchain_interface::integritee::Balance;
Expand Down Expand Up @@ -59,6 +59,12 @@ impl SetBalanceCommand {
)
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
13 changes: 8 additions & 5 deletions cli/src/trusted_base_cli/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_accountid_from_str, get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use base58::ToBase58;
Expand Down Expand Up @@ -65,9 +65,12 @@ impl TransferCommand {
TrustedCall::balance_transfer(from.public().into(), to, self.amount)
.sign(&KeyPair::Sr25519(Box::new(from)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
let res =
perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?;
info!("trusted call transfer executed");
Ok(res)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
11 changes: 9 additions & 2 deletions cli/src/trusted_base_cli/commands/unshield_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
get_layer_two_nonce,
trusted_cli::TrustedCli,
trusted_command_utils::{get_accountid_from_str, get_identifiers, get_pair_from_str},
trusted_operation::perform_trusted_operation,
trusted_operation::{perform_trusted_operation, send_direct_request},
Cli, CliResult, CliResultOk,
};
use ita_parentchain_interface::integritee::Balance;
Expand All @@ -31,6 +31,7 @@ use itp_stf_primitives::{
use log::*;
use sp_core::{crypto::Ss58Codec, Pair};
use std::boxed::Box;

#[derive(Parser)]
pub struct UnshieldFundsCommand {
/// Sender's incognito AccountId in ss58check format, mnemonic or hex seed
Expand Down Expand Up @@ -63,6 +64,12 @@ impl UnshieldFundsCommand {
TrustedCall::balance_unshield(from.public().into(), to, self.amount, shard)
.sign(&KeyPair::Sr25519(Box::new(from)), nonce, &mrenclave, &shard)
.into_trusted_operation(trusted_args.direct);
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top).map(|_| CliResultOk::None)?)

if trusted_args.direct {
Ok(send_direct_request(cli, trusted_args, &top).map(|_| CliResultOk::None)?)
} else {
Ok(perform_trusted_operation::<()>(cli, trusted_args, &top)
.map(|_| CliResultOk::None)?)
}
}
}
Loading
Loading