Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ab37149
enable target_a and _b syncing for sidechain mode and prepare new dem…
brenzi Nov 23, 2023
2ae982d
add shard vault proxy account on target A/B as well. derivation is de…
brenzi Nov 23, 2023
d62b26d
prepare event listener on target A and fix demoscript
brenzi Nov 23, 2023
d9bff04
remove old enclave_bridge unshield call from trusted_call
brenzi Nov 23, 2023
e9c408c
abstracting parentchain effect opaque_calls. stf can send to any pare…
brenzi Nov 23, 2023
ff686b6
sending stf extrinsics to all parentchains now
brenzi Nov 24, 2023
ec5918e
WIP: triggering block import of target_a and b upon sidechain on_slot
brenzi Nov 24, 2023
42b10e7
refactored aura to trigger target_a and target_b import
brenzi Nov 25, 2023
2f12d4b
shielding from target_a worked
brenzi Nov 25, 2023
a62dc20
demo passes first and second rungit add -u!
brenzi Nov 25, 2023
3c5cafc
log cosmetics
brenzi Nov 26, 2023
72f2849
generic event display (fails). log cosmetics
brenzi Nov 27, 2023
30c1ef5
hack the fees. and more pimps
brenzi Nov 27, 2023
c46c67b
recorded demo with this
brenzi Nov 27, 2023
90cb372
fixed cargo test
brenzi Nov 28, 2023
6d97c2a
clippy
brenzi Nov 28, 2023
c47a9c5
fixed enclave tests
brenzi Nov 28, 2023
6eacfd7
cleanup
brenzi Nov 28, 2023
886af3b
Merge branch 'master' into ab/target-a-shielding-unshielding-sidechai…
brenzi Nov 28, 2023
b16439c
fix CI
brenzi Nov 28, 2023
2ea0472
CI: introduce fee tolerance when assering balances
brenzi Nov 28, 2023
13c20f3
fix evm tests
brenzi Nov 28, 2023
20b7468
fix
brenzi Nov 28, 2023
83ee1aa
clippy with test flag
brenzi Nov 28, 2023
39a3147
fix demo_sidechain with fee tolerance
brenzi Nov 28, 2023
a70685d
CI fixes
brenzi Nov 28, 2023
b75036e
review remarks fixed
brenzi Nov 29, 2023
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
fixed enclave tests
  • Loading branch information
brenzi committed Nov 28, 2023
commit c47a9c54724a8b350a9e24869614de2022702beb
6 changes: 1 addition & 5 deletions app-libs/parentchain-interface/src/integritee/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
fn dispatch(&self, executor: &Executor) -> Result<()> {
trace!("dispatching indirect call {:?}", self);
match self {
IndirectCall::ShieldFunds(_shieldfunds_args) => {
debug!("shielding from Integritee suppressed");
//shieldfunds_args.dispatch(executor)
Ok(())
},
IndirectCall::ShieldFunds(shieldfunds_args) => shieldfunds_args.dispatch(executor),
IndirectCall::Invoke(invoke_args) => invoke_args.dispatch(executor),
}
}
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;
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
35 changes: 14 additions & 21 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 Down Expand Up @@ -58,9 +58,6 @@ use sp_io::hashing::blake2_256;
use sp_runtime::{traits::Verify, MultiAddress, MultiSignature};
use std::{format, prelude::v1::*, sync::Arc};

// fixme: this if a temporary hack only
pub const TX_FEE: Balance = 100000000;

#[derive(Encode, Decode, Clone, Debug, PartialEq, Eq)]
#[allow(non_camel_case_types)]
pub enum TrustedCall {
Expand Down Expand Up @@ -266,12 +263,10 @@ where
TrustedCall::balance_transfer(from, to, value) => {
let origin = ita_sgx_runtime::RuntimeOrigin::signed(from.clone());
std::println!("⣿STF⣿ 🔄 balance_transfer from ⣿⣿⣿ to ⣿⣿⣿ amount ⣿⣿⣿");
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())
})?;
// endow fee to enclave (self)
let fee_recipient: AccountId = enclave_signer_account();
// fixme: apply fees through standard frame process and tune it
let fee = TX_FEE;
let fee = crate::STF_TX_FEE;
info!(
"from {}, to {}, amount {}, fee {}",
account_id_to_string(&from),
Expand All @@ -280,7 +275,7 @@ where
fee
);
ita_sgx_runtime::BalancesCall::<Runtime>::transfer {
dest: MultiAddress::Id(vault_pubkey.into()),
dest: MultiAddress::Id(fee_recipient),
value: fee,
}
.dispatch_bypass_filter(origin.clone())
Expand All @@ -303,12 +298,10 @@ where
account_id_to_string(&beneficiary),
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())
})?;
// 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 = TX_FEE * 3;
let fee = crate::STF_TX_FEE * 3;

info!(
"balance_unshield(from (L2): {}, to (L1): {}, amount {} (+fee: {}), shard {})",
Expand All @@ -321,7 +314,7 @@ where

let origin = ita_sgx_runtime::RuntimeOrigin::signed(account_incognito.clone());
ita_sgx_runtime::BalancesCall::<Runtime>::transfer {
dest: MultiAddress::Id(vault_pubkey.into()),
dest: MultiAddress::Id(fee_recipient),
value: fee,
}
.dispatch_bypass_filter(origin)
Expand Down Expand Up @@ -527,12 +520,12 @@ 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 vault
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()))?;
let account_info = System::account(&AccountId::from(vault_pubkey));
// endow fee to enclave (self)
let fee_recipient: AccountId = enclave_signer_account();

