Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P 1164 auto fund sign account when omni executor is running in #3231

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,13 @@ fmt-cargo:
@cd parachain && cargo fmt --all
@cd tee-worker && cargo fmt --all
@cd tee-worker/identity/enclave-runtime && cargo fmt --all
@cd tee-worker/omni-executor && cargo fmt --all

.PHONY: fmt-taplo ## taplo fmt
fmt-taplo:
@cd parachain && RUST_LOG=error taplo fmt
@cd tee-worker && RUST_LOG=error taplo fmt
@cd tee-worker/omni-executor && RUST_LOG=error taplo fmt

.PHONY: fmt-ts ## ts fmt
fmt-ts:
Expand Down
11 changes: 1 addition & 10 deletions tee-worker/identity/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,7 @@ log*
**/*.rs.bk

# binaries
bin/*.so
bin/litentry-*
bin/*.wasm

# sealed data
bin/*.bin

# public RSA key
bin/rsa_pubkey.txt
bin/ecc_pubkey.txt
bin/*

# VS Code settings
.vscode
Expand Down
Empty file.
1 change: 0 additions & 1 deletion tee-worker/identity/bin/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions tee-worker/omni-executor/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ target/
.idea/
**/*.bin

storage_db

cache
omni-executor.manifest
omni-executor.manifest.sgx
Expand Down
15 changes: 15 additions & 0 deletions tee-worker/omni-executor/.taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include = ["Cargo.toml", "**/Cargo.toml"]

[formatting]
array_auto_expand = false
array_auto_collapse = false
indent_string = " "
inline_table_expand = false

[[rule]]
include = ["Cargo.toml", "**/Cargo.toml"]
keys = ["dependencies", "target", "patch", "workspace", "workspace.dependencies", "workspace.package", "features"]

[rule.formatting]
reorder_keys = true
array_auto_expand = true
3 changes: 3 additions & 0 deletions tee-worker/omni-executor/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 14 additions & 11 deletions tee-worker/omni-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ resolver = "2"
edition = "2021"

[workspace.dependencies]
log = "0.4.22"
tokio = "1.40.0"
alloy = "0.3.6"
async-trait = "0.1.82"
clap = "4.5.17"
env_logger = "0.11.5"
scale-encode = "0.10.0"
frame-support = { version = "39.0.0", features = ["std"] }
hex = "0.4.3"
log = "0.4.22"
parity-scale-codec = "3.6.12"
alloy = "0.3.6"
clap = "4.5.17"
solana-sdk = "2.1.5"
regex = "1.7"
scale-encode = "0.10.0"
solana-client = "2.1.5"
solana-sdk = "2.1.5"
sp-core = "35.0.0"
sp-state-machine = { version = "0.44.0", features = ["std"] }
subxt = "0.38.0"
subxt-core = "0.38.0"
subxt-signer = { version = "0.38.0", features = ["subxt"] }
sp-state-machine = { version = "0.44.0", features = ["std"] }
frame-support = { version = "39.0.0", features = ["std"] }
tokio = "1.40.0"

executor-core = { path = "executor-core" }
ethereum-intent-executor = { path = "ethereum/intent-executor" }
solana-intent-executor = { path = "solana/intent-executor" }
parentchain-listener = { path = "parentchain/listener" }
executor-core = { path = "executor-core" }
parentchain-api-interface = { path = "parentchain/api-interface" }
parentchain-listener = { path = "parentchain/listener" }
parentchain-primitives = { path = "parentchain/primitives" }
parentchain-rpc-client = { path = "parentchain/rpc-client" }
parentchain-storage = { path = "parentchain/storage" }
solana-intent-executor = { path = "solana/intent-executor" }

[workspace.lints.clippy]
result_unit_err = "allow"
9 changes: 4 additions & 5 deletions tee-worker/omni-executor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause

ARCH_LIBDIR ?= /lib/$(shell $(CC) -dumpmachine)
SGX_MODE ?= HW
SGX ?= 1

SELF_EXE = omni-executor-worker
COMPILATION_FEATURES =
Expand All @@ -12,8 +12,8 @@ OMNI_DIR := $(ROOTDIR)/tee-worker/omni-executor

.PHONY: all
all: $(SELF_EXE) omni-executor.manifest
ifeq ($(SGX_MODE), HW)
COMPILATION_FEATURES = gramine-quote
ifeq ($(SGX), 1)
COMPILATION_FEATURES := $(COMPILATION_FEATURES),gramine-quote
all: omni-executor.manifest.sgx omni-executor.sig
endif

Expand Down Expand Up @@ -48,7 +48,7 @@ sgx_sign: omni-executor.manifest $(SELF_EXE)
--output $<.sgx \
--key enclave_key.pem

ifeq ($(SGX_MODE), HW)
ifeq ($(SGX), 1)
GRAMINE = gramine-sgx
else
GRAMINE = gramine-direct
Expand All @@ -66,7 +66,6 @@ clean:
distclean: clean
cargo clean

# By default SGX_MODE=SW for docker image
.PHONY: build-docker
build-docker:
docker build --target executor-worker -t litentry/omni-executor:latest -f $(OMNI_DIR)/Dockerfile $(OMNI_DIR)
Expand Down
1 change: 1 addition & 0 deletions tee-worker/omni-executor/executor-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition.workspace = true
async-trait = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
regex = { workspace = true }
tokio = { workspace = true }

[lints]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::fmt::Debug;
use std::fs;
use std::fs::File;
use std::io::{ErrorKind, Write};
use std::path::Path;

