Skip to content

Commit

Permalink
fix unused
Browse files Browse the repository at this point in the history
  • Loading branch information
Kailai-Wang committed Jun 23, 2024
1 parent cc61660 commit 452570d
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ use bc_relayer_registry::{RelayerRegistry, RelayerRegistryUpdater};
use bc_signer_registry::{SignerRegistry, SignerRegistryUpdater};
use codec::Encode;
use core::str::from_utf8;
use ita_stf::{Getter, TrustedCall, TrustedCallSigned};
use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::error::Error;
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation};
use itp_stf_primitives::traits::IndirectExecutor;
use itp_types::{
parentchain::{
AccountId, FilterEvents, HandleParentchainEvents, ParentchainEventProcessingError,
ParentchainId,
},
parentchain::{FilterEvents, HandleParentchainEvents, ParentchainEventProcessingError},
MrEnclave, WorkerType,
};
use lc_scheduled_enclave::{ScheduledEnclaveUpdater, GLOBAL_SCHEDULED_ENCLAVE};
Expand All @@ -42,38 +39,6 @@ use std::string::ToString;
pub struct ParentchainEventHandler {}

impl ParentchainEventHandler {
fn shield_funds<
Executor: IndirectExecutor<
TrustedCallSigned,
Error,
RelayerRegistry,
SignerRegistry,
EnclaveRegistry,
>,
>(
executor: &Executor,
account: &AccountId,
amount: Balance,
) -> 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 =
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(())
}

