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
ecdf920
add design document with some mermaid diagrams
brenzi Oct 11, 2023
347e187
support enclave signing with changing keypairs at runtime
brenzi Oct 11, 2023
81e94dd
tame nervous polling of not yet finalized block
brenzi Oct 11, 2023
6ddd043
shard vault account creation works
brenzi Oct 11, 2023
156aac3
prepare vault account getter. not working yet
brenzi Oct 11, 2023
f1d3d77
fix build and add trusted_call dummy for unshielding
brenzi Oct 12, 2023
9911098
fix transfer call indexes
brenzi Oct 12, 2023
ead3662
unshieldind dummy with real vault account and proxy call
brenzi Oct 12, 2023
b20d978
await vault account creation before registering proxy
brenzi Oct 12, 2023
4524b9f
proxied unshielding call encodes correctly and would be executed if t…
brenzi Oct 12, 2023
6587f1b
start MU_RA doc diagrams and refactor namings for improved readability
brenzi Oct 12, 2023
d5ce0c7
refactoring MU RA functions for better readability. try to extract cl…
brenzi Oct 12, 2023
cd3562d
logging pubkey of counterparty now during MU RA. but seems skip_ra wo…
brenzi Oct 12, 2023
36bdc5c
add client account to MU RA request
brenzi Oct 13, 2023
b5da3a2
starting to modularize vault logic
brenzi Oct 13, 2023
ed26be7
secondary worker is registered as a vault proxy now
brenzi Oct 13, 2023
da6bea0
Merge remote-tracking branch 'origin/master' into ab/proxied-vault-ac…
brenzi Oct 13, 2023
b72c063
cleanup
brenzi Oct 13, 2023
4d2c000
clippy
brenzi Oct 13, 2023
9bc2e60
doc cleanup
brenzi Oct 13, 2023
757c07a
doc pimp
brenzi Oct 13, 2023
2b7ed16
cleanup
brenzi Oct 13, 2023
bb69ebd
reverting polling fix which is solved in another PR
brenzi Oct 24, 2023
42fac49
fix diagram bug
brenzi Oct 24, 2023
f5acb2d
fix mock test
brenzi Oct 24, 2023
6e03fff
avoid panic if add_shard_vault_proxy fails
brenzi Oct 25, 2023
2109bd2
skip shard vault stuff for offchain-worker
brenzi Oct 26, 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
await vault account creation before registering proxy
  • Loading branch information
brenzi committed Oct 12, 2023
commit b20d978652574db93da1b781da8e855bb6577edd
1 change: 0 additions & 1 deletion app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ where
call_hash,
)));
// todo: the following is a placeholder dummy which will replace the above with #1257
// todo: insert correct vault accountid here
let vault_pubkey: [u8; 32] = get_storage_by_key_hash(SHARD_VAULT_KEY.into())
.ok_or(StfError::Dispatch("shard vault key hasn't been set".to_string()))?;
let vault_address = Address::from(AccountId::from(vault_pubkey));
Expand Down
1 change: 1 addition & 0 deletions core-primitives/ocall-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub trait EnclaveOnChainOCallApi: Clone + Send + Sync {
&self,
extrinsics: Vec<OpaqueExtrinsic>,
parentchain_id: &ParentchainId,
await_each_inclusion: bool,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

necessary to wait for vault to be created before trying to send an extrinsic as vault

) -> SgxResult<()>;