/// Represents the point in chain. It can be a whole block or a more precise unit, for example
/// in case of substrate chain it is BLOCK_NUM::EVENT_NUM
Expand Down Expand Up @@ -66,7 +67,15 @@ pub struct FileCheckpointRepository {

impl FileCheckpointRepository {
pub fn new(file_name: &str) -> Self {
// todo add regex check here
let file_name_regex = regex::Regex::new(r"^[a-zA-Z0-9_\-\.\/]+$").expect("Invalid regex");
if !file_name_regex.is_match(file_name) {
panic!("Invalid file name: {}", file_name);
}

if let Some(parent) = Path::new(file_name).parent() {
fs::create_dir_all(parent).expect("Failed to create directories");
}

Self { file_name: file_name.to_owned() }
}
}
Expand Down
41 changes: 40 additions & 1 deletion tee-worker/omni-executor/executor-worker/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
use clap::Parser;
use clap::{Args, Parser, Subcommand};

#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub cmd: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
Run(RunArgs),
GenKey(GenKeyArgs),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does GenKey do exactly? It seems we don't need this command

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's used for the first time execution to generate a signer account. Then user can fund that account. Then start over.


#[derive(Args)]
pub struct RunArgs {
pub parentchain_url: String,
pub ethereum_url: String,
pub solana_url: String,
#[arg(short, long, default_value = "0", value_name = "start block to sync from parentchain")]
pub start_block: u64,
#[arg(
short,
long,
default_value = "local/keystore/substrate_alice.bin",
value_name = "keystore file path"
)]
pub keystore_path: String,
#[arg(
short,
long,
default_value = "local/log/parentchain_last_log.bin",
value_name = "log file path"
)]
pub log_path: String,
}

#[derive(Args)]
pub struct GenKeyArgs {
#[arg(
short,
long,
default_value = "local/keystore/substrate_alice.bin",
value_name = "keystore file path"
)]
pub keystore_path: String,
}
49 changes: 23 additions & 26 deletions tee-worker/omni-executor/executor-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

use crate::cli::Cli;
use clap::Parser;
use cli::*;
use ethereum_intent_executor::EthereumIntentExecutor;
use log::error;
use parentchain_storage::init_storage;
use solana_intent_executor::SolanaIntentExecutor;
use std::io::Write;
use std::thread;
use std::thread::JoinHandle;
use std::{fs, thread};
use tokio::runtime::Handle;
use tokio::signal;
use tokio::sync::oneshot;
Expand All @@ -47,52 +47,49 @@ async fn main() -> Result<(), ()> {

let cli = Cli::parse();

fs::create_dir_all("data/").map_err(|e| {
error!("Could not create data dir: {:?}", e);
})?;
match cli.cmd {
Commands::Run(args) => {
init_storage(&args.parentchain_url).await.expect("Could not initialize storage");
listen_to_parentchain(args).await.unwrap();

init_storage(&cli.parentchain_url).await.expect("Could not initialize storage");

listen_to_parentchain(cli.parentchain_url, cli.ethereum_url, cli.solana_url, cli.start_block)
.await
.unwrap();

match signal::ctrl_c().await {
Ok(()) => {},
Err(err) => {
eprintln!("Unable to listen for shutdown signal: {}", err);
// we also shut down in case of error
match signal::ctrl_c().await {
Ok(()) => {},
Err(err) => {
eprintln!("Unable to listen for shutdown signal: {}", err);
// we also shut down in case of error
},
}
},
Commands::GenKey(args) => {
let _ = parentchain_listener::get_signer(&args.keystore_path);
},
}

Ok(())
}

async fn listen_to_parentchain(
parentchain_url: String,
ethereum_url: String,
solana_url: String,
start_block: u64,
) -> Result<JoinHandle<()>, ()> {
async fn listen_to_parentchain(args: RunArgs) -> Result<JoinHandle<()>, ()> {
let (_sub_stop_sender, sub_stop_receiver) = oneshot::channel();
let ethereum_intent_executor =
EthereumIntentExecutor::new(&ethereum_url).map_err(|e| log::error!("{:?}", e))?;
EthereumIntentExecutor::new(&args.ethereum_url).map_err(|e| log::error!("{:?}", e))?;
let solana_intent_executor =
SolanaIntentExecutor::new(solana_url).map_err(|e| log::error!("{:?}", e))?;
SolanaIntentExecutor::new(args.solana_url).map_err(|e| log::error!("{:?}", e))?;

let mut parentchain_listener =
parentchain_listener::create_listener::<EthereumIntentExecutor, SolanaIntentExecutor>(
"litentry_rococo",
Handle::current(),
&parentchain_url,
&args.parentchain_url,
ethereum_intent_executor,
solana_intent_executor,
sub_stop_receiver,
&args.keystore_path,
&args.log_path,
)
.await?;

Ok(thread::Builder::new()
.name("litentry_rococo_sync".to_string())
.spawn(move || parentchain_listener.sync(start_block))
.spawn(move || parentchain_listener.sync(args.start_block))
.unwrap())
}
8 changes: 8 additions & 0 deletions tee-worker/omni-executor/local/keystore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This folder contains the dev keystore: signer key

How is bin file generated:

```bash
# subkey inspect '//Alice'
echo -n "e5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a" | xxd -r -p > substrate_alice.bin
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
¨u¸ÜTúrŚ ل¢ý÷m«xFm¨JÜòe¼½%͹
4 changes: 3 additions & 1 deletion tee-worker/omni-executor/parentchain/listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ edition.workspace = true

[dependencies]
async-trait = { workspace = true }
hex = "0.4.3"
hex = { workspace = true }
log = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-encode = { workspace = true }
sp-core = { workspace = true }
subxt = { workspace = true }
subxt-core = { workspace = true }
subxt-signer = { workspace = true }
Expand Down
Loading
Loading