fn set_scheduled_enclave(
worker_type: WorkerType,
sbn: SidechainBlockNumber,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::error::Error;
use itp_stf_primitives::traits::IndirectExecutor;
use itp_types::{
parentchain::{AccountId, FilterEvents, HandleParentchainEvents},
parentchain::{FilterEvents, HandleParentchainEvents},
H256,
};
use log::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use ita_stf::TrustedCallSigned;
use itc_parentchain_indirect_calls_executor::error::Error;
use itp_stf_primitives::traits::IndirectExecutor;
use itp_types::{
parentchain::{AccountId, FilterEvents, HandleParentchainEvents},
parentchain::{FilterEvents, HandleParentchainEvents},
H256,
};
use log::*;
Expand Down
7 changes: 2 additions & 5 deletions bitacross-worker/app-libs/stf/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ use crate::ENCLAVE_ACCOUNT_KEY;
use codec::{Decode, Encode};
use ita_sgx_runtime::{ParentchainLitentry, ParentchainTargetA, ParentchainTargetB};
use itp_stf_interface::{BlockMetadata, ShardCreationInfo};
use itp_stf_primitives::{
error::{StfError, StfResult},
types::AccountId,
};
use itp_stf_primitives::error::{StfError, StfResult};
use itp_storage::{storage_double_map_key, storage_map_key, storage_value_key, StorageHasher};
use itp_types::parentchain::ParentchainId;

use itp_utils::stringify::account_id_to_string;
use log::*;
use std::prelude::v1::*;
Expand Down
4 changes: 2 additions & 2 deletions bitacross-worker/app-libs/stf/src/stf_sgx_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{Getter, State, Stf, TrustedCall, TrustedCallSigned};
use ita_sgx_runtime::Runtime;
use itp_node_api::metadata::{metadata_mocks::NodeMetadataMock, provider::NodeMetadataRepository};
use itp_stf_interface::{
parentchain_pallet::ParentchainPalletInstancesInterface, sudo_pallet::SudoPalletInterface,
system_pallet::SystemPalletAccountInterface, InitState, StateCallInterface,
sudo_pallet::SudoPalletInterface, system_pallet::SystemPalletAccountInterface, InitState,
StateCallInterface,
};
use itp_stf_primitives::types::{AccountId, ShardIdentifier};
use itp_types::parentchain::ParentchainId;
Expand Down
12 changes: 6 additions & 6 deletions bitacross-worker/app-libs/stf/src/trusted_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ use crate::{
trusted_call_result::TrustedCallResult,
Getter,
};
use codec::{Compact, Decode, Encode};
use codec::{Decode, Encode};
use frame_support::{ensure, traits::UnfilteredDispatchable};
pub use ita_sgx_runtime::{Balance, Index, Runtime, System};
use itp_node_api::metadata::{provider::AccessNodeMetadata, NodeMetadataTrait};
use itp_node_api_metadata::{pallet_balances::BalancesCallIndexes, pallet_proxy::ProxyCallIndexes};

use itp_stf_interface::ExecuteCall;
use itp_stf_primitives::{
error::StfError,
traits::{TrustedCallSigning, TrustedCallVerification},
types::{AccountId, KeyPair, ShardIdentifier, TrustedOperation},
};
use itp_types::{
parentchain::{ParentchainCall, ParentchainId, ProxyType},
Address, Moment, OpaqueCall, H256,
parentchain::{ParentchainCall, ParentchainId},
Moment, H256,
};
use itp_utils::stringify::account_id_to_string;
pub use litentry_primitives::{
Expand Down Expand Up @@ -197,8 +197,8 @@ where
self,
_shard: &ShardIdentifier,
_top_hash: H256,
calls: &mut Vec<ParentchainCall>,
node_metadata_repo: Arc<NodeMetadataRepository>,
_calls: &mut Vec<ParentchainCall>,
_node_metadata_repo: Arc<NodeMetadataRepository>,
) -> Result<Self::Result, Self::Error> {
let sender = self.call.sender_identity().clone();
let account_id: AccountId = sender.to_account_id().ok_or(Self::Error::InvalidAccount)?;
Expand Down
8 changes: 3 additions & 5 deletions bitacross-worker/bitacross/core/bc-musig2-ceremony/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,8 @@ fn random_seed() -> [u8; 32] {
#[cfg(test)]
pub mod test {
use crate::{
generate_aggregated_public_key, CeremonyCommand, CeremonyError, CeremonyEvent,
MuSig2Ceremony, NonceReceivingErrorReason, SignBitcoinPayload, SignaturePayload, SignerId,
SignersWithKeys,
CeremonyCommand, CeremonyError, CeremonyEvent, MuSig2Ceremony, NonceReceivingErrorReason,
SignBitcoinPayload, SignerId, SignersWithKeys,
};
use alloc::sync::Arc;
use itp_sgx_crypto::{key_repository::AccessKey, schnorr::Pair as SchnorrPair};
Expand All @@ -449,8 +448,7 @@ pub mod test {
sha2::digest::Mac,
};
use litentry_primitives::RequestAesKey;
use musig2::{secp::MaybeScalar, verify_single, PubNonce, SecNonce};
use signature::Verifier;
use musig2::{secp::MaybeScalar, SecNonce};

pub const MY_SIGNER_ID: SignerId = [0u8; 32];

Expand Down
8 changes: 4 additions & 4 deletions bitacross-worker/cli/tests/basic_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ fn test_version() {
init();

let res = Cli::try_parse_from(vec!["placeholder_cli_path", "--version"]);
let err = clap::Error::new(clap::error::ErrorKind::DisplayVersion);
assert!(matches!(res, Err(err)));
let _err = clap::Error::new(clap::error::ErrorKind::DisplayVersion);
assert!(matches!(res, Err(_err)));
}

#[test]
fn test_help() {
init();

let res = Cli::try_parse_from(vec!["placeholder_cli_path", "--help"]);
let err = clap::Error::new(clap::error::ErrorKind::DisplayHelp);
assert!(matches!(res, Err(err)));
let _err = clap::Error::new(clap::error::ErrorKind::DisplayHelp);
assert!(matches!(res, Err(_err)));
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use core::fmt::Debug;
use itc_parentchain::primitives::{ParentchainId, ParentchainInitParams};
use itp_sgx_crypto::{ecdsa, schnorr};
use itp_stf_interface::ShardCreationInfo;
use itp_types::{parentchain::Header, Balance, ShardIdentifier};
use itp_types::{parentchain::Header, ShardIdentifier};
use pallet_teebag::EnclaveFingerprint;
use sgx_crypto_helper::rsa3072::Rsa3072PubKey;
use sp_core::ed25519;
Expand Down Expand Up @@ -105,10 +105,7 @@ mod impl_ffi {
HEADER_MAX_SIZE, MR_ENCLAVE_SIZE, SHIELDING_KEY_SIZE, SIGNING_KEY_SIZE,
};
use itp_stf_interface::ShardCreationInfo;
use itp_types::{
parentchain::{Balance, Header},
ShardIdentifier,
};
use itp_types::{parentchain::Header, ShardIdentifier};
use log::*;
use pallet_teebag::EnclaveFingerprint;
use sgx_crypto_helper::rsa3072::Rsa3072PubKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use itp_stf_primitives::{
};
use itp_stf_state_observer::traits::ObserveState;
use itp_top_pool_author::traits::AuthorApi;
use itp_types::{parentchain::ParentchainId, Index, ShardIdentifier};
use itp_types::{Index, ShardIdentifier};
use log::*;
use sp_core::{ed25519::Pair as Ed25519Pair, Pair};
use std::{boxed::Box, sync::Arc, vec::Vec};
Expand Down
2 changes: 1 addition & 1 deletion bitacross-worker/core-primitives/stf-executor/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use itp_stf_primitives::{
traits::{GetterAuthorization, TrustedCallVerification},
types::TrustedOperation,
};
use itp_types::parentchain::ParentchainId;

#[cfg(feature = "sgx")]
use std::sync::SgxRwLock as RwLock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use itp_stf_primitives::{
traits::TrustedCallSigning,
types::{AccountId, ShardIdentifier, TrustedOperation},
};
use itp_types::{parentchain::ParentchainId, H256};
use itp_types::H256;
use sp_runtime::traits::Header as HeaderTrait;
use std::{time::Duration, vec::Vec};

Expand Down
2 changes: 1 addition & 1 deletion bitacross-worker/core-primitives/stf-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use itp_node_api_metadata::NodeMetadataTrait;
use itp_node_api_metadata_provider::AccessNodeMetadata;
use itp_stf_primitives::traits::TrustedCallVerification;
use itp_types::{
parentchain::{AccountId, BlockHash, BlockNumber, ParentchainCall, ParentchainId},
parentchain::{BlockHash, BlockNumber, ParentchainCall, ParentchainId},
ShardIdentifier, H256,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

use itp_types::parentchain::{AccountId, ParentchainId};
use itp_types::parentchain::ParentchainId;

/// Interface trait of the parentchain pallet.
pub trait ParentchainPalletInstancesInterface<State, ParentchainHeader> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ use itp_test::mock::{
},
};
use itp_top_pool::mocks::trusted_operation_pool_mock::TrustedOperationPoolMock;
use itp_utils::ToHexPrefixed;
use litentry_primitives::BroadcastedRequest;

use sgx_crypto_helper::{rsa3072::Rsa3072KeyPair, RsaKeyPair};
use std::sync::Arc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,9 @@ mod test {
use bc_relayer_registry::RelayerRegistry;
use bc_signer_registry::SignerRegistry;
use codec::Encode;
use itc_parentchain_test::ParentchainBlockBuilder;

use itp_node_api::{
api_client::{
ExtrinsicParams, ParentchainAdditionalParams, ParentchainExtrinsicParams,
ParentchainUncheckedExtrinsic,
},
api_client::ExtrinsicParams,
metadata::{metadata_mocks::NodeMetadataMock, provider::NodeMetadataRepository},
};
use itp_sgx_crypto::mocks::KeyRepositoryMock;
Expand All @@ -335,9 +332,7 @@ mod test {
stf_mock::{GetterMock, TrustedCallSignedMock},
};
use itp_top_pool_author::mocks::AuthorApiMock;
use itp_types::{Block, Enclave, PostOpaqueTaskFn, RsaRequest, ShardIdentifier};
use sp_core::{ed25519, Pair};
use sp_runtime::{MultiAddress, MultiSignature, OpaqueExtrinsic};
use itp_types::Block;

type TestShieldingKeyRepo = KeyRepositoryMock<ShieldingCryptoMock>;
type TestStfEnclaveSigner = StfEnclaveSignerMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ use crate::{
EnclaveBitcoinKeyRepository, EnclaveEthereumKeyRepository, EnclaveSigningKeyRepository,
},
std::string::ToString,
utils::{
get_stf_enclave_signer_from_solo_or_parachain,
get_validator_accessor_from_integritee_solo_or_parachain,
},
utils::get_validator_accessor_from_integritee_solo_or_parachain,
};
use bc_musig2_ceremony::{generate_aggregated_public_key, PublicKey};
use bc_signer_registry::SignerRegistryLookup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use itp_sgx_crypto::{
use itp_sgx_externalities::SgxExternalities;
use itp_stf_executor::{enclave_signer::StfEnclaveSigner, traits::StfEnclaveSigning};
use itp_stf_interface::{
mocks::GetterExecutorMock, parentchain_pallet::ParentchainPalletInstancesInterface,
system_pallet::SystemPalletAccountInterface, InitState, StateCallInterface,
mocks::GetterExecutorMock, system_pallet::SystemPalletAccountInterface, InitState,
StateCallInterface,
};
use itp_stf_primitives::{
traits::TrustedCallVerification,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
*/

use super::test_setup::TestStf;
use ita_stf::{stf_sgx_tests::StfState, State};
use ita_stf::State;
use itp_sgx_externalities::{SgxExternalities, SgxExternalitiesTrait};
use itp_stf_interface::{parentchain_pallet::ParentchainPalletInstancesInterface, InitState};
use itp_stf_interface::InitState;
use itp_stf_primitives::types::AccountId;
use itp_stf_state_handler::handle_state::HandleState;
use itp_types::{parentchain::ParentchainId, ShardIdentifier};
use itp_types::ShardIdentifier;

/// Returns an empty `State` with the corresponding `ShardIdentifier`.
pub fn init_state<S: HandleState<StateT = SgxExternalities>>(
Expand Down
56 changes: 2 additions & 54 deletions bitacross-worker/enclave-runtime/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
use crate::{
error::{Error, Result},
initialization::global_components::{
EnclaveExtrinsicsFactory, EnclaveNodeMetadataRepository, EnclaveStfEnclaveSigner,
EnclaveValidatorAccessor, GLOBAL_INTEGRITEE_PARACHAIN_HANDLER_COMPONENT,
EnclaveExtrinsicsFactory, EnclaveNodeMetadataRepository, EnclaveValidatorAccessor,
GLOBAL_INTEGRITEE_PARACHAIN_HANDLER_COMPONENT,
GLOBAL_INTEGRITEE_SOLOCHAIN_HANDLER_COMPONENT, GLOBAL_TARGET_A_PARACHAIN_HANDLER_COMPONENT,
GLOBAL_TARGET_A_SOLOCHAIN_HANDLER_COMPONENT, GLOBAL_TARGET_B_PARACHAIN_HANDLER_COMPONENT,
GLOBAL_TARGET_B_SOLOCHAIN_HANDLER_COMPONENT,
},
};
use codec::{Decode, Input};
use itc_parentchain_block_import_dispatcher::BlockImportDispatcher;
use itp_component_container::ComponentGetter;
use std::{result::Result as StdResult, slice, sync::Arc};

Expand Down Expand Up @@ -125,54 +124,3 @@ pub(crate) fn get_extrinsic_factory_from_integritee_solo_or_parachain(
};
Ok(extrinsics_factory)
}

pub(crate) fn get_extrinsic_factory_from_target_a_solo_or_parachain(
) -> Result<Arc<EnclaveExtrinsicsFactory>> {
let extrinsics_factory =
if let Ok(solochain_handler) = GLOBAL_TARGET_A_SOLOCHAIN_HANDLER_COMPONENT.get() {
solochain_handler.extrinsics_factory.clone()
} else if let Ok(parachain_handler) = GLOBAL_TARGET_A_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.extrinsics_factory.clone()
} else {
return Err(Error::NoTargetAParentchainAssigned)
};
Ok(extrinsics_factory)
}

pub(crate) fn get_extrinsic_factory_from_target_b_solo_or_parachain(
) -> Result<Arc<EnclaveExtrinsicsFactory>> {
let extrinsics_factory =
if let Ok(solochain_handler) = GLOBAL_TARGET_B_SOLOCHAIN_HANDLER_COMPONENT.get() {
solochain_handler.extrinsics_factory.clone()
} else if let Ok(parachain_handler) = GLOBAL_TARGET_B_PARACHAIN_HANDLER_COMPONENT.get() {
parachain_handler.extrinsics_factory.clone()
} else {
return Err(Error::NoTargetBParentchainAssigned)
};
Ok(extrinsics_factory)
}

pub(crate) fn get_stf_enclave_signer_from_solo_or_parachain() -> Result<Arc<EnclaveStfEnclaveSigner>>
{
let stf_enclave_signer =
if let Ok(solochain_handler) = GLOBAL_INTEGRITEE_SOLOCHAIN_HANDLER_COMPONENT.get() {
match &*solochain_handler.import_dispatcher {
BlockImportDispatcher::TriggeredDispatcher(dispatcher) =>
dispatcher.block_importer.indirect_calls_executor.stf_enclave_signer.clone(),
BlockImportDispatcher::ImmediateDispatcher(dispatcher) =>
dispatcher.block_importer.indirect_calls_executor.stf_enclave_signer.clone(),
_ => return Err(Error::NoLitentryParentchainAssigned),
}
} else if let Ok(parachain_handler) = GLOBAL_INTEGRITEE_PARACHAIN_HANDLER_COMPONENT.get() {
match &*parachain_handler.import_dispatcher {
BlockImportDispatcher::TriggeredDispatcher(dispatcher) =>
dispatcher.block_importer.indirect_calls_executor.stf_enclave_signer.clone(),
BlockImportDispatcher::ImmediateDispatcher(dispatcher) =>
dispatcher.block_importer.indirect_calls_executor.stf_enclave_signer.clone(),
_ => return Err(Error::NoLitentryParentchainAssigned),
}
} else {
return Err(Error::NoLitentryParentchainAssigned)
};
Ok(stf_enclave_signer)
}

0 comments on commit 452570d

Please sign in to comment.