Skip to content

Commit

Permalink
Initialize storage on omni executor startup (#3228)
Browse files Browse the repository at this point in the history
  • Loading branch information
silva-fj authored Jan 17, 2025
1 parent 0727fb3 commit 85190ed
Show file tree
Hide file tree
Showing 22 changed files with 1,809 additions and 273 deletions.
1,516 changes: 1,391 additions & 125 deletions tee-worker/omni-executor/Cargo.lock

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion tee-worker/omni-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ members = [
"executor-worker",
"parentchain/listener",
"parentchain/api-interface",
"parentchain/rpc-client",
"parentchain/storage",
"parentchain/primitives",
"ethereum/intent-executor",
"solana/intent-executor",
]
Expand All @@ -19,7 +21,7 @@ log = "0.4.22"
tokio = "1.40.0"
async-trait = "0.1.82"
env_logger = "0.11.5"
scale-encode = "0.7.1"
scale-encode = "0.10.0"
parity-scale-codec = "3.6.12"
alloy = "0.3.6"
clap = "4.5.17"
Expand All @@ -28,6 +30,17 @@ solana-client = "2.1.5"
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"] }

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

[workspace.lints.clippy]
result_unit_err = "allow"
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition.workspace = true
[dependencies]
alloy = { workspace = true, features = ["contract", "signer-local", "rpc", "rpc-types"] }
async-trait = { workspace = true }
executor-core = { path = "../../executor-core" }
executor-core = { workspace = true }
log = { workspace = true }

[dev-dependencies]
Expand Down
9 changes: 5 additions & 4 deletions tee-worker/omni-executor/executor-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ edition.workspace = true
[dependencies]
clap = { workspace = true, features = ["derive"] }
env_logger = { workspace = true }
ethereum-intent-executor = { path = "../ethereum/intent-executor" }
executor-core = { path = "../executor-core" }
ethereum-intent-executor = { workspace = true }
executor-core = { workspace = true }
hex = "0.4.3"
log = { workspace = true }
parentchain-listener = { path = "../parentchain/listener" }
parentchain-listener = { workspace = true }
parentchain-storage = { workspace = true }
scale-encode = { workspace = true }
serde_json = "1.0.127"
solana-intent-executor = { path = "../solana/intent-executor" }
solana-intent-executor = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal"] }

[lints]
Expand Down
3 changes: 3 additions & 0 deletions tee-worker/omni-executor/executor-worker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::cli::Cli;
use clap::Parser;
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::JoinHandle;
Expand Down Expand Up @@ -50,6 +51,8 @@ async fn main() -> Result<(), ()> {
error!("Could not create data dir: {:?}", e);
})?;

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();
Expand Down
7 changes: 6 additions & 1 deletion tee-worker/omni-executor/omni-executor.manifest.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fs.mounts = [
{ path = "/data", uri = "file:data", type="encrypted", key_name="{{'_sgx_mrsigner' if env.get('SGX', '0') == '1' else 'fake_sgx_mrsigner'}}" },
{ path = "/etc", uri = "file:/etc" },
{ path = "/usr", uri = "file:/usr" },
{ path = "/storage_db", uri = "file:storage_db" },
]

sgx.debug = true
Expand All @@ -39,6 +40,10 @@ sgx.trusted_files = [
"file:/usr/lib/ssl/certs/ca-certificates.crt",
]

sgx.allowed_files = [
"file:storage_db/",
]

# The maximum number of threads in a single process needs to be declared in advance.
# You need to account for:
# - one main thread
Expand All @@ -54,4 +59,4 @@ sgx.remote_attestation = "dcap"
loader.insecure__use_cmdline_argv = true
loader.insecure__use_host_env = true

fs.insecure__keys.fake_sgx_mrsigner = "ffeeddccbbaa99887766554433221100"
fs.insecure__keys.fake_sgx_mrsigner = "ffeeddccbbaa99887766554433221100"
9 changes: 5 additions & 4 deletions tee-worker/omni-executor/parentchain/listener/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ async-trait = { workspace = true }
hex = "0.4.3"
log = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-encode = "0.7.1"
subxt = { workspace = true }
subxt-core = { workspace = true }
subxt-signer = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

