Skip to content

Commit

Permalink
skip shard vault creation if teeracle or OCW (#1680)
Browse files Browse the repository at this point in the history
* skip shard vault creation if teeracle

* handle enclabe bridge shielding separately to fix OCW CI

* fix fees for shielding
  • Loading branch information
brenzi authored Jan 31, 2025
1 parent 5d4a8b6 commit e788f3c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use itp_stf_primitives::{
traits::IndirectExecutor,
types::{AccountId, TrustedOperation},
};
use itp_types::{parentchain::ParentchainId, Balance, ShardIdentifier};
use itp_types::{Balance, ShardIdentifier};
use log::{debug, info};
use std::vec::Vec;

Expand All @@ -41,19 +41,18 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
IndirectDispatch<Executor, TrustedCallSigned> for ShieldFundsArgs
{
fn dispatch(&self, executor: &Executor) -> Result<()> {
info!("Found ShieldFunds extrinsic in block: \nAccount Encrypted {:?} \nAmount: {} \nShard: {}",
info!("Found EnclaveBridge::ShieldFunds extrinsic in block: \nAccount Encrypted {:?} \nAmount: {} \nShard: {}",
self.account_encrypted, self.amount, bs58::encode(self.shard.encode()).into_string());

debug!("decrypt the account id");
let account_vec = executor.decrypt(&self.account_encrypted)?;
let account = AccountId::decode(&mut account_vec.as_slice())?;

let enclave_account_id = executor.get_enclave_account()?;
let trusted_call = TrustedCall::balance_shield(
let trusted_call = TrustedCall::balance_shield_through_enclave_bridge_pallet(
enclave_account_id,
account,
self.amount,
ParentchainId::Integritee,
);
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &self.shard)?;
let trusted_operation =
Expand Down
24 changes: 24 additions & 0 deletions app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum TrustedCall {
balance_unshield(AccountId, AccountId, Balance, ShardIdentifier) = 3, // (AccountIncognito, BeneficiaryPublicAccount, Amount, Shard)
balance_shield(AccountId, AccountId, Balance, ParentchainId) = 4, // (Root, AccountIncognito, Amount, origin parentchain)
balance_transfer_with_note(AccountId, AccountId, Balance, Vec<u8>) = 5,
balance_shield_through_enclave_bridge_pallet(AccountId, AccountId, Balance) = 6, // (Root, AccountIncognito, Amount)
note_bloat(AccountId, u32) = 10,
waste_time(AccountId, u32) = 11,
send_note(AccountId, AccountId, Vec<u8>) = 20,
Expand Down Expand Up @@ -136,6 +137,8 @@ impl TrustedCall {
Self::balance_unshield(sender_account, ..) => sender_account,
Self::balance_shield(sender_account, ..) => sender_account,
Self::balance_transfer_with_note(sender_account, ..) => sender_account,
Self::balance_shield_through_enclave_bridge_pallet(sender_account, ..) =>
sender_account,
Self::timestamp_set(sender_account, ..) => sender_account,
Self::send_note(sender_account, ..) => sender_account,
Self::add_session_proxy(sender_account, ..) => sender_account,
Expand Down Expand Up @@ -416,6 +419,26 @@ where
store_note(&enclave_account, self.call, vec![who])?;
Ok(())
},
TrustedCall::balance_shield_through_enclave_bridge_pallet(
enclave_account,
who,
value,
) => {
ensure_enclave_signer_account(&enclave_account)?;
debug!(
"balance_shield_through_enclave_bridge_pallet({}, {})",
account_id_to_string(&who),
value,
);
ensure!(
shard_vault().is_none(),
StfError::EnclaveBridgeShieldingDisabledIfVaultAssigned
);
std::println!("⣿STF⣿ 🛡 will shield to {}", account_id_to_string(&who));
shield_funds(&who, value)?;
store_note(&enclave_account, self.call, vec![who])?;
Ok(())
},
TrustedCall::timestamp_set(enclave_account, now, parentchain_id) => {
ensure_enclave_signer_account(&enclave_account)?;
debug!("timestamp_set({}, {:?})", now, parentchain_id);
Expand Down Expand Up @@ -678,6 +701,7 @@ fn get_fee_for(tc: &TrustedCallSigned) -> Balance {
TrustedCall::waste_time(..) => Balance::from(0u32),
TrustedCall::timestamp_set(..) => Balance::from(0u32),
TrustedCall::balance_shield(..) => Balance::from(0u32), //will be charged on recipient, elsewhere
TrustedCall::balance_shield_through_enclave_bridge_pallet(..) => Balance::from(0u32), //will be charged on recipient, elsewhere
#[cfg(any(feature = "test", test))]
TrustedCall::balance_set_balance(..) => Balance::from(0u32),
_ => one / crate::STF_TX_FEE_UNIT_DIVIDER,
Expand Down
13 changes: 6 additions & 7 deletions cli/demo_shielding_unshielding_multiworker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,14 @@ echo ""

SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

"${SCRIPT_DIR}"/demo_shielding_unshielding.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_1_URL}" -P "${WORKER_1_PORT}" -C "${CLIENT_BIN}" -t first
"${SCRIPT_DIR}"/demo_shielding_unshielding.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_2_URL}" -P "${WORKER_2_PORT}" -C "${CLIENT_BIN}" -t second

if [ "$FLAVOR_ID" = offchain-worker ]; then
"${SCRIPT_DIR}"/demo_shielding_unshielding.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_1_URL}" -P "${WORKER_1_PORT}" -C "${CLIENT_BIN}" -t first
"${SCRIPT_DIR}"/demo_shielding_unshielding.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_2_URL}" -P "${WORKER_2_PORT}" -C "${CLIENT_BIN}" -t second
echo "offchain-worker does not support shard vault shielding, therefore we skip those tests"
exit 0
else
"${SCRIPT_DIR}"/demo_shielding_unshielding_using_shard_vault.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_1_URL}" -P "${WORKER_1_PORT}" -C "${CLIENT_BIN}" -t first
"${SCRIPT_DIR}"/demo_shielding_unshielding_using_shard_vault.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_2_URL}" -P "${WORKER_2_PORT}" -C "${CLIENT_BIN}" -t second
echo "sidechain-worker does not support enclave bridge shielding, therefore we skip those tests"
fi

"${SCRIPT_DIR}"/demo_shielding_unshielding_using_shard_vault.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_1_URL}" -P "${WORKER_1_PORT}" -C "${CLIENT_BIN}" -t first
"${SCRIPT_DIR}"/demo_shielding_unshielding_using_shard_vault.sh -p "${INTEGRITEE_RPC_PORT}" -u "${INTEGRITEE_RPC_URL}" -V "${WORKER_2_URL}" -P "${WORKER_2_PORT}" -C "${CLIENT_BIN}" -t second

exit 0
1 change: 1 addition & 0 deletions core-primitives/stf-primitives/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ pub enum StfError {
ChangingShardVaultAccountNotAllowed,
WrongParentchainIdForShardVault,
NoShardVaultAssigned,
EnclaveBridgeShieldingDisabledIfVaultAssigned,
}
20 changes: 11 additions & 9 deletions service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,15 +734,17 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
None
};

init_provided_shard_vault(
shard,
&enclave,
integritee_rpc_api.clone(),
maybe_target_a_rpc_api.clone(),
maybe_target_b_rpc_api.clone(),
run_config.shielding_target,
we_are_primary_validateer,
);
if WorkerModeProvider::worker_mode() == WorkerMode::Sidechain {
init_provided_shard_vault(
shard,
&enclave,
integritee_rpc_api.clone(),
maybe_target_a_rpc_api.clone(),
maybe_target_b_rpc_api.clone(),
run_config.shielding_target,
we_are_primary_validateer,
);
}

// ------------------------------------------------------------------------
// Start prometheus metrics server.
Expand Down

0 comments on commit e788f3c

Please sign in to comment.