fn worker_request<V: Encode + Decode>(
Expand Down
1 change: 1 addition & 0 deletions core-primitives/test/src/mock/onchain_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ impl EnclaveOnChainOCallApi for OnchainMock {
&self,
_extrinsics: Vec<OpaqueExtrinsic>,
_: &ParentchainId,
_: bool,
) -> SgxResult<()> {
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion core/parentchain/light-client/src/light_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ where
{
fn send_extrinsics(&mut self, extrinsics: Vec<OpaqueExtrinsic>) -> Result<(), Error> {
self.ocall_api
.send_to_parentchain(extrinsics, &self.parentchain_id)
.send_to_parentchain(extrinsics, &self.parentchain_id, false)
.map_err(|e| {
Error::Other(
format!("[{:?}] Failed to send extrinsics: {}", self.parentchain_id, e).into(),
Expand Down
3 changes: 2 additions & 1 deletion enclave-runtime/Enclave.edl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ enclave {

sgx_status_t ocall_send_to_parentchain(
[in, size = extrinsics_size] uint8_t * extrinsics, uint32_t extrinsics_size,
[in, size=parentchain_id_size] uint8_t* parentchain_id, uint32_t parentchain_id_size
[in, size=parentchain_id_size] uint8_t* parentchain_id, uint32_t parentchain_id_size,
int await_each_inclusion
);
};
};
5 changes: 3 additions & 2 deletions enclave-runtime/src/initialization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ pub(crate) fn init_proxied_shard_vault(shard: ShardIdentifier) -> EnclaveResult<
info!("vault funding call: 0x{}", hex::encode(call.0.clone()));
let xts = enclave_extrinsics_factory.create_extrinsics(&[call], None)?;

ocall_api.send_to_parentchain(xts, &ParentchainId::Integritee);
//this extrinsic must be included in a block before we can move on. otherwise the next will fail
ocall_api.send_to_parentchain(xts, &ParentchainId::Integritee, true);

let nonce_cache = Arc::new(NonceCache::default());
let vault_extrinsics_factory = enclave_extrinsics_factory
Expand All @@ -364,7 +365,7 @@ pub(crate) fn init_proxied_shard_vault(shard: ShardIdentifier) -> EnclaveResult<
info!("add proxy call: 0x{}", hex::encode(call.0.clone()));
let xts = vault_extrinsics_factory.create_extrinsics(&[call], None)?;

ocall_api.send_to_parentchain(xts, &ParentchainId::Integritee);
ocall_api.send_to_parentchain(xts, &ParentchainId::Integritee, false);

// xt: delegate proxy authority to its own enclave accountid proxy.add_proxy() (panic if fails)
// caveat: must send from vault account. how to sign extrinsics with other keypair?
Expand Down
1 change: 1 addition & 0 deletions enclave-runtime/src/ocall/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ extern "C" {
extrinsics_size: u32,
parentchain_id: *const u8,
parentchain_id_size: u32,
await_each_inclusion: c_int,
) -> sgx_status_t;

pub fn ocall_read_ipfs(
Expand Down
2 changes: 2 additions & 0 deletions enclave-runtime/src/ocall/on_chain_ocall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl EnclaveOnChainOCallApi for OcallApi {
&self,
extrinsics: Vec<OpaqueExtrinsic>,
parentchain_id: &ParentchainId,
await_each_inclusion: bool,
) -> SgxResult<()> {
let mut rt: sgx_status_t = sgx_status_t::SGX_ERROR_UNEXPECTED;
let extrinsics_encoded = extrinsics.encode();
Expand All @@ -45,6 +46,7 @@ impl EnclaveOnChainOCallApi for OcallApi {
extrinsics_encoded.len() as u32,
parentchain_id_encoded.as_ptr(),
parentchain_id_encoded.len() as u32,
await_each_inclusion.into(),
)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl EnclaveOnChainOCallApi for ProposeToImportOCallApi {
&self,
_extrinsics: Vec<OpaqueExtrinsic>,
_: &ParentchainId,
_: bool,
) -> SgxResult<()> {
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions service/src/ocall_bridge/bridge_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub trait WorkerOnChainBridge {
&self,
extrinsics_encoded: Vec<u8>,
parentchain_id: Vec<u8>,
await_each_inclusion: bool,
) -> OCallBridgeResult<()>;
}

Expand Down
7 changes: 5 additions & 2 deletions service/src/ocall_bridge/ffi/send_to_parentchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use crate::ocall_bridge::bridge_api::{Bridge, WorkerOnChainBridge};
use log::*;
use sgx_types::sgx_status_t;
use sgx_types::{c_int, sgx_status_t};
use std::{slice, sync::Arc, vec::Vec};

/// # Safety
Expand All @@ -30,12 +30,14 @@ pub unsafe extern "C" fn ocall_send_to_parentchain(
extrinsics_encoded_size: u32,
parentchain_id: *const u8,
parentchain_id_size: u32,
await_each_inclusion: c_int,
) -> sgx_status_t {
send_to_parentchain(
extrinsics_encoded,
extrinsics_encoded_size,
parentchain_id,
parentchain_id_size,
await_each_inclusion.into(),
Bridge::get_oc_api(),
)
}
Expand All @@ -45,6 +47,7 @@ fn send_to_parentchain(
extrinsics_encoded_size: u32,
parentchain_id: *const u8,
parentchain_id_size: u32,
await_each_inclusion: bool,
oc_api: Arc<dyn WorkerOnChainBridge>,
) -> sgx_status_t {
let extrinsics_encoded_vec: Vec<u8> = unsafe {
Expand All @@ -54,7 +57,7 @@ fn send_to_parentchain(
let parentchain_id: Vec<u8> =
unsafe { Vec::from(slice::from_raw_parts(parentchain_id, parentchain_id_size as usize)) };

match oc_api.send_to_parentchain(extrinsics_encoded_vec, parentchain_id) {
match oc_api.send_to_parentchain(extrinsics_encoded_vec, parentchain_id, await_each_inclusion) {
Ok(_) => sgx_status_t::SGX_SUCCESS,
Err(e) => {
error!("send extrinsics_encoded failed: {:?}", e);
Expand Down
32 changes: 24 additions & 8 deletions service/src/ocall_bridge/worker_on_chain_ocall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use itp_types::{parentchain::ParentchainId, WorkerRequest, WorkerResponse};
use log::*;
use sp_runtime::OpaqueExtrinsic;
use std::{sync::Arc, vec::Vec};
use substrate_api_client::{ac_primitives::serde_impls::StorageKey, GetStorage, SubmitExtrinsic};
use substrate_api_client::{
ac_primitives::serde_impls::StorageKey, rpc_api::SubmitAndWatchUntilSuccess, GetStorage,
SubmitAndWatch, SubmitExtrinsic, XtStatus,
};

pub struct WorkerOnChainOCall<F> {
integritee_api_factory: Arc<F>,
Expand Down Expand Up @@ -107,6 +110,7 @@ where
&self,
extrinsics_encoded: Vec<u8>,
parentchain_id: Vec<u8>,
await_each_inlcusion: bool,
) -> OCallBridgeResult<()> {
// TODO: improve error handling, using a mut status is not good design?
let mut status: OCallBridgeResult<()> = Ok(());
Expand All @@ -131,16 +135,28 @@ where
);
let api = self.create_api(parentchain_id)?;
for call in extrinsics.into_iter() {
if let Err(e) = api.submit_opaque_extrinsic(&call.encode().into()) {
error!(
"Could not send extrinsic to node: {:?}, error: {:?}",
serde_json::to_string(&call),
e
);
if await_each_inlcusion {
if let Err(e) = api.submit_and_watch_opaque_extrinsic_until(
&call.encode().into(),
XtStatus::InBlock,
) {
error!(
"Could not send extrinsic to node: {:?}, error: {:?}",
serde_json::to_string(&call),
e
);
}
} else {
if let Err(e) = api.submit_opaque_extrinsic(&call.encode().into()) {
error!(
"Could not send extrinsic to node: {:?}, error: {:?}",
serde_json::to_string(&call),
e
);
}
}
}
}

status
}
}
Expand Down