Skip to content

Commit

Permalink
Parachain pallet-bitacross implementation (#2471)
Browse files Browse the repository at this point in the history
* fix: add extrinsic and parsing for indirect executor

* fix: seal unseal operations for GLOBAL RELAYER REGISTRY

* fix: update indirect executor to update Relayer Registry

* feat: add relayer account type

* debug: misc

* debug: fix event

* debug: change pallet folder name

* debug: fmt

* debug: using existing struct

* debug: fmt

* pallet-bitacross skeleton

* runtime integration

* some more update

* fix: update indirect call executor and registry to use Identity instead of AccountId

* fix: clippy

* refactor: remove accidental commit

* refactor: remove error log

* refactor: remove comments

---------

Co-authored-by: Minqi Wang <wangminqi@aliyun.com>
Co-authored-by: WMQ <46511820+wangminqi@users.noreply.github.com>
Co-authored-by: Kailai Wang <Kailai.Wang@hotmail.com>
  • Loading branch information
4 people committed Feb 11, 2024
1 parent 9bd0002 commit 5ce842f
Show file tree
Hide file tree
Showing 24 changed files with 712 additions and 127 deletions.
4 changes: 0 additions & 4 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
members = [
'node',
'pallets/account-fix',
'pallets/bitacross',
'pallets/bridge',
'pallets/bridge-transfer',
'pallets/drop3',
Expand All @@ -17,7 +18,7 @@ members = [
'pallets/parentchain',
'pallets/test-utils',
'pallets/group',
'pallets/bitacross-pallet',
'pallets/bitacross',
'precompiles/*',
'primitives/common',
'primitives/core',
Expand Down
45 changes: 43 additions & 2 deletions bitacross-worker/Cargo.lock

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

1 change: 1 addition & 0 deletions bitacross-worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ members = [
"litentry/core/direct-call",
"bitacross/core/bc-task-receiver",
"bitacross/core/bc-task-sender",
"bitacross/core/bc-relayer-registry",
]

[patch."https://github.com/apache/teaclave-sgx-sdk.git"]
Expand Down
4 changes: 4 additions & 0 deletions bitacross-worker/app-libs/parentchain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ sp-core = { default-features = false, features = ["full_crypto"], git = "https:/
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }

# litentry
bc-relayer-registry = { path = "../../bitacross/core/bc-relayer-registry", default-features = false }
lc-scheduled-enclave = { path = "../../litentry/core/scheduled-enclave", default-features = false, optional = true }
litentry-hex-utils = { path = "../../../primitives/hex", default-features = false }
litentry-primitives = { path = "../../litentry/primitives", default-features = false }
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }


[dev-dependencies]
env_logger = "0.9.0"
itp-node-api = { path = "../../core-primitives/node-api", features = ["mocks"] }
Expand Down Expand Up @@ -66,6 +68,7 @@ std = [
"litentry-primitives/std",
"lc-scheduled-enclave/std",
"sp-std/std",
"bc-relayer-registry/std",
]
sgx = [
"sgx_tstd",
Expand All @@ -77,4 +80,5 @@ sgx = [
"itp-top-pool-author/sgx",
"litentry-primitives/sgx",
"lc-scheduled-enclave/sgx",
"bc-relayer-registry/sgx",
]
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
indirect_calls::{RemoveScheduledEnclaveArgs, UpdateScheduledEnclaveArgs},
integritee::extrinsic_parser::ParseExtrinsic,
};
use bc_relayer_registry::{RelayerRegistryUpdater, GLOBAL_RELAYER_REGISTRY};
use codec::{Decode, Encode};
use core::marker::PhantomData;
pub use event_filter::FilterableEvents;
Expand All @@ -37,6 +38,7 @@ use itc_parentchain_indirect_calls_executor::{
};
use itp_node_api::metadata::NodeMetadataTrait;
use itp_stf_primitives::traits::IndirectExecutor;
use litentry_primitives::Identity;
use log::trace;
use sp_core::crypto::AccountId32;

Expand All @@ -49,6 +51,10 @@ pub enum IndirectCall {
UpdateScheduledEnclave(UpdateScheduledEnclaveArgs),
#[codec(index = 2)]
RemoveScheduledEnclave(RemoveScheduledEnclaveArgs),
#[codec(index = 3)]
AddRelayer(AddRelayerArgs),
#[codec(index = 4)]
RemoveRelayer(RemoveRelayerArgs),
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
Expand All @@ -63,6 +69,9 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
update_scheduled_enclave_args.dispatch(executor, ()),
IndirectCall::RemoveScheduledEnclave(remove_scheduled_enclave_args) =>
remove_scheduled_enclave_args.dispatch(executor, ()),
IndirectCall::AddRelayer(add_relayer_args) => add_relayer_args.dispatch(executor, ()),
IndirectCall::RemoveRelayer(remove_relayer_args) =>
remove_relayer_args.dispatch(executor, ()),
}
}
}
Expand All @@ -82,6 +91,38 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
}
}

#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct AddRelayerArgs {
account_id: Identity,
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
IndirectDispatch<Executor, TrustedCallSigned> for AddRelayerArgs
{
type Args = ();
fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> {
log::info!("Adding Relayer Account to Registry: {:?}", self.account_id);
GLOBAL_RELAYER_REGISTRY.update(self.account_id.clone()).unwrap();
Ok(())
}
}

