Skip to content

Commit

Permalink
implement public getter undistributed fees (#1681)
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi authored Jan 31, 2025
1 parent e788f3c commit 81e4437
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,7 @@ dependencies = [
"itp-hashing",
"itp-node-api",
"itp-node-api-metadata",
"itp-randomness",
"itp-sgx-externalities",
"itp-sgx-runtime-primitives",
"itp-stf-interface",
Expand Down
1 change: 1 addition & 0 deletions app-libs/stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ita-sgx-runtime = { default-features = false, path = "../sgx-runtime" }
itp-hashing = { default-features = false, path = "../../core-primitives/hashing" }
itp-node-api = { default-features = false, path = "../../core-primitives/node-api" }
itp-node-api-metadata = { default-features = false, path = "../../core-primitives/node-api/metadata" }
itp-randomness = { path = "../../core-primitives/randomness", default-features = false }
itp-sgx-externalities = { default-features = false, path = "../../core-primitives/substrate-sgx/externalities" }
itp-sgx-runtime-primitives = { default-features = false, path = "../../core-primitives/sgx-runtime-primitives" }
itp-stf-interface = { default-features = false, path = "../../core-primitives/stf-interface" }
Expand Down
26 changes: 25 additions & 1 deletion app-libs/stf/src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use ita_sgx_runtime::{
Balances, Notes, ParentchainIntegritee, ParentchainTargetA, ParentchainTargetB, Runtime,
SessionProxy, System,
};
use itp_randomness::{Randomness, SgxRandomness};
use itp_stf_interface::ExecuteGetter;
use itp_stf_primitives::{
traits::GetterAuthorization,
Expand All @@ -39,7 +40,10 @@ use crate::evm_helpers::{get_evm_account, get_evm_account_codes, get_evm_account

use crate::{
guess_the_number::{GuessTheNumberPublicGetter, GuessTheNumberTrustedGetter},
helpers::{shielding_target, shielding_target_genesis_hash, wrap_bytes},
helpers::{
enclave_signer_account, shielding_target, shielding_target_genesis_hash, wrap_bytes,
},
STF_TX_FEE_UNIT_DIVIDER,
};
use ita_parentchain_specs::MinimalChainSpec;
use itp_sgx_runtime_primitives::types::{Balance, Moment};
Expand Down Expand Up @@ -118,6 +122,7 @@ impl PoolTransactionValidation for Getter {
pub enum PublicGetter {
some_value = 0,
total_issuance = 1,
undistributed_fees = 2,
parentchains_info = 10,
note_buckets_info = 11,
guess_the_number(GuessTheNumberPublicGetter) = 50,
Expand Down Expand Up @@ -293,6 +298,25 @@ impl ExecuteGetter for PublicGetter {
match self {
PublicGetter::some_value => Some(42u32.encode()),
PublicGetter::total_issuance => Some(Balances::total_issuance().encode()),
PublicGetter::undistributed_fees => {
let pot: AccountId = enclave_signer_account();
let info = System::account(&pot);
debug!("PublicGetter undistributed_fees");
debug!("AccountInfo for {} is {:?}", account_id_to_string(&pot), info);
let fees = info.data.free;
// for privacy reasons, we add some noise to the fees.
// This avoids leaking the exact number and cost of recent TrustedCalls
let noise =
MinimalChainSpec::one_unit(shielding_target_genesis_hash().unwrap_or_default())
/ STF_TX_FEE_UNIT_DIVIDER
* Balance::from(SgxRandomness::random_u32(0, 10));
let noisy_fees = fees.saturating_sub(noise);
std::println!(
"⣿STF⣿ 🔍 PublicGetter query: undistributed fees at least {}",
noisy_fees
);
Some(noisy_fees.encode())
},
PublicGetter::parentchains_info => {
let integritee = ParentchainInfo {
id: ParentchainId::Integritee,
Expand Down
36 changes: 36 additions & 0 deletions cli/src/trusted_base_cli/commands/get_undistributed_fees.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
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.
*/
use crate::{
trusted_cli::TrustedCli, trusted_operation::perform_trusted_operation, Cli, CliResult,
CliResultOk,
};
use ita_stf::{Balance, Getter, PublicGetter, TrustedCallSigned};
use itp_stf_primitives::types::TrustedOperation;

#[derive(Parser)]
pub struct GetUndistributedFeesCommand {}

impl GetUndistributedFeesCommand {
pub(crate) fn run(&self, cli: &Cli, trusted_args: &TrustedCli) -> CliResult {
let top = TrustedOperation::<TrustedCallSigned, Getter>::get(Getter::public(
PublicGetter::undistributed_fees,
));
let fees: Balance = perform_trusted_operation(cli, trusted_args, &top).unwrap();
println!("{:?}", fees);
Ok(CliResultOk::Balance { balance: fees })
}
}
6 changes: 3 additions & 3 deletions cli/src/trusted_base_cli/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pub mod add_session_proxy;
pub mod balance;
pub mod get_fingerprint;
pub mod get_header;
pub mod get_note_buckets_info;
pub mod get_notes;
pub mod get_parentchains_info;
pub mod get_session_proxies;
pub mod get_shard;
pub mod get_shard_vault;
pub mod get_total_issuance;

pub mod add_session_proxy;
pub mod get_session_proxies;
pub mod get_undistributed_fees;
pub mod nonce;
pub mod note_bloat;
pub mod transfer;
Expand Down
7 changes: 6 additions & 1 deletion cli/src/trusted_base_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ use crate::{
get_parentchains_info::GetParentchainsInfoCommand,
get_session_proxies::GetSessionProxiesCommand, get_shard::GetShardCommand,
get_shard_vault::GetShardVaultCommand, get_total_issuance::GetTotalIssuanceCommand,
nonce::NonceCommand, note_bloat::NoteBloatCommand, transfer::TransferCommand,
get_undistributed_fees::GetUndistributedFeesCommand, nonce::NonceCommand,
note_bloat::NoteBloatCommand, transfer::TransferCommand,
unshield_funds::UnshieldFundsCommand, version::VersionCommand,
waste_time::WasteTimeCommand, watchdog::WatchdogCommand,
},
Expand Down Expand Up @@ -80,6 +81,9 @@ pub enum TrustedBaseCommand {
/// get total issuance of this shard's native token
GetTotalIssuance(GetTotalIssuanceCommand),

/// get a noisy amount of collected but undistributed fees
GetUndistributedFees(GetUndistributedFeesCommand),

/// get info for all parentchains' sync status
GetParentchainsInfo(GetParentchainsInfoCommand),

Expand Down Expand Up @@ -127,6 +131,7 @@ impl TrustedBaseCommand {
TrustedBaseCommand::GetShardVault(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::GetSidechainHeader(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::GetTotalIssuance(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::GetUndistributedFees(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::AddSessionProxy(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::GetSessionProxies(cmd) => cmd.run(cli, trusted_cli),
TrustedBaseCommand::NoteBloat(cmd) => cmd.run(cli, trusted_cli),
Expand Down
1 change: 1 addition & 0 deletions enclave-runtime/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ dependencies = [
"itp-hashing",
"itp-node-api",
"itp-node-api-metadata",
"itp-randomness",
"itp-sgx-externalities",
"itp-sgx-runtime-primitives",
"itp-stf-interface",
Expand Down

0 comments on commit 81e4437

Please sign in to comment.