Skip to content

Commit

Permalink
Merge pull request #12 from capsule-corp-ternoa/rtu-fix
Browse files Browse the repository at this point in the history
Mainnet minor fixes
  • Loading branch information
peshwar9 authored Nov 8, 2023
2 parents 269c8f3 + 9239b27 commit 87a20fa
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sgx_server"
version ="0.4.4"
version ="0.4.5"
edition = "2021"

[[bin]]
Expand Down
9 changes: 7 additions & 2 deletions src/backup/admin_bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
servers::state::{
get_blocknumber, get_clusters, reset_nft_availability, set_keypair, SharedState,
StateConfig,
},
}, backup::sync::cluster_discovery,
};

use super::{
Expand Down Expand Up @@ -794,7 +794,12 @@ pub async fn admin_backup_push_bulk(
debug!("ADMIN PUSH BULK : Keypair success");

set_keypair(&state, enclave_keypair).await;
debug!("share-state Enclave Account updated");
debug!("ADMIN PUSH BULK : share-state Enclave Account updated");

match cluster_discovery(&state).await {
Ok(res) => debug!("ADMIN PUSH BULK : CLUSTER DISCOVERY FOR NEW IDENTITY : {res}"),
Err(err) => error!("ADMIN PUSH BULK : CLUSTER DISCOVERY FAILED : {err}"),
}

//update_health_status(&state, String::new()).await;
let keyshare_list: BTreeMap<u32, helper::Availability> =
Expand Down
30 changes: 25 additions & 5 deletions src/backup/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ pub async fn fetch_keyshares(

// Crawl and parse registered clusters and enclaves from on-chain data
pub async fn cluster_discovery(state: &SharedState) -> Result<bool, anyhow::Error> {
debug!("CLUSTER DISCOVERY : get api");
debug!("\n***CLUSTER DISCOVERY***\n");
let api = get_chain_api(state).await;

let max_cluster_address = ternoa::storage().tee().next_cluster_id();
Expand Down Expand Up @@ -1741,9 +1741,29 @@ pub async fn parse_block_body(

// For all extrinsics in the block body
for ext in body.extrinsics().iter() {
let ext = ext?;
let pallet = ext.pallet_name()?;
let call = ext.variant_name()?;
let ext = match ext {
Ok(ext) => ext,
Err(err) => {
error!("BLOCK-PARSER : ERROR Parsing extrinsic in block.{block_number} : {err:?}");
continue
},
};

let pallet = match ext.pallet_name() {
Ok(pallet) => pallet,
Err(err) => {
error!("BLOCK-PARSER : ERROR Parsing pallet in block.{block_number} : {err:?}");
continue
},
};

let call = match ext.variant_name() {
Ok(call) => call,
Err(err) => {
error!("BLOCK-PARSER : ERROR Parsing call variant in block.{block_number} : {err:?}");
continue
},
};
//debug!(" - crawler extrinsic = {} : {}", pallet, call);

match pallet.to_uppercase().as_str() {
Expand Down Expand Up @@ -2478,7 +2498,7 @@ mod test {
.unwrap();

// Analyze the Response
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
let body = hyper::body::to_bytes(response.into_body()).await.unwrap();
let body: Value = serde_json::from_slice(&body).unwrap();
println!("Health Check Result: {:#?}", body);
Expand Down
2 changes: 1 addition & 1 deletion src/chain/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const VERSION: &str = "0.4.4";
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const ATTESTATION_SERVER_URL: &str = if cfg!(feature = "alphanet") {
// PRODUCTION-KEY when binary is built by github
"https://alphanet-attestation.ternoa.network/attest"
Expand Down
22 changes: 13 additions & 9 deletions src/servers/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,18 @@ pub async fn http_server() -> Result<Router, Error> {
// Get all cluster and registered enclaves from the chain
// Also checks if this enclave has been registered.
info!("ENCLAVE START : Initialization Cluster Discovery.");
while let Err(err) = cluster_discovery(&state_config.clone()).await {
error!("ENCLAVE START : cluster discovery error : {err:?}");
debug!("ENCLAVE START : Retry Cluster Discovery after a delay...");
std::thread::sleep(std::time::Duration::from_secs(RETRY_DELAY.into()));
//while let Err(err) = cluster_discovery(&state_config.clone()).await {
for _retry in 0..RETRY_COUNT {
if let Err(err) = cluster_discovery(&state_config.clone()).await {
error!("ENCLAVE START : cluster discovery error : {err:?}");
debug!("ENCLAVE START : Retry Cluster Discovery after a delay...");
std::thread::sleep(std::time::Duration::from_secs(RETRY_DELAY.into()));
}else{
info!("ENCLAVE START : Cluster Discovery Successful.");
break
}
}

info!("ENCLAVE START : Cluster Discovery successfull.");

// Check the previous Sync-State
info!("ENCLAVE START : check for sync.state file from previous run ...");
if std::path::Path::new(&SYNC_STATE_FILE).exists() {
Expand Down Expand Up @@ -504,7 +508,7 @@ pub async fn http_server() -> Result<Router, Error> {

// Cluster discovery Error
Err(err) => {
error!("\t > Error during running-mode cluster discovery {err:?}");
error!("\t > Error during running-mode cluster-discovery {err:?}");
// TODO [decision] : Integrity of clusters is corrupted. what to do? Going
// to maintenace mode and stop serving to API calls? Wipe?
continue
Expand Down Expand Up @@ -614,9 +618,9 @@ pub async fn http_server() -> Result<Router, Error> {
// Non Numeric SyncState file content:
if block_number % 10 == 0 {
if get_identity(&state_config).await.is_none() {
debug!("\t <<< Enclave has is not registered >>>");
debug!("\t <<< Enclave is not registered >>>");
} else {
debug!("\t <<< Enclave has never Synced >>>");
debug!("\t <<< Enclave is never Synced >>>");
}
}
// Prevent Crawling after first registration
Expand Down

0 comments on commit 87a20fa

Please sign in to comment.