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

Support different Parentchain configs for Integritee, TargetA, TargetB and default to AssetTip for TargetB (aka support Asset Hub) #1652

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

clangenb
Copy link
Contributor

@clangenb clangenb commented Nov 22, 2024

This was mostly accomplished introducing additional type parameters, or generics to support config discrepancies.

Other changes:

  • Remove the concrete ParentchainApi to prevent ambiguities. We explicitly use now IntegriteeRpcApi, TargetARpcApi, TargetBRpcApi`, or just have generic type parameters.

@clangenb clangenb changed the base branch from ab/asset-hub-second-attempt to master November 22, 2024 13:21
@clangenb clangenb added A0-core Affects a core part B1-releasenotes C1-low 📌 Does not elevate a release containing this beyond "low priority" E3-hardmerge PR introduces a lot changes in a lot of files. Requires some effort to merge or rebase to. labels Nov 22, 2024
let account_data = if let Some(data) = api.get_account_data(&accountid).unwrap() {
data
} else {
AccountData::default()
};
let account_data = api.get_account_data(&accountid).unwrap().unwrap_or_default();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have changed the implementation. It returns now, our AccountData instead of the one from the api-client. This simplifies some things.

Comment on lines +31 to +33
pub struct ExtrinsicsFactoryMock<C> {
_phantom: PhantomData<C>,
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't derive default if the concrete type doesn't implement default. This is a well-known rust bug, and we have to implement default manually.

Comment on lines 195 to 224
// // Check if this is an integritee chain and Compose a register_sgx_enclave extrinsic
// if let Ok(ra_renewal) = api.get_constant::<Moment>("Teerex", "MaxAttestationRenewalPeriod") {
// info!("[{:?}] this chain has the teerex pallet. estimating RA fees", parentchain_id);
// let nonce = api.get_nonce_of(accountid)?;
//
// let encoded_xt: Bytes = compose_extrinsic_with_nonce!(
// api,
// nonce,
// TEEREX,
// "register_sgx_enclave",
// vec![0u8; SGX_RA_PROOF_MAX_LEN],
// Some(vec![0u8; MAX_URL_LEN]),
// SgxAttestationMethod::Dcap { proxied: false }
// )
// .encode()
// .into();
// let tx_fee =
// api.get_fee_details(&encoded_xt, None).unwrap().unwrap().inclusion_fee.unwrap();
// let ra_fee = tx_fee.base_fee + tx_fee.len_fee + tx_fee.adjusted_weight_fee;
// info!(
// "[{:?}] one enclave registration costs {:?} and needs to be renewed every {:?}h",
// parentchain_id,
// ra_fee,
// ra_renewal / 1_000 / 3_600
// );
// min_required_funds += 5 * ra_fee;
// } else {
// info!("[{:?}] this chain has no teerex pallet, no need to add RA fees", parentchain_id);
// }

Copy link
Contributor Author

@clangenb clangenb Nov 22, 2024

Choose a reason for hiding this comment

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

This change was from you, what was the plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have reactivated it, as I saw no reason to change the behaviour.

Comment on lines -223 to -257

#[cfg(test)]
mod tests {

use super::*;
use itp_node_api::{
api_client::ParentchainApi,
node_api_factory::{CreateNodeApi, Result as NodeApiResult},
};
use itp_sgx_temp_dir::TempDir;
use mockall::mock;

#[test]
fn given_empty_worker_request_when_submitting_then_return_empty_response() {
mock! {
NodeApiFactory {}
impl CreateNodeApi for NodeApiFactory {
fn create_api(&self) -> NodeApiResult<ParentchainApi>;
}
}

let mock_node_api_factory = Arc::new(MockNodeApiFactory::new());
let temp_dir = TempDir::new().unwrap();
let on_chain_ocall =
WorkerOnChainOCall::new(mock_node_api_factory, None, None, temp_dir.path().into());

let response = on_chain_ocall
.worker_request(Vec::<u8>::new().encode(), ParentchainId::Integritee.encode())
.unwrap();

assert!(!response.is_empty()); // the encoded empty vector is not empty
let decoded_response: Vec<u8> = Decode::decode(&mut response.as_slice()).unwrap();
assert!(decoded_response.is_empty()); // decode the response, and we get an empty vector again
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test is not really meaningful, and with the generics I could no longer use the mock! macro.

rpc::{tungstenite_client::TungsteniteRpcClient, Error as RpcClientError},
};

pub type ParentchainApi = Api<ParentchainRuntimeConfig, TungsteniteRpcClient>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this type to prevent ambiguities. We use IntegriteeApi, TargetAApi, TargetBApi in all cases now, or we are generic over traits.

@clangenb clangenb changed the title WIP asset hub support Support different Parentchain configs for Integritee, TargetA, TargetB and default to AssetTip for TargetB (aka support Asset Hub) Nov 22, 2024
@clangenb clangenb requested a review from brenzi November 22, 2024 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A0-core Affects a core part B1-releasenotes C1-low 📌 Does not elevate a release containing this beyond "low priority" E3-hardmerge PR introduces a lot changes in a lot of files. Requires some effort to merge or rebase to.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants