Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
4689acf
Shielding parentchain transfers (#1378)
coax1d Nov 15, 2023
4e4de90
Ab/shield from shard vault (#1497)
brenzi Nov 20, 2023
9672c7e
expose shard and shard vault rpc call (#1498)
brenzi Nov 20, 2023
922e873
[CI] test shielding/unshielding using shard vault (#1499)
brenzi Nov 20, 2023
d2db3e0
fix unresolved imports
m-yahya Nov 22, 2023
636ed10
import String
m-yahya Nov 22, 2023
1eeef4d
reorder imports
m-yahya Nov 22, 2023
a07aad4
fix path
m-yahya Nov 22, 2023
06d312d
fix path
m-yahya Nov 22, 2023
690fe70
comment orders dir path
m-yahya Nov 22, 2023
25ef717
remove comment
m-yahya Nov 23, 2023
882e394
Clean up cargo dependencies (#1503)
Kailai-Wang Nov 28, 2023
b8c6dc6
TargetA shielding unshielding sidechain by event (#1502)
brenzi Nov 29, 2023
60ad5cf
run tests on ubuntu-latest
m-yahya Nov 29, 2023
60ef825
Specify return type in `perform_trusted_operation` (#1500)
kziemianek Nov 30, 2023
4625871
run tests on self-hosted runner
m-yahya Nov 30, 2023
597c787
Fix OOM error in large parentchain syncs with sidechain feature. (#1493)
clangenb Nov 30, 2023
5cb95fe
bump version 0.12.1
brenzi Nov 30, 2023
a36ae4b
support json-rpc request string id (#1512)
kziemianek Dec 1, 2023
642aece
fix matrix host
m-yahya Dec 1, 2023
e40355f
Return encoded extrinsics without padding (#1505)
Kailai-Wang Dec 4, 2023
66223ce
ensure extrinsic success for enclave RA registration and fix #1515 (#…
brenzi Dec 6, 2023
88bf275
rename scripts
m-yahya Dec 7, 2023
b70c116
fix file name
m-yahya Dec 7, 2023
8a3ea6e
skip indirect invocations for initial sync of integritee parentchain …
brenzi Dec 8, 2023
3d31fa7
use envsubst
m-yahya Dec 9, 2023
3c13d36
remove test for BEST-Energy
m-yahya Dec 12, 2023
5f82ff5
automatically init shard if primary worker and no shard exists onchai…
brenzi Dec 13, 2023
c76c688
Hopefully fix of the service test
mosonyi Dec 15, 2023
af4080e
rename test
m-yahya Dec 15, 2023
c5d61cc
peer discovery by shard status with flexible url prefix (#1532)
brenzi Dec 17, 2023
9aa5d60
fix comment
m-yahya Dec 18, 2023
ea55416
comment enclave test
m-yahya Dec 18, 2023
b7c72bb
custom dependencies on parentchain runtimes to decode L1 Events (#1528)
brenzi Dec 21, 2023
78b1356
tiny mods to ease testing and log readability (#1549)
brenzi Dec 21, 2023
7e91475
Ab/fix light client provisioning and unshielding (#1541)
brenzi Dec 21, 2023
7ff60be
got rid of runtime dependencies (#1550)
brenzi Dec 21, 2023
455c3b7
cosmetics (#1551)
brenzi Dec 26, 2023
b85cabb
more robust sidechain block import logic (#1558)
brenzi Dec 29, 2023
c640ddc
make rococo relaychain work as shielding target (#1546)
brenzi Jan 10, 2024
061aff2
propagate parentchain(s) timestamps (#1572)
brenzi Jan 15, 2024
5df0a13
fast-sync targetA/B (#1573)
brenzi Jan 17, 2024
17aae85
add comment
m-yahya Jan 23, 2024
6aa384d
dummy commit to start CI tests
m-yahya Jan 23, 2024
95681ea
Merge tag 'v0.12.11' into my/fix-merged-conflicts
m-yahya Feb 12, 2024
9b840f0
update cargo lock
m-yahya Feb 12, 2024
10f98b4
fix clippy error
m-yahya Feb 12, 2024
f8995bf
update with upstream
m-yahya Feb 12, 2024
05cf25d
update toml_datetime
m-yahya Feb 12, 2024
d1ce9a1
manually set toml_datetime to 0.6.3
m-yahya Feb 12, 2024
0d4734b
update lock files with upstream
m-yahya Feb 12, 2024
f7d5069
update toml_datetime with correct command
m-yahya Feb 12, 2024
6c7c29c
specify the taplo version
m-yahya Feb 14, 2024
297674b
add missing dependencies
m-yahya Feb 14, 2024
11f0aaa
fix args, type mismatches, and inference error
m-yahya Feb 14, 2024
0249a18
fix unreachable pattern
m-yahya Feb 15, 2024
9f10430
fix mismatched types
m-yahya Feb 15, 2024
ebe771f
fix decode response error
m-yahya Feb 21, 2024
487c01a
comment EVM test
m-yahya Feb 21, 2024
fb3c623
test gh runner
m-yahya Apr 3, 2024
2654bac
comment teeracle test
m-yahya Apr 4, 2024
4fdb5e5
comment teeracle tests
m-yahya Apr 4, 2024
e83f47d
comment teeracle test
m-yahya Apr 4, 2024
a7c12af
test commit
m-yahya Apr 4, 2024
8f8c35f
test commit
m-yahya Apr 24, 2024
1a30c25
comment Teeracle test
m-yahya Apr 24, 2024
a5af265
comment teeracle test
m-yahya Apr 24, 2024
5e98531
comment teeracle release
m-yahya Apr 25, 2024
8ae1066
comment tests
m-yahya Apr 25, 2024
1d1f453
Update build_and_test.yml
muhammadumairsabir Apr 26, 2024
355ad4f
Update build_and_test.yml
muhammadumairsabir Apr 26, 2024
c82f277
Update build_and_test.yml
muhammadumairsabir May 28, 2024
9455db5
remove retry option
m-yahya Jul 31, 2024
ac07d62
use actions v3
m-yahya Jul 31, 2024
d98153f
update CI with upstream and comment EVM and Teeracle tests
m-yahya Jul 31, 2024
3734a61
add debug info and use actions v4
m-yahya Jul 31, 2024
3a413d3
use artifact actions v4
m-yahya Jul 31, 2024
a18f4bd
use actions v3 and comment benchmark test
m-yahya Aug 1, 2024
6c5c68f
comment M6, M8, M6 tests
m-yahya Aug 1, 2024
b9c6957
run benchmark with self-hosted runner
m-yahya Aug 1, 2024
733f461
use test-runner-sgx
m-yahya Aug 1, 2024
46bc615
add steps to upload worker artifacts
m-yahya Aug 1, 2024
04b0736
update download worker artifacts
m-yahya Aug 1, 2024
398c718
update with the upstream
m-yahya Aug 1, 2024
8e574ff
fix artifact not found error
m-yahya Aug 1, 2024
f6539d5
run build test on self-hosted runner
m-yahya Aug 1, 2024
27187f1
fix artifact not found
m-yahya Aug 1, 2024
15d0865
update to fix artifact not found
m-yahya Aug 1, 2024
28d3ab0
fix artifacts not found
m-yahya Aug 1, 2024
e5c3f73
fix artifact not found error
m-yahya Aug 1, 2024
fba497f
fix artifact not found
m-yahya Aug 1, 2024
6391a2b
comment download sidechain image
m-yahya Aug 2, 2024
ac8aac3
comment download worker image
m-yahya Aug 2, 2024
46ff609
update with the upstream
m-yahya Aug 2, 2024
e772ec6
update to fix artifact not found error
m-yahya Aug 2, 2024
26eac61
uncomment M6 test
m-yahya Aug 2, 2024
20e3527
uncomment M6 offchain-worker
m-yahya Aug 2, 2024
0b61872
uncomment Release Build of teeracle
m-yahya Aug 2, 2024
a8fc453
add tests
m-yahya Aug 2, 2024
c68f6b6
runs on ubuntu-latest
m-yahya Aug 2, 2024
8437042
use self-hosted to trigger expected checks
m-yahya Aug 2, 2024
9bc265d
update to use ubuntu-latest
m-yahya Aug 2, 2024
9f75a13
update to use ubuntu-latest
m-yahya Aug 2, 2024
fb479c2
run integration-tests on ubuntu-latest
m-yahya Aug 2, 2024
d295fcd
use matrix.host
m-yahya Aug 2, 2024
b0fdc0b
run release-build on integritee-builder-sgx
m-yahya Aug 2, 2024
992f4f7
run M6 on ubuntu-latest
m-yahya Aug 2, 2024
40a2f4d
add host for BestEnergy test
m-yahya Aug 2, 2024
d73e296
run BestEnergy on ubuntu-latest
m-yahya Aug 2, 2024
1c1bacc
update actions version
m-yahya Aug 2, 2024
6cc3d06
fix artifacts not found error
m-yahya Aug 2, 2024
4ace537
correct name for download sidechain image
m-yahya Aug 2, 2024
ec771ec
add M6 test
m-yahya Aug 2, 2024
76a9a9b
use test-runner-sgx
m-yahya Aug 2, 2024
527f98e
remove test yml
m-yahya Aug 2, 2024
558a38f
remove diff file
m-yahya Aug 2, 2024
44b1c6d
use selft hosted
m-yahya Aug 3, 2024
f2b7b2c
use ubuntu latest
m-yahya Aug 3, 2024
4b6ad71
update with upstream
m-yahya Aug 3, 2024
8e1fefd
Merge branch 'my/fix-merged-conflicts' of https://github.com/olisyste…
m-yahya Aug 3, 2024
642946a
use ubuntu latest
m-yahya Aug 3, 2024
d816ba0
use artifact v4 for cli client
m-yahya Aug 3, 2024
2dd4d08
uncomment tests
m-yahya Aug 3, 2024
b95d613
comment script
m-yahya Aug 3, 2024
bc7dfa0
use SW
m-yahya Aug 3, 2024
8c77b9c
add energy market demo
m-yahya Aug 3, 2024
3e316c5
comment tests
m-yahya Aug 3, 2024
dfc8ef4
manually add worker node 1
m-yahya Aug 3, 2024
cc247bd
comment demo
m-yahya Aug 3, 2024
d9d70c4
add tests without demo
m-yahya Aug 3, 2024
c92f8b9
run on ubuntu-latest
m-yahya Aug 3, 2024
5ccde13
run with HW
m-yahya Aug 3, 2024
6f23768
remove bin output files
m-yahya Aug 5, 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
Prev Previous commit
Next Next commit
TargetA shielding unshielding sidechain by event (integritee-network#…
…1502)

* enable target_a and _b syncing for sidechain mode and prepare new demo script. syncing target_a happening

* add shard vault proxy account on target A/B as well. derivation is deterministic, so the vault account is the same on all parentchains

* prepare event listener on target A and fix demoscript

* remove old enclave_bridge unshield call from trusted_call

* abstracting parentchain effect opaque_calls. stf can send to any parentchain. (only integritee implemented for now)

* sending stf extrinsics to all parentchains now

* WIP: triggering block import of target_a and b upon sidechain on_slot

* refactored aura to trigger target_a and target_b import

* shielding from target_a worked

* demo passes first and second rungit add -u!

* log cosmetics

* generic event display (fails). log cosmetics

* hack the fees. and more pimps

* recorded demo with this

* fixed cargo test

* clippy

* fixed enclave tests

* cleanup

* fix CI

* CI: introduce fee tolerance when assering balances

* fix evm tests

* fix

* clippy with test flag

* fix demo_sidechain with fee tolerance

* CI fixes

* review remarks fixed
  • Loading branch information
brenzi authored Nov 29, 2023
commit b8c6dc6f950eaba47f6d33cd80cff1061438b9a4
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2839,6 +2839,7 @@ dependencies = [
"parse_duration",
"primitive-types",
"prometheus",
"regex 1.9.5",
"scale-info",
"serde 1.0.188",
"serde_derive 1.0.188",
Expand Down Expand Up @@ -3892,6 +3893,7 @@ dependencies = [
"itp-time-utils",
"itp-top-pool-author",
"itp-types",
"itp-utils",
"its-block-composer",
"its-block-verification",
"its-consensus-common",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ where
.filter(|&event| event.to == *vault_account)
.try_for_each(|event| {
info!("found transfer_event to vault account: {}", event);
//call = IndirectCall::ShieldFunds(ShieldFundsArgs{ })
//debug!("shielding from Integritee suppressed");
Self::shield_funds(executor, &event.from, event.amount)
//Err(ParentchainError::FunctionalityDisabled)
})
.map_err(|_| ParentchainError::ShieldFundsFailure)?;
}
Expand Down
1 change: 1 addition & 0 deletions app-libs/parentchain-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
extern crate sgx_tstd as std;

use codec::Decode;

pub mod indirect_calls;
pub mod integritee;
pub mod target_a;
Expand Down
51 changes: 44 additions & 7 deletions app-libs/parentchain-interface/src/target_a/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,64 @@

*/

use codec::Encode;
pub use ita_sgx_runtime::{Balance, Index};

use ita_stf::TrustedCallSigned;
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use itc_parentchain_indirect_calls_executor::error::Error;
use itp_stf_primitives::traits::IndirectExecutor;
use itp_types::parentchain::{AccountId, FilterEvents, HandleParentchainEvents};
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_types::parentchain::{AccountId, FilterEvents, HandleParentchainEvents, ParentchainError};
use itp_utils::hex::hex_encode;
use log::*;

pub struct ParentchainEventHandler {}

impl ParentchainEventHandler {
fn shield_funds<Executor: IndirectExecutor<TrustedCallSigned, Error>>(
executor: &Executor,
account: &AccountId,
amount: Balance,
) -> Result<(), Error> {
trace!("[TargetA] shielding for {:?} amount {}", account, amount,);
let shard = executor.get_default_shard();
let trusted_call =
TrustedCall::balance_shield(executor.get_enclave_account()?, account.clone(), amount);
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?;
let trusted_operation =
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call);

let encrypted_trusted_call = executor.encrypt(&trusted_operation.encode())?;
executor.submit_trusted_call(shard, encrypted_trusted_call);

Ok(())
}
}

impl<Executor> HandleParentchainEvents<Executor, TrustedCallSigned, Error>
for ParentchainEventHandler
where
Executor: IndirectExecutor<TrustedCallSigned, Error>,
{
fn handle_events(
_executor: &Executor,
_events: impl FilterEvents,
_vault_account: &AccountId,
executor: &Executor,
events: impl FilterEvents,
vault_account: &AccountId,
) -> Result<(), Error> {
debug!("not handling any events for target A");
let filter_events = events.get_transfer_events();
trace!(
"[TargetA] filtering transfer events to shard vault account: {}",
hex_encode(vault_account.encode().as_slice())
);
if let Ok(events) = filter_events {
events
.iter()
.filter(|&event| event.to == *vault_account)
.try_for_each(|event| {
std::println!("⣿TargetA⣿ 🛡 found transfer event to shard vault account: {} will shield to {}", event.amount, hex_encode(event.from.encode().as_ref()));
Self::shield_funds(executor, &event.from, event.amount)
})
.map_err(|_| ParentchainError::ShieldFundsFailure)?;
}
Ok(())
}
}
17 changes: 10 additions & 7 deletions app-libs/parentchain-interface/src/target_a/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use itc_parentchain_indirect_calls_executor::{
};
use itp_node_api::metadata::pallet_balances::BalancesCallIndexes;
use itp_stf_primitives::traits::IndirectExecutor;
use log::trace;
use log::{debug, trace};

/// The default indirect call (extrinsic-triggered) of the Target-A-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
Expand All @@ -48,11 +48,16 @@ pub enum IndirectCall {
impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
IndirectDispatch<Executor, TrustedCallSigned> for IndirectCall
{
fn dispatch(&self, executor: &Executor) -> Result<()> {
fn dispatch(&self, _executor: &Executor) -> Result<()> {
debug!("shielding from TargetA extrinsic to Alice suppressed");
/*
trace!("dispatching indirect call {:?}", self);
match self {
IndirectCall::TransferToAliceShieldsFunds(args) => args.dispatch(executor),
}

*/
Ok(())
}
}

Expand Down Expand Up @@ -89,19 +94,17 @@ where
};
let index = xt.call_index;
let call_args = &mut &xt.call_args[..];
log::trace!("[TransferToAliceShieldsFundsFilter] attempting to execute indirect call with index {:?}", index);
trace!("[TransferToAliceShieldsFundsFilter] attempting to execute indirect call with index {:?}", index);
if index == metadata.transfer_call_indexes().ok()?
|| index == metadata.transfer_keep_alive_call_indexes().ok()?
|| index == metadata.transfer_allow_death_call_indexes().ok()?
{
log::debug!(
"found `transfer` or `transfer_allow_death` or `transfer_keep_alive` call."
);
debug!("found `transfer` or `transfer_allow_death` or `transfer_keep_alive` call.");
let args = decode_and_log_error::<TransferToAliceShieldsFundsArgs>(call_args)?;
if args.destination == ALICE_ACCOUNT_ID.into() {
Some(IndirectCall::TransferToAliceShieldsFunds(args))
} else {
log::debug!("Parentchain transfer was not for Alice; ignoring...");
debug!("Parentchain transfer extrinsic was not for Alice; ignoring...");
// No need to put it into the top pool if it isn't executed in the first place.
None
}
Expand Down
2 changes: 1 addition & 1 deletion app-libs/sgx-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub use frame_support::{
StorageValue,
};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_parentchain::Call as ParentchainCall;
pub use pallet_parentchain::Call as ParentchainPalletCall;
pub use pallet_timestamp::Call as TimestampCall;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
Expand Down
2 changes: 1 addition & 1 deletion app-libs/stf/src/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ExecuteGetter for TrustedGetterSigned {
let info = System::account(&who);
debug!("TrustedGetter free_balance");
debug!("AccountInfo for {} is {:?}", account_id_to_string(&who), info);
debug!("Account free balance is {}", info.data.free);
std::println!("⣿STF⣿ 🔍 TrustedGetter query: free balance for ⣿⣿⣿ is ⣿⣿⣿",);
Some(info.data.free.encode())
},
TrustedGetter::reserved_balance(who) => {
Expand Down
3 changes: 3 additions & 0 deletions app-libs/stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ pub mod test_genesis;
pub mod trusted_call;

pub(crate) const ENCLAVE_ACCOUNT_KEY: &str = "Enclave_Account_Key";

// fixme: this if a temporary hack only
pub const STF_TX_FEE: Balance = 100000000;
7 changes: 2 additions & 5 deletions app-libs/stf/src/stf_sgx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ use itp_stf_interface::{
};
use itp_stf_primitives::{error::StfError, traits::TrustedCallVerification};
use itp_storage::storage_value_key;
use itp_types::{
parentchain::{AccountId, ParentchainId},
OpaqueCall,
};
use itp_types::parentchain::{AccountId, ParentchainCall, ParentchainId};
use itp_utils::stringify::account_id_to_string;
use log::*;
use sp_runtime::traits::StaticLookup;
Expand Down Expand Up @@ -147,7 +144,7 @@ where
fn execute_call(
state: &mut State,
call: TCS,
calls: &mut Vec<OpaqueCall>,
calls: &mut Vec<ParentchainCall>,
node_metadata_repo: Arc<NodeMetadataRepository>,
) -> Result<(), Self::Error> {
state.execute_with(|| call.execute(calls, node_metadata_repo))
Expand Down
6 changes: 3 additions & 3 deletions app-libs/stf/src/test_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ const ENDOWED_SEED: Seed = *b"12345678901234567890123456789012";
const SECOND_ENDOWED_SEED: Seed = *b"22345678901234567890123456789012";
const UNENDOWED_SEED: Seed = *b"92345678901234567890123456789012";

const ALICE_FUNDS: Balance = 1000000000000000;
pub const ENDOWED_ACC_FUNDS: Balance = 2000;
pub const SECOND_ENDOWED_ACC_FUNDS: Balance = 1000;
const ALICE_FUNDS: Balance = 10_000_000_000_000_000;
pub const ENDOWED_ACC_FUNDS: Balance = 2_000_000_000_000;
pub const SECOND_ENDOWED_ACC_FUNDS: Balance = 1_000_000_000_000;

pub fn endowed_account() -> ed25519::Pair {
ed25519::Pair::from_seed(&ENDOWED_SEED)
Expand Down
96 changes: 68 additions & 28 deletions app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::vec::Vec;
#[cfg(feature = "evm")]
use crate::evm_helpers::{create_code_hash, evm_create2_address, evm_create_address};
use crate::{
helpers::{ensure_enclave_signer_account, get_storage_by_key_hash},
helpers::{enclave_signer_account, ensure_enclave_signer_account, get_storage_by_key_hash},
Getter,
};
use codec::{Compact, Decode, Encode};
Expand All @@ -44,7 +44,10 @@ use itp_stf_primitives::{
traits::{TrustedCallSigning, TrustedCallVerification},
types::{AccountId, KeyPair, ShardIdentifier, Signature, TrustedOperation},
};
use itp_types::{parentchain::ProxyType, Address, OpaqueCall};
use itp_types::{
parentchain::{ParentchainCall, ProxyType},
Address, OpaqueCall,
};
use itp_utils::stringify::account_id_to_string;
use log::*;
use sp_core::{
Expand Down Expand Up @@ -214,7 +217,7 @@ where

fn execute(
self,
calls: &mut Vec<OpaqueCall>,
calls: &mut Vec<ParentchainCall>,
node_metadata_repo: Arc<NodeMetadataRepository>,
) -> Result<(), Self::Error> {
let sender = self.call.sender_account().clone();
Expand Down Expand Up @@ -259,12 +262,26 @@ where
},
TrustedCall::balance_transfer(from, to, value) => {
let origin = ita_sgx_runtime::RuntimeOrigin::signed(from.clone());
debug!(
"balance_transfer({}, {}, {})",
std::println!("⣿STF⣿ 🔄 balance_transfer from ⣿⣿⣿ to ⣿⣿⣿ amount ⣿⣿⣿");
// endow fee to enclave (self)
let fee_recipient: AccountId = enclave_signer_account();
// fixme: apply fees through standard frame process and tune it
let fee = crate::STF_TX_FEE;
info!(
"from {}, to {}, amount {}, fee {}",
account_id_to_string(&from),
account_id_to_string(&to),
value
value,
fee
);
ita_sgx_runtime::BalancesCall::<Runtime>::transfer {
dest: MultiAddress::Id(fee_recipient),
value: fee,
}
.dispatch_bypass_filter(origin.clone())
.map_err(|e| {
Self::Error::Dispatch(format!("Balance Transfer error: {:?}", e.error))
})?;
ita_sgx_runtime::BalancesCall::<Runtime>::transfer {
dest: MultiAddress::Id(to),
value,
Expand All @@ -276,28 +293,36 @@ where
Ok(())
},
TrustedCall::balance_unshield(account_incognito, beneficiary, value, shard) => {
debug!(
"balance_unshield({}, {}, {}, {})",
std::println!(
"⣿STF⣿ 🛡👐 balance_unshield from ⣿⣿⣿ to {}, amount {}",
account_id_to_string(&beneficiary),
value
);
// endow fee to enclave (self)
let fee_recipient: AccountId = enclave_signer_account();
// fixme: apply fees through standard frame process and tune it. has to be at least two L1 transfer's fees
let fee = crate::STF_TX_FEE * 3;

info!(
"balance_unshield(from (L2): {}, to (L1): {}, amount {} (+fee: {}), shard {})",
account_id_to_string(&account_incognito),
account_id_to_string(&beneficiary),
value,
fee,
shard
);
unshield_funds(account_incognito, value)?;

calls.push(OpaqueCall::from_tuple(&(
node_metadata_repo
.get_from_metadata(|m| m.unshield_funds_call_indexes())
.map_err(|_| StfError::InvalidMetadata)?
.map_err(|_| StfError::InvalidMetadata)?,
shard,
beneficiary.clone(),
value,
call_hash,
)));
// todo: the following is a placeholder dummy which will replace the above with #1257.
// the extrinsic will be sent and potentially deplete the vault at the current state which
// is nothing to worry about before we solve mentioned issue.
let origin = ita_sgx_runtime::RuntimeOrigin::signed(account_incognito.clone());
ita_sgx_runtime::BalancesCall::<Runtime>::transfer {
dest: MultiAddress::Id(fee_recipient),
value: fee,
}
.dispatch_bypass_filter(origin)
.map_err(|e| {
Self::Error::Dispatch(format!("Balance Unshielding error: {:?}", e.error))
})?;
burn_funds(account_incognito, value)?;

let vault_pubkey: [u8; 32] = get_storage_by_key_hash(SHARD_VAULT_KEY.into())
.ok_or_else(|| {
StfError::Dispatch("shard vault key hasn't been set".to_string())
Expand All @@ -320,7 +345,7 @@ where
None::<ProxyType>,
vault_transfer_call,
));
calls.push(proxy_call);
calls.push(ParentchainCall::TargetA(proxy_call));
Ok(())
},
TrustedCall::balance_shield(enclave_account, who, value) => {
Expand All @@ -329,15 +354,15 @@ where
shield_funds(who, value)?;

// Send proof of execution on chain.
calls.push(OpaqueCall::from_tuple(&(
calls.push(ParentchainCall::Integritee(OpaqueCall::from_tuple(&(
node_metadata_repo
.get_from_metadata(|m| m.publish_hash_call_indexes())
.map_err(|_| StfError::InvalidMetadata)?
.map_err(|_| StfError::InvalidMetadata)?,
call_hash,
Vec::<itp_types::H256>::new(),
b"shielded some funds!".to_vec(),
)));
))));
Ok(())
},
#[cfg(feature = "evm")]
Expand Down Expand Up @@ -476,7 +501,7 @@ where
}
}

fn unshield_funds(account: AccountId, amount: u128) -> Result<(), StfError> {
fn burn_funds(account: AccountId, amount: u128) -> Result<(), StfError> {
let account_info = System::account(&account);
if account_info.data.free < amount {
return Err(StfError::MissingFunds)
Expand All @@ -487,15 +512,30 @@ fn unshield_funds(account: AccountId, amount: u128) -> Result<(), StfError> {
new_free: account_info.data.free - amount,
}
.dispatch_bypass_filter(ita_sgx_runtime::RuntimeOrigin::root())
.map_err(|e| StfError::Dispatch(format!("Unshield funds error: {:?}", e.error)))?;
.map_err(|e| StfError::Dispatch(format!("Burn funds error: {:?}", e.error)))?;
Ok(())
}

fn shield_funds(account: AccountId, amount: u128) -> Result<(), StfError> {
//fixme: make fee configurable and send fee to vault account on L2
let fee = amount / 571; // approx 0.175%

// endow fee to enclave (self)
let fee_recipient: AccountId = enclave_signer_account();

let account_info = System::account(&fee_recipient);
ita_sgx_runtime::BalancesCall::<Runtime>::force_set_balance {
who: MultiAddress::Id(fee_recipient),
new_free: account_info.data.free + fee,
}
.dispatch_bypass_filter(ita_sgx_runtime::RuntimeOrigin::root())
.map_err(|e| StfError::Dispatch(format!("Shield funds error: {:?}", e.error)))?;

// endow shieding amount - fee to beneficiary
let account_info = System::account(&account);
ita_sgx_runtime::BalancesCall::<Runtime>::force_set_balance {
who: MultiAddress::Id(account),
new_free: account_info.data.free + amount,
new_free: account_info.data.free + amount - fee,
}
.dispatch_bypass_filter(ita_sgx_runtime::RuntimeOrigin::root())
.map_err(|e| StfError::Dispatch(format!("Shield funds error: {:?}", e.error)))?;
Expand Down
Loading