#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct RemoveRelayerArgs {
account_id: Identity,
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
IndirectDispatch<Executor, TrustedCallSigned> for RemoveRelayerArgs
{
type Args = ();
fn dispatch(&self, _executor: &Executor, _args: Self::Args) -> Result<()> {
log::info!("Remove Relayer Account from Registry: {:?}", self.account_id);
GLOBAL_RELAYER_REGISTRY.remove(self.account_id.clone()).unwrap();
Ok(())
}
}

/// Default filter we use for the Integritee-Parachain.
pub struct BitAcrossIndirectCallsFilter<ExtrinsicParser> {
_phantom: PhantomData<ExtrinsicParser>,
Expand Down Expand Up @@ -116,15 +157,20 @@ where
let index = xt.call_index;
let call_args = &mut &xt.call_args[..];

if index == metadata.placeholder_call_indexes().ok()? {
let args = decode_and_log_error::<BitAcrossArgs>(call_args)?;
Some(IndirectCall::BitAcross(args))
} else if index == metadata.update_scheduled_enclave().ok()? {
if index == metadata.update_scheduled_enclave().ok()? {
let args = decode_and_log_error::<UpdateScheduledEnclaveArgs>(call_args)?;
Some(IndirectCall::UpdateScheduledEnclave(args))
} else if index == metadata.remove_scheduled_enclave().ok()? {
let args = decode_and_log_error::<RemoveScheduledEnclaveArgs>(call_args)?;
Some(IndirectCall::RemoveScheduledEnclave(args))
} else if index == metadata.add_relayer_call_indexes().ok()? {
log::error!("Received Add Relayer indirect call");
let args = decode_and_log_error::<AddRelayerArgs>(call_args)?;
Some(IndirectCall::AddRelayer(args))
} else if index == metadata.remove_relayer_call_indexes().ok()? {
log::error!("Processing Remove Relayer Call");
let args = decode_and_log_error::<RemoveRelayerArgs>(call_args)?;
Some(IndirectCall::RemoveRelayer(args))
} else {
None
}
Expand Down
83 changes: 83 additions & 0 deletions bitacross-worker/bitacross/core/bc-relayer-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[package]
name = "bc-relayer-registry"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitcoin = { version = "0.31.0", default-features = false, features = ["secp-recovery", "no-std"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
hex = { version = "0.4.3", default-features = false }
lazy_static = { version = "1.1.0", features = ["spin_no_std"] }
log = { version = "0.4", default-features = false }
pallet-evm = { default-features = false, git = "https://github.com/integritee-network/frontier.git", branch = "bar/polkadot-v0.9.42" }
rand = { version = "0.7", optional = true }
rand-sgx = { package = "rand", git = "https://github.com/mesalock-linux/rand-sgx", tag = "sgx_1.1.3", features = ["sgx_tstd"], optional = true }
ring = { version = "0.16.20", default-features = false }
scale-info = { version = "2.4.0", default-features = false, features = ["derive"] }
secp256k1 = { version = "0.28.0", default-features = false }
serde = { version = "1.0", default-features = false, features = ["alloc", "derive"] }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42", default-features = false }
strum = { version = "0.26", default-features = false }
strum_macros = { version = "0.26", default-features = false }
thiserror = { version = "1.0.26", optional = true }


# sgx dependencies
base64_sgx = { package = "base64", rev = "sgx_1.1.3", git = "https://github.com/mesalock-linux/rust-base64-sgx", optional = true }
sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git", branch = "master", optional = true, features = ["net", "thread"] }
thiserror-sgx = { package = "thiserror", git = "https://github.com/mesalock-linux/thiserror-sgx", tag = "sgx_1.1.3", optional = true }


# internal dependencies
itp-settings = { path = "../../../core-primitives/settings", default-features = false }
itp-sgx-crypto = { path = "../../../core-primitives/sgx/crypto", default-features = false }
itp-sgx-io = { path = "../../../core-primitives/sgx/io", default-features = false }
itp-utils = { path = "../../../core-primitives/utils", default-features = false }
litentry-hex-utils = { path = "../../../../primitives/hex", default-features = false }
parentchain-primitives = { package = "core-primitives", path = "../../../../primitives/core", default-features = false }
teerex-primitives = { path = "../../../../primitives/teerex", default-features = false }
# litentry primities
litentry-primitives = { path = "../../../litentry/primitives", default-features = false }

[dev-dependencies]
base64 = { version = "0.13", features = ["alloc"] }

[features]
default = ["std"]
production = [
"parentchain-primitives/production",
]
sgx = [
"sgx_tstd",
"rand-sgx",
"itp-sgx-crypto/sgx",
"thiserror-sgx",
"itp-sgx-io/sgx",
"litentry-primitives/sgx",
]
std = [
"strum/std",
"hex/std",
"serde/std",
"itp-sgx-crypto/std",
"itp-utils/std",
"sp-core/std",
"sp-std/std",
"sp-io/std",
"sp-runtime/std",
"ring/std",
"parentchain-primitives/std",
"teerex-primitives/std",
"rand",
"log/std",
"bitcoin/std",
"secp256k1/std",
"thiserror",
"itp-sgx-io/std",
"litentry-primitives/std",
]

0 comments on commit 5ce842f

Please sign in to comment.