executor-core = { path = "../../executor-core" }
parentchain-api-interface = { path = "../api-interface" }
parentchain-storage = { path = "../storage" }
executor-core = { workspace = true }
parentchain-api-interface = { workspace = true }
parentchain-primitives = { workspace = true }
parentchain-rpc-client = { workspace = true }
parentchain-storage = { workspace = true }

[dev-dependencies]
env_logger = { workspace = true }
Expand Down
22 changes: 12 additions & 10 deletions tee-worker/omni-executor/parentchain/listener/src/event_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use crate::metadata::{MetadataProvider, SubxtMetadataProvider};
use crate::primitives::BlockEvent;
use crate::rpc_client::{SubstrateRpcClient, SubstrateRpcClientFactory};
use crate::transaction_signer::TransactionSigner;
use async_trait::async_trait;
use executor_core::event_handler::Error::RecoverableError;
Expand All @@ -35,6 +33,8 @@ use parentchain_api_interface::{
runtime_types::core_primitives::intent::Intent as RuntimeIntent,
tx as parentchain_tx,
};
use parentchain_primitives::BlockEvent;
use parentchain_rpc_client::{SubstrateRpcClient, SubstrateRpcClientFactory};
use std::marker::PhantomData;
use std::sync::Arc;
use subxt::ext::scale_decode;
Expand All @@ -51,8 +51,8 @@ pub struct EventHandler<
EthereumIntentExecutorT: IntentExecutor,
SolanaIntentExecutorT: IntentExecutor,
KeyStoreT: KeyStore<SecretKeyBytes>,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId>,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, RpcClient>,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId, ChainConfig::Header>,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, ChainConfig::Header, RpcClient>,
AccountStoreStorage: Storage<ChainConfig::AccountId, AccountStore>,
> {
metadata_provider: Arc<MetadataProviderT>,
Expand Down Expand Up @@ -80,8 +80,8 @@ impl<
EthereumIntentExecutorT: IntentExecutor,
SolanaIntentExecutorT: IntentExecutor,
KeyStoreT: KeyStore<SecretKeyBytes>,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId>,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, RpcClient>,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId, ChainConfig::Header>,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, ChainConfig::Header, RpcClient>,
AccountStoreStorage: Storage<ChainConfig::AccountId, AccountStore>,
>
EventHandler<
Expand Down Expand Up @@ -136,8 +136,10 @@ impl<
EthereumIntentExecutorT: IntentExecutor + Send + Sync,
SolanaIntentExecutorT: IntentExecutor + Send + Sync,
KeyStoreT: KeyStore<SecretKeyBytes> + Send + Sync,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId> + Send + Sync,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, RpcClient> + Send + Sync,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId, ChainConfig::Header> + Send + Sync,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, ChainConfig::Header, RpcClient>
+ Send
+ Sync,
AccountStoreStorage: Storage<ChainConfig::AccountId, AccountStore> + Send + Sync,
> EventHandlerTrait<BlockEvent>
for EventHandler<
Expand Down Expand Up @@ -246,8 +248,8 @@ async fn handle_intent_requested_event<
EthereumIntentExecutorT: IntentExecutor + Send + Sync,
SolanaIntentExecutorT: IntentExecutor + Send + Sync,
KeyStoreT: KeyStore<SecretKeyBytes> + Send + Sync,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId> + Send + Sync,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, RpcClient> + Send + Sync,
RpcClient: SubstrateRpcClient<ChainConfig::AccountId, ChainConfig::Header> + Send + Sync,
RpcClientFactory: SubstrateRpcClientFactory<ChainConfig::AccountId, ChainConfig::Header, RpcClient> + Send + Sync,
>(
ethereum_intent_executor: &EthereumIntentExecutorT,
solana_intent_executor: &SolanaIntentExecutorT,
Expand Down
42 changes: 26 additions & 16 deletions tee-worker/omni-executor/parentchain/listener/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,42 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use crate::primitives::{BlockEvent, EventId};
use crate::rpc_client::SubstrateRpcClient;
use crate::rpc_client::SubstrateRpcClientFactory;
use async_trait::async_trait;
use executor_core::fetcher::{EventsFetcher, LastFinalizedBlockNumFetcher};
use log::error;
use parentchain_primitives::{BlockEvent, EventId};
use parentchain_rpc_client::SubstrateRpcClient;
use parentchain_rpc_client::SubstrateRpcClientFactory;
use std::marker::PhantomData;
use std::sync::Arc;

/// Used for fetching data from parentchain
pub struct Fetcher<
AccountId,
RpcClient: SubstrateRpcClient<AccountId>,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, RpcClient>,
Header,
RpcClient: SubstrateRpcClient<AccountId, Header>,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, Header, RpcClient>,
> {
client_factory: Arc<RpcClientFactory>,
client: Option<RpcClient>,
phantom_data: PhantomData<AccountId>,
phantom_account_id: PhantomData<AccountId>,
phantom_header: PhantomData<Header>,
}

impl<
AccountId,
RpcClient: SubstrateRpcClient<AccountId>,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, RpcClient>,
> Fetcher<AccountId, RpcClient, RpcClientFactory>
Header,
RpcClient: SubstrateRpcClient<AccountId, Header>,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, Header, RpcClient>,
> Fetcher<AccountId, Header, RpcClient, RpcClientFactory>
{
pub fn new(client_factory: Arc<RpcClientFactory>) -> Self {
Self { client: None, client_factory, phantom_data: PhantomData }
Self {
client: None,
client_factory,
phantom_account_id: PhantomData,
phantom_header: PhantomData,
}
}

async fn connect_if_needed(&mut self) {
Expand All @@ -57,9 +65,10 @@ impl<
#[async_trait]
impl<
AccountId: Sync + Send,
RpcClient: SubstrateRpcClient<AccountId> + Sync + Send,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, RpcClient> + Sync + Send,
> LastFinalizedBlockNumFetcher for Fetcher<AccountId, RpcClient, RpcClientFactory>
Header: Sync + Send,
RpcClient: SubstrateRpcClient<AccountId, Header> + Sync + Send,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, Header, RpcClient> + Sync + Send,
> LastFinalizedBlockNumFetcher for Fetcher<AccountId, Header, RpcClient, RpcClientFactory>
{
async fn get_last_finalized_block_num(&mut self) -> Result<Option<u64>, ()> {
self.connect_if_needed().await;
Expand All @@ -76,9 +85,10 @@ impl<
#[async_trait]
impl<
AccountId: Sync + Send,
RpcClient: SubstrateRpcClient<AccountId> + Sync + Send,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, RpcClient> + Sync + Send,
> EventsFetcher<EventId, BlockEvent> for Fetcher<AccountId, RpcClient, RpcClientFactory>
Header: Sync + Send,
RpcClient: SubstrateRpcClient<AccountId, Header> + Sync + Send,
RpcClientFactory: SubstrateRpcClientFactory<AccountId, Header, RpcClient> + Sync + Send,
> EventsFetcher<EventId, BlockEvent> for Fetcher<AccountId, Header, RpcClient, RpcClientFactory>
{
async fn get_block_events(&mut self, block_num: u64) -> Result<Vec<BlockEvent>, ()> {
self.connect_if_needed().await;
Expand Down
41 changes: 3 additions & 38 deletions tee-worker/omni-executor/parentchain/listener/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ mod fetcher;
mod key_store;
mod listener;
mod metadata;
mod primitives;
mod rpc_client;
mod sync_checkpoint;
mod transaction_signer;

use crate::event_handler::EventHandler;
use crate::fetcher::Fetcher;
use crate::key_store::SubstrateKeyStore;
use crate::listener::ParentchainListener;
use crate::metadata::SubxtMetadataProvider;
use crate::rpc_client::SubstrateRpcClient;
use crate::rpc_client::{SubxtClient, SubxtClientFactory};
use crate::transaction_signer::TransactionSigner;
use executor_core::intent_executor::IntentExecutor;
use executor_core::key_store::KeyStore;
Expand All @@ -40,48 +37,16 @@ use parentchain_api_interface::{
runtime_types::core_primitives::teebag::types::DcapProvider,
teebag::calls::types::register_enclave::{AttestationType, WorkerMode, WorkerType},
};
use parentchain_rpc_client::SubstrateRpcClient;
use parentchain_rpc_client::{CustomConfig, SubxtClient, SubxtClientFactory};
use parentchain_storage::AccountStoreStorage;
use scale_encode::EncodeAsType;
use std::sync::Arc;
use subxt::config::signed_extensions;
use subxt::Config;
use subxt_core::utils::AccountId32;
use subxt_core::Metadata;
use subxt_signer::sr25519::Keypair;
use tokio::runtime::Handle;
use tokio::sync::oneshot::Receiver;

// We don't need to construct this at runtime,
// so an empty enum is appropriate:
#[derive(EncodeAsType)]
pub enum CustomConfig {}

//todo: adjust if needed
impl Config for CustomConfig {
type Hash = subxt::utils::H256;
type AccountId = subxt::utils::AccountId32;
type Address = subxt::utils::MultiAddress<Self::AccountId, u32>;
type Signature = subxt::utils::MultiSignature;
type Hasher = subxt::config::substrate::BlakeTwo256;
type Header = subxt::config::substrate::SubstrateHeader<u32, Self::Hasher>;
type ExtrinsicParams = signed_extensions::AnyOf<
Self,
(
// Load in the existing signed extensions we're interested in
// (if the extension isn't actually needed it'll just be ignored):
signed_extensions::CheckSpecVersion,
signed_extensions::CheckTxVersion,
signed_extensions::CheckNonce,
signed_extensions::CheckGenesis<Self>,
signed_extensions::CheckMortality<Self>,
signed_extensions::ChargeAssetTxPayment<Self>,
signed_extensions::ChargeTransactionPayment,
signed_extensions::CheckMetadataHash,
),
>;
type AssetId = u32;
}

/// Creates parentchain listener
pub async fn create_listener<EthereumIntentExecutor, SolanaIntentExecutor>(
id: &str,
Expand Down
11 changes: 8 additions & 3 deletions tee-worker/omni-executor/parentchain/listener/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ use crate::event_handler::EventHandler;
use crate::fetcher::Fetcher;
use crate::key_store::SubstrateKeyStore;
use crate::metadata::SubxtMetadataProvider;
use crate::primitives::SyncCheckpoint;
use crate::primitives::{BlockEvent, EventId};
use crate::sync_checkpoint::SyncCheckpoint;
use executor_core::listener::Listener;
use parentchain_primitives::{BlockEvent, EventId};
use subxt::Metadata;
use subxt_core::Config;

Expand All @@ -35,7 +35,12 @@ pub type ParentchainListener<
SolanaIntentExecutor,
AccountStoreStorage,
> = Listener<
Fetcher<<ChainConfig as Config>::AccountId, RpcClient, RpcClientFactory>,
Fetcher<
<ChainConfig as Config>::AccountId,
<ChainConfig as Config>::Header,
RpcClient,
RpcClientFactory,
>,
SyncCheckpoint,
CheckpointRepository,
IntentEventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use crate::rpc_client::{SubstrateRpcClient, SubstrateRpcClientFactory, SubxtClientFactory};
use async_trait::async_trait;
use parentchain_rpc_client::{SubstrateRpcClient, SubstrateRpcClientFactory, SubxtClientFactory};
use parity_scale_codec::Decode;
use subxt::{Config, Metadata};
use subxt_core::utils::AccountId32;
Expand Down
Loading

0 comments on commit 85190ed

Please sign in to comment.