-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add note bloat and waste time TrustedCalls and cli (#1645)
* add note bloat and waste time TrusstedCalls and cli * bloating state and wasting time works * fix ringbuffer size tracking * clippy * fix tests
- Loading branch information
Showing
12 changed files
with
300 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems 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. | ||
*/ | ||
|
||
use crate::{ | ||
get_layer_two_nonce, | ||
trusted_cli::TrustedCli, | ||
trusted_command_utils::{get_identifiers, get_pair_from_str}, | ||
trusted_operation::{perform_trusted_operation, send_direct_request}, | ||
Cli, CliResult, CliResultOk, | ||
}; | ||
use ita_stf::{Getter, Index, TrustedCall, TrustedCallSigned}; | ||
use itp_stf_primitives::{ | ||
traits::TrustedCallSigning, | ||
types::{KeyPair, TrustedOperation}, | ||
}; | ||
use log::*; | ||
use sp_core::{crypto::Ss58Codec, Pair}; | ||
use std::boxed::Box; | ||
|
||
#[derive(Parser)] | ||
pub struct NoteBloatCommand { | ||
/// subject's AccountId in ss58check format. must have maintainer privilege | ||
account: String, | ||
|
||
/// kilobytes of notes to store | ||
kilobytes: u32, | ||
} | ||
|
||
impl NoteBloatCommand { | ||
pub(crate) fn run(&self, cli: &Cli, trusted_args: &TrustedCli) -> CliResult { | ||
let signer = get_pair_from_str(trusted_args, &self.account); | ||
info!("account ss58 is {}", signer.public().to_ss58check()); | ||
|
||
println!("send trusted call note-bloat({}kB)", self.kilobytes); | ||
|
||
let (mrenclave, shard) = get_identifiers(trusted_args); | ||
let nonce = get_layer_two_nonce!(signer, cli, trusted_args); | ||
let top: TrustedOperation<TrustedCallSigned, Getter> = | ||
TrustedCall::note_bloat(signer.public().into(), self.kilobytes) | ||
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard) | ||
.into_trusted_operation(trusted_args.direct); | ||
|
||
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)?) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems 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. | ||
*/ | ||
|
||
use crate::{ | ||
get_layer_two_nonce, | ||
trusted_cli::TrustedCli, | ||
trusted_command_utils::{get_identifiers, get_pair_from_str}, | ||
trusted_operation::{perform_trusted_operation, send_direct_request}, | ||
Cli, CliResult, CliResultOk, | ||
}; | ||
use ita_stf::{Getter, Index, TrustedCall, TrustedCallSigned}; | ||
use itp_stf_primitives::{ | ||
traits::TrustedCallSigning, | ||
types::{KeyPair, TrustedOperation}, | ||
}; | ||
use log::*; | ||
use sp_core::{crypto::Ss58Codec, Pair}; | ||
use std::boxed::Box; | ||
|
||
#[derive(Parser)] | ||
pub struct WasteTimeCommand { | ||
/// subject's AccountId in ss58check format. must have maintainer privilege | ||
account: String, | ||
|
||
/// milliseconds to waste | ||
millis: u32, | ||
} | ||
|
||
impl WasteTimeCommand { | ||
pub(crate) fn run(&self, cli: &Cli, trusted_args: &TrustedCli) -> CliResult { | ||
let signer = get_pair_from_str(trusted_args, &self.account); | ||
info!("account ss58 is {}", signer.public().to_ss58check()); | ||
|
||
println!("send trusted call waste-time({}ms)", self.millis); | ||
|
||
let (mrenclave, shard) = get_identifiers(trusted_args); | ||
let nonce = get_layer_two_nonce!(signer, cli, trusted_args); | ||
let top: TrustedOperation<TrustedCallSigned, Getter> = | ||
TrustedCall::waste_time(signer.public().into(), self.millis) | ||
.sign(&KeyPair::Sr25519(Box::new(signer)), nonce, &mrenclave, &shard) | ||
.into_trusted_operation(trusted_args.direct); | ||
|
||
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)?) | ||
} | ||
} | ||
} |
Oops, something went wrong.