let account_info = System::account(&AccountId::from(fee_recipient.clone()));
ita_sgx_runtime::BalancesCall::<Runtime>::force_set_balance {
who: MultiAddress::Id(vault_pubkey.into()),
who: MultiAddress::Id(fee_recipient),
new_free: account_info.data.free + fee,
}
.dispatch_bypass_filter(ita_sgx_runtime::RuntimeOrigin::root())
Expand Down
2 changes: 1 addition & 1 deletion enclave-runtime/src/test/sidechain_aura_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn produce_sidechain_block_and_import_it() {
&shielding_key,
sender_with_low_balance,
receiver.public().into(),
200000,
ita_stf::test_genesis::SECOND_ENDOWED_ACC_FUNDS + 1,
);
info!("Add trusted operations to TOP pool..");
executor::block_on(top_pool_author.submit_top(trusted_operation, shard_id)).unwrap();
Expand Down
29 changes: 18 additions & 11 deletions enclave-runtime/src/test/tests_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use itp_stf_primitives::{
use itp_stf_state_handler::handle_state::HandleState;
use itp_test::mock::handle_state_mock;
use itp_top_pool_author::{test_utils::submit_operation_to_top_pool, traits::AuthorApi};
use itp_types::{AccountId, Block, Header};
use itp_types::{AccountId, Balance, Block, Header};
use its_primitives::{
traits::{
Block as BlockTrait, BlockData, Header as SidechainHeaderTrait,
Expand Down Expand Up @@ -382,9 +382,13 @@ fn test_create_state_diff() {

let sender = funded_pair();
let receiver = unfunded_public();

let signed_call = TrustedCall::balance_transfer(sender.public().into(), receiver.into(), 1000)
.sign(&sender.clone().into(), 0, &mrenclave, &shard);
const TX_AMOUNT: Balance = 1_000_000_000_000;
let signed_call = TrustedCall::balance_transfer(
sender.public().into(),
receiver.into(),
TX_AMOUNT,
)
.sign(&sender.clone().into(), 0, &mrenclave, &shard);
let trusted_operation = direct_top(signed_call);

submit_operation_to_top_pool(
Expand Down Expand Up @@ -424,10 +428,13 @@ fn test_create_state_diff() {
get_from_state_diff(&state_diff, &account_key_hash::<AccountId>(&receiver.into()));

// state diff should consist of the following updates:
// (last_hash, sidechain block_number, sender_funds, receiver_funds, [no clear, after polkadot_v0.9.26 update], events)
assert_eq!(state_diff.len(), 6);
assert_eq!(receiver_acc_info.data.free, 1000);
assert_eq!(sender_acc_info.data.free, 1000);
// (last_hash, sidechain block_number, sender_funds, receiver_funds, fee_recipient account [no clear, after polkadot_v0.9.26 update], events)
assert_eq!(state_diff.len(), 7);
assert_eq!(receiver_acc_info.data.free, TX_AMOUNT);
assert_eq!(
sender_acc_info.data.free,
ita_stf::test_genesis::ENDOWED_ACC_FUNDS - TX_AMOUNT - ita_stf::STF_TX_FEE
);
}

fn test_executing_call_updates_account_nonce() {
Expand Down Expand Up @@ -615,7 +622,7 @@ pub fn test_retrieve_events() {
let repo = Arc::new(NodeMetadataRepository::<NodeMetadataMock>::default());
TestStf::execute_call(&mut state, trusted_call, &mut opaque_vec, repo).unwrap();

assert_eq!(TestStf::get_events(&mut state).len(), 3);
assert_eq!(TestStf::get_events(&mut state).len(), 4);
}

pub fn test_retrieve_event_count() {
Expand All @@ -640,7 +647,7 @@ pub fn test_retrieve_event_count() {
TestStf::execute_call(&mut state, trusted_call, &mut opaque_vec, repo).unwrap();

let event_count = TestStf::get_event_count(&mut state);
assert_eq!(event_count, 3);
assert_eq!(event_count, 4);
}

pub fn test_reset_events() {
Expand All @@ -663,7 +670,7 @@ pub fn test_reset_events() {
let receiver_acc_info = TestStf::get_account_data(&mut state, &receiver.public().into());
assert_eq!(receiver_acc_info.free, transfer_value);
// Ensure that there really have been events generated.
assert_eq!(TestStf::get_events(&mut state).len(), 3);
assert_eq!(TestStf::get_events(&mut state).len(), 4);

// Remove the events.
TestStf::reset_events(&mut state);
Expand Down
7 changes: 6 additions & 1 deletion enclave-runtime/src/test/top_pool_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ fn create_shielding_call_extrinsic<ShieldingKey: ShieldingCryptoEncrypt>(
let shield_funds_indexes = dummy_node_metadata.shield_funds_call_indexes().unwrap();
let opaque_extrinsic = OpaqueExtrinsic::from_bytes(
ParentchainUncheckedExtrinsic::<ShieldFundsFn>::new_signed(
(shield_funds_indexes, shard, target_account, 1000u128),
(
shield_funds_indexes,
shard,
target_account,
ita_stf::test_genesis::SECOND_ENDOWED_ACC_FUNDS,
),
Address::Address32([1u8; 32]),
MultiSignature::Ed25519(signature),
default_extra_for_test.signed_extra(),
Expand Down