Skip to content

Commit c43f180

Browse files
authored
Adding integration tests for the omni-executor (#3255)
1 parent 7c08d8f commit c43f180

File tree

32 files changed

+6313
-110
lines changed

32 files changed

+6313
-110
lines changed

tee-worker/client-api/parachain-api/prepare-build/interfaces/omniExecutor/definitions.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default {
1212
MrEnclave: "H256",
1313
NativeCall: {
1414
_enum: {
15+
request_auth_token: "(LitentryIdentity, AuthOptions)",
1516
request_intent: "(LitentryIdentity, Intent)",
1617
create_account_store: "(LitentryIdentity)",
1718
add_account: "(LitentryIdentity, LitentryIdentity, LitentryValidationData, bool, Option<Vec<OmniAccountPermission>>)",
@@ -45,8 +46,8 @@ export default {
4546
NativeCallResponse: "Result<NativeCallOk, NativeCallError>",
4647
NativeCallOk: {
4748
_enum: {
48-
AuthToken: "(Text)",
49-
ExtrinsicReport: "(XtReport)",
49+
ExtrinsicReport: "XtReport",
50+
AuthToken: "Text",
5051
},
5152
},
5253
XtReport: {
@@ -59,36 +60,38 @@ export default {
5960
status: "TxStatus",
6061
},
6162
TxStatus: {
62-
// Transaction is part of the future queue.
63-
Future: "Null",
64-
// Transaction is part of the ready queue.
65-
Ready: "Null",
66-
// The transaction has been broadcast to the given peers.
67-
Broadcast: "Vec<Text>",
68-
// Transaction has been included in block with given hash.
69-
InBlock: "H256",
70-
// The block this transaction was included in has been retracted.
71-
Retracted: "H256",
72-
// Maximum number of finality watchers has been reached,
73-
// old watchers are being removed.
74-
FinalityTimeout: "H256",
75-
// Transaction has been finalized by a finality-gadget, e.g GRANDPA
76-
Finalized: "H256",
77-
// Transaction has been replaced in the pool, by another transaction
78-
// that provides the same tags. (e.g. same (sender, nonce)).
79-
Usurped: "H256",
80-
// Transaction has been dropped from the pool because of the limit.
81-
Dropped: "Null",
82-
// Transaction is no longer valid in the current state.
83-
Invalid: "Null",
63+
_enum: {
64+
// Transaction is part of the future queue.
65+
Future: "Null",
66+
// Transaction is part of the ready queue.
67+
Ready: "Null",
68+
// The transaction has been broadcast to the given peers.
69+
Broadcast: "Vec<Text>",
70+
// Transaction has been included in block with given hash.
71+
InBlock: "H256",
72+
// The block this transaction was included in has been retracted.
73+
Retracted: "H256",
74+
// Maximum number of finality watchers has been reached,
75+
// old watchers are being removed.
76+
FinalityTimeout: "H256",
77+
// Transaction has been finalized by a finality-gadget, e.g GRANDPA
78+
Finalized: "H256",
79+
// Transaction has been replaced in the pool, by another transaction
80+
// that provides the same tags. (e.g. same (sender, nonce)).
81+
Usurped: "H256",
82+
// Transaction has been dropped from the pool because of the limit.
83+
Dropped: "Null",
84+
// Transaction is no longer valid in the current state.
85+
Invalid: "Null",
86+
},
8487
},
8588
NativeCallError: {
8689
_enum: {
8790
UnexpectedCall: "(Text)",
8891
UnauthorizedSender: "Null",
8992
AuthTokenCreationFailed: "Null",
9093
InternalError: "Null",
91-
IInvalidMemberIdentity: "Null",
94+
InvalidMemberIdentity: "Null",
9295
ValidationDataVerificationFailed: "Null",
9396
},
9497
},

tee-worker/client-api/parachain-api/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import { default as vc } from "../build/interfaces/vc/definitions";
1717
import { default as omniAccount } from "../build/interfaces/omniAccount/definitions";
1818
import { default as trusted_operations } from "../build/interfaces/trusted_operations/definitions";
1919
import { default as sidechain } from "../build/interfaces/sidechain/definitions";
20-
export { identity, vc, trusted_operations, sidechain, omniAccount };
20+
import { default as omniExecutor } from "../build/interfaces/omniExecutor/definitions";
21+
export { identity, vc, trusted_operations, sidechain, omniAccount, omniExecutor };
2122

2223
// Export handy types
2324
import type { LitentryIdentity, Web3Network } from "../build/interfaces/identity/types";

tee-worker/omni-executor/Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tee-worker/omni-executor/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"oauth-providers",
1414
"parentchain/listener",
1515
"parentchain/api-interface",
16+
"parentchain/attestation",
1617
"parentchain/rpc-client",
1718
"parentchain/signer",
1819
"rpc-server",
@@ -69,6 +70,7 @@ heima-primitives = { package = "core-primitives", path = "../../common/primitive
6970
native-task-handler = { path = "native-task-handler" }
7071
oauth-providers = { path = "oauth-providers" }
7172
parentchain-api-interface = { path = "parentchain/api-interface" }
73+
parentchain-attestation = { path = "parentchain/attestation" }
7274
parentchain-listener = { path = "parentchain/listener" }
7375
parentchain-rpc-client = { path = "parentchain/rpc-client" }
7476
parentchain-signer = { path = "parentchain/signer" }

tee-worker/omni-executor/executor-worker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ethereum-intent-executor = { workspace = true }
1818
executor-core = { workspace = true }
1919
executor-storage = { workspace = true }
2020
native-task-handler = { workspace = true }
21+
parentchain-attestation = { workspace = true }
2122
parentchain-listener = { workspace = true }
2223
parentchain-rpc-client = { workspace = true }
2324
parentchain-signer = { workspace = true }

tee-worker/omni-executor/executor-worker/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct RunArgs {
2020
pub ethereum_url: String,
2121
pub solana_url: String,
2222
pub worker_rpc_port: String,
23-
#[arg(short, long, default_value = "0", value_name = "start block to sync from parentchain")]
23+
#[arg(long, default_value = "0", value_name = "start block to sync from parentchain")]
2424
pub start_block: u64,
2525
#[arg(
2626
short,

tee-worker/omni-executor/executor-worker/src/main.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ use log::error;
2424
use native_task_handler::{
2525
run_native_task_handler, Aes256KeyStore, ParentchainTxSigner, TaskHandlerContext,
2626
};
27+
use parentchain_attestation::perform_attestation;
2728
use parentchain_rpc_client::metadata::SubxtMetadataProvider;
2829
use parentchain_rpc_client::{CustomConfig, SubxtClientFactory};
2930
use parentchain_signer::key_store::SubstrateKeyStore;
30-
use parentchain_signer::TransactionSigner;
31+
use parentchain_signer::{get_signer, TransactionSigner};
3132
use rpc_server::{start_server as start_rpc_server, ShieldingKey};
3233
use solana_intent_executor::SolanaIntentExecutor;
3334
use std::env;
@@ -92,6 +93,18 @@ async fn main() -> Result<(), ()> {
9293
// TODO: get mrenclave from quote
9394
let mrenclave = [0u8; 32];
9495

96+
let signer = get_signer(substrate_key_store.clone());
97+
98+
perform_attestation(
99+
parentchain_rpc_client_factory.clone(),
100+
signer,
101+
transaction_signer.clone(),
102+
)
103+
.await
104+
.map_err(|_| {
105+
error!("Could not perform attestation");
106+
})?;
107+
95108
start_rpc_server(
96109
&args.worker_rpc_port,
97110
parentchain_rpc_client_factory,
@@ -106,9 +119,7 @@ async fn main() -> Result<(), ()> {
106119
error!("Could not start server: {:?}", e);
107120
})?;
108121

109-
listen_to_parentchain(args, storage_db, transaction_signer, substrate_key_store)
110-
.await
111-
.unwrap();
122+
listen_to_parentchain(args, storage_db, transaction_signer).await.unwrap();
112123

113124
match signal::ctrl_c().await {
114125
Ok(()) => {},
@@ -131,7 +142,6 @@ async fn listen_to_parentchain(
131142
args: RunArgs,
132143
storage_db: Arc<StorageDB>,
133144
parentchain_tx_signer: Arc<ParentchainTxSigner>,
134-
substrate_key_store: Arc<SubstrateKeyStore>,
135145
) -> Result<JoinHandle<()>, ()> {
136146
let (_sub_stop_sender, sub_stop_receiver) = oneshot::channel();
137147
let ethereum_intent_executor =
@@ -149,7 +159,6 @@ async fn listen_to_parentchain(
149159
sub_stop_receiver,
150160
storage_db,
151161
parentchain_tx_signer,
152-
substrate_key_store,
153162
&args.log_path,
154163
)
155164
.await?;

tee-worker/omni-executor/native-task-handler/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async fn handle_native_task<
167167
Intent::SystemRemark(remark) => {
168168
let remark_call = SystemCall::remark { remark: remark.to_vec() };
169169
let dispatch_as_omni_account_call =
170-
parentchain_api_interface::tx().omni_account().dispatch_as_omni_account(
170+
parentchain_api_interface::tx().omni_account().dispatch_as_signed(
171171
sender_identity.hash().to_subxt_type(),
172172
RuntimeCall::System(remark_call),
173173
task.auth_type.to_subxt_type(),
@@ -180,7 +180,7 @@ async fn handle_native_task<
180180
value: transfer.value,
181181
};
182182
let dispatch_as_omni_account_call =
183-
parentchain_api_interface::tx().omni_account().dispatch_as_omni_account(
183+
parentchain_api_interface::tx().omni_account().dispatch_as_signed(
184184
sender_identity.hash().to_subxt_type(),
185185
RuntimeCall::Balances(transfer_call),
186186
task.auth_type.to_subxt_type(),
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "parentchain-attestation"
3+
version = "0.1.0"
4+
authors = ['Trust Computing GmbH <[email protected]>']
5+
edition.workspace = true
6+
7+
[dependencies]
8+
log = { workspace = true }
9+
subxt-core = { workspace = true }
10+
subxt-signer = { workspace = true }
11+
12+
# Local dependencies
13+
parentchain-api-interface = { workspace = true }
14+
parentchain-rpc-client = { workspace = true }
15+
parentchain-signer = { workspace = true }
16+
17+
[dev-dependencies]
18+
env_logger = { workspace = true }
19+
20+
[lints]
21+
workspace = true
22+
23+
[features]
24+
gramine-quote = []
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
use parentchain_api_interface::{
2+
runtime_types::core_primitives::teebag::types::DcapProvider,
3+
teebag::calls::types::register_enclave::{AttestationType, WorkerMode, WorkerType},
4+
};
5+
use parentchain_rpc_client::{
6+
metadata::SubxtMetadataProvider, CustomConfig, SubstrateRpcClient, SubxtClient,
7+
SubxtClientFactory,
8+
};
9+
use parentchain_signer::{key_store::SubstrateKeyStore, TransactionSigner};
10+
use std::sync::Arc;
11+
use subxt_core::Metadata;
12+
use subxt_signer::sr25519::Keypair;
13+
14+
type TxSigner = TransactionSigner<
15+
SubstrateKeyStore,
16+
SubxtClient<CustomConfig>,
17+
SubxtClientFactory<CustomConfig>,
18+
CustomConfig,
19+
Metadata,
20+
SubxtMetadataProvider<CustomConfig>,
21+
>;
22+
23+
#[allow(unused_assignments, unused_mut, unused_variables)]
24+
pub async fn perform_attestation(
25+
client_factory: Arc<SubxtClientFactory<CustomConfig>>,
26+
signer: Keypair,
27+
transaction_signer: Arc<TxSigner>,
28+
) -> Result<(), ()> {
29+
let mut quote = vec![];
30+
let mut attestation_type = AttestationType::Dcap(DcapProvider::Intel);
31+
32+
#[cfg(feature = "gramine-quote")]
33+
{
34+
use log::info;
35+
use std::fs;
36+
use std::fs::File;
37+
use std::io::Write;
38+
let mut f = File::create("/dev/attestation/user_report_data").unwrap();
39+
let content = signer.public_key().0;
40+
f.write_all(&content).unwrap();
41+
42+
quote = fs::read("/dev/attestation/quote").unwrap();
43+
info!("Attestation quote {:?}", quote);
44+
}
45+
#[cfg(not(feature = "gramine-quote"))]
46+
{
47+
attestation_type = AttestationType::Ignore;
48+
}
49+
50+
let registration_call = parentchain_api_interface::tx().teebag().register_enclave(
51+
WorkerType::OmniExecutor,
52+
WorkerMode::OffChainWorker,
53+
quote,
54+
vec![],
55+
None,
56+
None,
57+
attestation_type,
58+
);
59+
60+
let mut client = client_factory.new_client_until_connected().await;
61+
let signed_call = transaction_signer.sign(registration_call).await;
62+
client.submit_tx(&signed_call).await.map_err(|e| {
63+
log::error!("Error while submitting tx: {:?}", e);
64+
})?;
65+
Ok(())
66+
}

0 commit comments

Comments
 (0)