Skip to content

Commit

Permalink
pimp logging
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Jul 19, 2023
1 parent 0494ffb commit de2dda2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
12 changes: 6 additions & 6 deletions cli/src/base_cli/commands/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use log::*;
use my_node_runtime::Balance;
use sp_core::{crypto::Ss58Codec, sr25519 as sr25519_core, Pair};
use substrate_api_client::{
extrinsic::BalancesExtrinsics, GetAccountInformation, SubmitAndWatch, XtStatus,
extrinsic::BalancesExtrinsics, GetAccountInformation, SubmitAndWatchUntilSuccess,
};

#[derive(Parser)]
Expand All @@ -48,11 +48,11 @@ impl TransferCommand {
let mut api = get_chain_api(cli);
api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(from_account)));
let xt = api.balance_transfer_allow_death(Address::Id(to_account.clone()), self.amount);
let tx_hash = api
.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock)
.unwrap()
.extrinsic_hash;
println!("[+] TrustedOperation got finalized. Hash: {:?}\n", tx_hash);
let tx_report = api.submit_and_watch_extrinsic_until_success(xt, false).unwrap();
println!(
"[+] L1 extrinsic success. extrinsic hash: {:?} / status: {:?}",
tx_report.extrinsic_hash, tx_report.status
);
let result = api.get_account_data(&to_account).unwrap().unwrap();
let balance = result.free;
println!("balance for {} is now {}", to_account, balance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ use sgx_tcrypto::{rsgx_sha256_slice, SgxEccHandle};
use sgx_tse::{rsgx_create_report, rsgx_verify_report};
use sgx_types::{
c_int, sgx_epid_group_id_t, sgx_quote_nonce_t, sgx_quote_sign_type_t, sgx_report_data_t,
sgx_spid_t, sgx_status_t, sgx_status_t::SGX_ERROR_UNEXPECTED, sgx_target_info_t, SgxResult, *,
sgx_spid_t, sgx_status_t, sgx_target_info_t, SgxResult, *,
};
use sp_core::{ed25519, Pair};
use std::{
Expand Down Expand Up @@ -678,7 +678,7 @@ where
.map_err(|e| EnclaveError::Other(e.into()))
}

/// Returns Ok if the verification of the quote by the quote verification enclave (QVE) was successful
/// Returns Ok if the verification of the quote by the quote verification enclave (QVE) was successful
pub fn ecdsa_quote_verification(&self, quote: Vec<u8>) -> SgxResult<()> {
let mut app_enclave_target_info: sgx_target_info_t = unsafe { std::mem::zeroed() };
let quote_collateral: sgx_ql_qve_collateral_t = unsafe { std::mem::zeroed() };
Expand Down
4 changes: 2 additions & 2 deletions core-primitives/attestation-handler/src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,11 @@ where
// Obtain Netscape Comment
offset += 1;
let mut payload = cert_der[offset..offset + len].to_vec();
println!("payload in mra cert verifier is: {:#?}", &payload);
trace!("payload in mra cert verifier is: {:?}", &payload);
if is_payload_base64_encoded {
payload = base64::decode(&payload[..]).or(Err(sgx_status_t::SGX_ERROR_UNEXPECTED))?;
}
println!("payload in mra cert verifier is: {:#?}", &payload);
trace!("payload in mra cert verifier is: {:?}", &payload);
if !is_dcap {
// Extract each field
let mut iter = payload.split(|x| *x == b'|');
Expand Down
11 changes: 5 additions & 6 deletions service/src/account_funding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use sp_core::{
use sp_keyring::AccountKeyring;
use sp_runtime::MultiAddress;
use substrate_api_client::{
extrinsic::BalancesExtrinsics, GetBalance, GetTransactionPayment, SubmitAndWatch, XtStatus,
extrinsic::BalancesExtrinsics, GetBalance, GetTransactionPayment, SubmitAndWatchUntilSuccess,
};

/// Information about the enclave on-chain account.
Expand Down Expand Up @@ -155,15 +155,14 @@ fn bootstrap_funds_from_alice(
let mut alice_signer_api = api.clone();
alice_signer_api.set_signer(ParentchainExtrinsicSigner::new(alice));

println!("[+] bootstrap funding Enclave from Alice's funds");
println!("[+] send extrinsic: bootstrap funding Enclave from Alice's funds");
let xt = alice_signer_api
.balance_transfer_allow_death(MultiAddress::Id(accountid.clone()), funding_amount);
let xt_report = alice_signer_api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock)?;
let xt_report = alice_signer_api.submit_and_watch_extrinsic_until_success(xt, false)?;
info!(
"[<] Extrinsic got included in a block. Extrinsic Hash: {:?}\n",
xt_report.extrinsic_hash
"[<] L1 extrinsic success. extrinsic hash: {:?} / status: {:?}",
xt_report.extrinsic_hash, xt_report.status
);

// Verify funds have arrived.
let free_balance = alice_signer_api.get_free_balance(accountid);
info!("TEE's NEW free balance = {:?}", free_balance);
Expand Down
21 changes: 15 additions & 6 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
let register_xt = move || enclave2.generate_dcap_ra_extrinsic(&trusted_url, skip_ra).unwrap();

let send_register_xt = move || {
println!("[+] Send register enclave extrinsic");
send_extrinsic(register_xt(), &node_api2, &tee_accountid.clone(), is_development_mode)
};

Expand Down Expand Up @@ -814,20 +815,23 @@ fn send_extrinsic(
accountid: &AccountId32,
is_development_mode: bool,
) -> Option<Hash> {
// Account funds
// ensure account funds
if let Err(x) = setup_account_funding(api, accountid, extrinsic.clone(), is_development_mode) {
error!("Starting worker failed: {:?}", x);
error!("Ensure enclave funding failed: {:?}", x);
// Return without registering the enclave. This will fail and the transaction will be banned for 30min.
return None
}

println!("[>] send extrinsic");
info!("[>] send extrinsic");
trace!(" encoded extrinsic: 0x{:}", hex::encode(extrinsic.clone()));

match api.submit_and_watch_opaque_extrinsic_until_success(extrinsic.into(), true) {
Ok(xt_report) => {
let register_qe_block_hash = xt_report.block_hash;
println!("[<] Extrinsic got finalized. Block hash: {:?}\n", register_qe_block_hash);
register_qe_block_hash
info!(
"[+] L1 extrinsic success. extrinsic hash: {:?} / status: {:?}",
xt_report.extrinsic_hash, xt_report.status
);
xt_report.block_hash
},
Err(e) => {
error!("ExtrinsicFailed {:?}", e);
Expand Down Expand Up @@ -878,5 +882,10 @@ fn we_are_primary_validateer(
) -> Result<bool, Error> {
let enclave_count_of_previous_block =
node_api.enclave_count(Some(*register_enclave_xt_header.parent_hash()))?;
println!(
"enclave count is {} for previous block 0x{:?}",
enclave_count_of_previous_block,
register_enclave_xt_header.parent_hash()
);
Ok(enclave_count_of_previous_block == 0)
}

0 comments on commit de2dda2

Please sign in to comment.