Skip to content

Commit

Permalink
apply codebase update to bc worker (#2587)
Browse files Browse the repository at this point in the history
* update bitacross to upstream 9a3b032

* fix

---------

Co-authored-by: Kai <7630809+Kailai-Wang@users.noreply.github.com>
  • Loading branch information
kziemianek and Kailai-Wang committed Mar 18, 2024
1 parent ecc010d commit e7423ae
Show file tree
Hide file tree
Showing 128 changed files with 4,004 additions and 9,549 deletions.
9,951 changes: 1,567 additions & 8,384 deletions bitacross-worker/Cargo.lock

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion bitacross-worker/app-libs/parentchain-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ sgx_tstd = { branch = "master", git = "https://github.com/apache/teaclave-sgx-sd
# local dependencies
ita-sgx-runtime = { path = "../sgx-runtime", default-features = false }
ita-stf = { path = "../stf", default-features = false }
itc-parentchain = { path = "../../core/parentchain/parentchain-crate", default-features = false }
itc-parentchain-indirect-calls-executor = { path = "../../core/parentchain/indirect-calls-executor", default-features = false }
itp-api-client-types = { path = "../../core-primitives/node-api/api-client-types", default-features = false }
itp-node-api = { path = "../../core-primitives/node-api", default-features = false }
itp-stf-primitives = { path = "../../core-primitives/stf-primitives", default-features = false }
itp-types = { path = "../../core-primitives/types", default-features = false }
itp-utils = { path = "../../core-primitives/utils", default-features = false }

# no-std compatible libraries
bs58 = { version = "0.4.0", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
log = { version = "0.4", default-features = false }
regex = { optional = true, version = "1.9.5" }

substrate-api-client = { optional = true, default-features = false, features = ["std", "sync-api"], git = "https://github.com/scs/substrate-api-client.git", branch = "polkadot-v0.9.42-tag-v0.14.0" }

# substrate dep
sp-core = { default-features = false, features = ["full_crypto"], git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" }
Expand All @@ -31,6 +36,7 @@ bc-relayer-registry = { path = "../../bitacross/core/bc-relayer-registry", defau
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"
Expand All @@ -41,13 +47,15 @@ itp-test = { path = "../../core-primitives/test" }
itp-top-pool-author = { path = "../../core-primitives/top-pool-author", features = ["mocks"] }
itc-parentchain-test = { path = "../../core/parentchain/test" }


[features]
default = ["std"]
std = [
"bs58/std",
"codec/std",
"ita-sgx-runtime/std",
"ita-stf/std",
"itc-parentchain/std",
"itc-parentchain-indirect-calls-executor/std",
"itp-api-client-types/std",
"itp-node-api/std",
Expand All @@ -56,12 +64,15 @@ std = [
"itp-stf-primitives/std",
"itp-top-pool-author/std",
"itp-types/std",
"itp-utils/std",
"log/std",
#substrate
"regex",
"sp-core/std",
"sp-runtime/std",
"substrate-api-client",
"litentry-primitives/std",
"lc-scheduled-enclave/std",
"sp-std/std",
"bc-relayer-registry/std",
]
sgx = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
Copyright 2021 Integritee AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use itp_api_client_types::ParentchainApi;
use itp_types::parentchain::{BalanceTransfer, ParentchainId};
use substrate_api_client::SubscribeEvents;

pub fn subscribe_to_parentchain_events(api: &ParentchainApi, parentchain_id: ParentchainId) {
println!("[L1Event:{}] Subscribing to selected events", parentchain_id);
let mut subscription = api.subscribe_events().unwrap();
loop {
let events = subscription.next_events_from_metadata().unwrap().unwrap();

for event in events.iter() {
let event = event.unwrap();
match event.pallet_name() {
"System" => continue,
"ParaInclusion" => continue,
"MessageQueue" => continue,
"TransactionPayment" => continue,
"Treasury" => continue,
"Balances" => match event.variant_name() {
"Deposit" => continue,
"Withdraw" => continue,
"Transfer" =>
if let Ok(Some(ev)) = event.as_event::<BalanceTransfer>() {
println!("[L1Event:{}] {:?}", parentchain_id, ev);
},
_ => println!(
"[L1Event:{}] {}::{}",
parentchain_id,
event.pallet_name(),
event.variant_name()
),
},
// TODO(Litentry): add important teebag events?
_ => println!(
"[L1Event:{}] {}::{}",
parentchain_id,
event.pallet_name(),
event.variant_name()
),
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ use codec::{Decode, Encode};
use core::marker::PhantomData;
use itc_parentchain_indirect_calls_executor::hash_of;
use itp_node_api::api_client::{
Address, CallIndex, PairSignature, ParentchainSignedExtra, Signature, UncheckedExtrinsicV4,
Address, CallIndex, PairSignature, Signature, UncheckedExtrinsicV4,
};
use itp_types::H256;

pub struct ExtrinsicParser<SignedExtra> {
_phantom: PhantomData<SignedExtra>,
}

/// Parses the extrinsics corresponding to the parentchain.
pub type ParentchainExtrinsicParser = ExtrinsicParser<ParentchainSignedExtra>;

/// Partially interpreted extrinsic containing the `signature` and the `call_index` whereas
/// the `call_args` remain in encoded form.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// along with Litentry. If not, see <https://www.gnu.org/licenses/>.

use codec::Encode;
use ita_stf::{Getter, TrustedCall, TrustedCallSigned, TrustedOperation};
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use itc_parentchain_indirect_calls_executor::error::{Error, Result};
use itp_stf_primitives::traits::IndirectExecutor;
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_types::{ShardIdentifier, H256};
use sp_core::crypto::AccountId32;
use sp_runtime::MultiAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
*/

pub mod invoke;
mod litentry;
pub mod litentry;
pub mod shield_funds;
pub mod timestamp_set;
pub mod transfer_to_alice_shields_funds;

pub use invoke::InvokeArgs;
pub use litentry::scheduled_enclave::{RemoveScheduledEnclaveArgs, SetScheduledEnclaveArgs};
pub use shield_funds::ShieldFundsArgs;
pub use timestamp_set::TimestampSetArgs;
pub use transfer_to_alice_shields_funds::{TransferToAliceShieldsFundsArgs, ALICE_ACCOUNT_ID};
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use itp_stf_primitives::{
traits::IndirectExecutor,
types::{AccountId, TrustedOperation},
};
use itp_types::{Balance, ShardIdentifier};
use itp_types::{parentchain::ParentchainId, Balance, ShardIdentifier};
use log::{debug, info};
use std::vec::Vec;

/// Arguments of the Integritee-Parachain's shield fund dispatchable.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct ShieldFundsArgs {
Expand All @@ -49,8 +50,12 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
let account = AccountId::decode(&mut account_vec.as_slice())?;

let enclave_account_id = executor.get_enclave_account()?;
let trusted_call =
TrustedCall::balance_shield(enclave_account_id.into(), account, self.amount);
let trusted_call = TrustedCall::balance_shield(
enclave_account_id.into(),
account,
self.amount,
ParentchainId::Litentry,
);
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &self.shard)?;
let trusted_operation =
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2021 Integritee AG and Supercomputing Systems AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

use crate::{Litentry, ParentchainInstance, TargetA, TargetB};
use codec::{Compact, Decode, Encode};
use core::{any::TypeId, marker::PhantomData};
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
IndirectDispatch,
};
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_types::{parentchain::ParentchainId, Moment};
use log::info;

#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
pub struct TimestampSetArgs<I: ParentchainInstance> {
now: Compact<Moment>,
_phantom: PhantomData<I>,
}

impl<Executor: IndirectExecutor<TrustedCallSigned, Error>, I: ParentchainInstance + 'static>
IndirectDispatch<Executor, TrustedCallSigned> for TimestampSetArgs<I>
{
type Args = ();
fn dispatch(&self, executor: &Executor, _args: Self::Args) -> Result<()> {
info!("Found TimestampSet extrinsic in block: now = {:?}", self.now);
let enclave_account_id = executor.get_enclave_account()?;
let parentchain_id = if TypeId::of::<I>() == TypeId::of::<Litentry>() {
ParentchainId::Litentry
} else if TypeId::of::<I>() == TypeId::of::<TargetA>() {
ParentchainId::TargetA
} else if TypeId::of::<I>() == TypeId::of::<TargetB>() {
ParentchainId::TargetB
} else {
return Err(Error::Other("unknown parentchain instance".into()))
};
let trusted_call =
TrustedCall::timestamp_set(enclave_account_id.into(), self.now.0, parentchain_id);
let shard = executor.get_default_shard();
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?;
let trusted_operation =
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call);

let encrypted_trusted_call = executor.encrypt(&trusted_operation.encode())?;
executor.submit_trusted_call(shard, encrypted_trusted_call);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ use itp_stf_primitives::{
traits::IndirectExecutor,
types::{AccountId, TrustedOperation},
};
use itp_types::Balance;
use itp_types::{parentchain::ParentchainId, Balance};
use log::info;
use sp_runtime::MultiAddress;

/// Arguments of a parentchains `transfer` or `transfer_allow_death` dispatchable.
///
/// This is a simple demo indirect call where a transfer to alice on chain will transfer
Expand Down Expand Up @@ -70,6 +71,7 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
executor.get_enclave_account()?.into(),
ALICE_ACCOUNT_ID,
self.value,
ParentchainId::Litentry,
);
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?;
let trusted_operation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ pub use ita_sgx_runtime::{Balance, Index};
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use itc_parentchain_indirect_calls_executor::error::Error;
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_types::parentchain::{AccountId, FilterEvents, HandleParentchainEvents, ParentchainError};
use itp_types::parentchain::{
AccountId, FilterEvents, HandleParentchainEvents, ParentchainError, ParentchainId,
};
use litentry_hex_utils::hex_encode;
use log::*;

Expand All @@ -35,10 +37,12 @@ impl ParentchainEventHandler {
) -> Result<(), Error> {
log::info!("shielding for {:?} amount {}", account, amount,);
let shard = executor.get_default_shard();
// todo: ensure this parentchain is assigned for the shard vault!
let trusted_call = TrustedCall::balance_shield(
executor.get_enclave_account()?.into(),
account.clone(),
amount,
ParentchainId::Litentry,
);
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?;
let trusted_operation =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,39 @@

mod event_filter;
mod event_handler;
mod extrinsic_parser;

use crate::{
decode_and_log_error,
extrinsic_parser::{ExtrinsicParser, ParseExtrinsic},
indirect_calls::{RemoveScheduledEnclaveArgs, SetScheduledEnclaveArgs},
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;
pub use event_handler::ParentchainEventHandler;
pub use extrinsic_parser::ParentchainExtrinsicParser;
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::{
error::{Error, Result},
filter_metadata::FilterIntoDataFrom,
IndirectDispatch,
};
use itp_api_client_types::ParentchainSignedExtra;
use itp_node_api::metadata::NodeMetadataTrait;
use itp_stf_primitives::traits::IndirectExecutor;
pub use itp_types::{
parentchain::{AccountId, Balance, Hash},
CallIndex, H256,
};
use litentry_primitives::Identity;
use log::trace;
use log::*;
use sp_runtime::traits::BlakeTwo256;

pub type BlockNumber = u32;
pub type Header = sp_runtime::generic::Header<BlockNumber, BlakeTwo256>;
pub type Signature = sp_runtime::MultiSignature;

/// Parses the extrinsics corresponding to the parentchain.
pub type ParentchainExtrinsicParser = ExtrinsicParser<ParentchainSignedExtra>;

/// The default indirect call (extrinsic-triggered) of the Integritee-Parachain.
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)]
Expand Down Expand Up @@ -104,18 +114,12 @@ impl<Executor: IndirectExecutor<TrustedCallSigned, Error>>
}
}

/// Default filter we use for the Integritee-Parachain.
pub struct BitAcrossIndirectCallsFilter<ExtrinsicParser> {
_phantom: PhantomData<ExtrinsicParser>,
}
/// Default filter we use for Litentry parachain.
pub struct ExtrinsicFilter {}

impl<ExtrinsicParser, NodeMetadata: NodeMetadataTrait> FilterIntoDataFrom<NodeMetadata>
for BitAcrossIndirectCallsFilter<ExtrinsicParser>
where
ExtrinsicParser: ParseExtrinsic,
{
impl<NodeMetadata: NodeMetadataTrait> FilterIntoDataFrom<NodeMetadata> for ExtrinsicFilter {
type Output = IndirectCall;
type ParseParentchainMetadata = ExtrinsicParser;
type ParseParentchainMetadata = ParentchainExtrinsicParser;

fn filter_into_from_metadata(
encoded_data: &[u8],
Expand All @@ -128,15 +132,13 @@ where
let xt = match Self::ParseParentchainMetadata::parse(call_mut) {
Ok(xt) => xt,
Err(e) => {
log::error!(
"[BitAcrossIndirectCallsFilter] Could not parse parentchain extrinsic: {:?}",
e
);
error!("ExtrinsicFilter: Could not parse parentchain extrinsic: {:?}", e);
return None
},
};
let index = xt.call_index;
let call_args = &mut &xt.call_args[..];
trace!("ExtrinsicFilter: attempting to execute indirect call with index {:?}", index);

if index == metadata.set_scheduled_enclave_call_indexes().ok()? {
let args = decode_and_log_error::<SetScheduledEnclaveArgs>(call_args)?;
Expand Down

0 comments on commit e7423ae

Please sign in to comment.