Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions core/parentchain/block-importer/src/block_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ use itp_types::{
use log::*;
use sp_runtime::{
generic::SignedBlock as SignedBlockG,
traits::{Block as ParentchainBlockTrait, NumberFor},
traits::{Block as ParentchainBlockTrait, Header as HeaderT, NumberFor},
};
use std::{marker::PhantomData, sync::Arc, vec::Vec};
use std::{marker::PhantomData, sync::Arc, vec, vec::Vec};

/// Parentchain block import implementation.
pub struct ParentchainBlockImporter<
Expand Down Expand Up @@ -117,15 +117,25 @@ impl<
let mut calls = Vec::<OpaqueCall>::new();
let id = self.validator_accessor.parentchain_id();

debug!("[{:?}] Import blocks to light-client!", id);
debug!(
"[{:?}] Import {} blocks to light-client. event blocks {}",
id,
blocks_to_import.len(),
events_to_import.len()
);
let events_to_import_aligned: Vec<Vec<u8>> = if events_to_import.is_empty() {
vec![vec![]; blocks_to_import.len()]
} else {
events_to_import
};
for (signed_block, raw_events) in
blocks_to_import.into_iter().zip(events_to_import.into_iter())
blocks_to_import.into_iter().zip(events_to_import_aligned.into_iter())
{
if let Err(e) = self
.validator_accessor
.execute_mut_on_validator(|v| v.submit_block(&signed_block))
{
error!("[{:?}] Header submission to light client failed: {:?}", id, e);
error!("[{:?}] Header submission to light client failed for block number {} and hash {:?}: {:?}", id, signed_block.block.header().number(), signed_block.block.hash(), e);

return Err(e.into())
}
Expand Down
8 changes: 8 additions & 0 deletions core/parentchain/light-client/src/light_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use core::iter::Iterator;
use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_storage::{Error as StorageError, StorageProof, StorageProofChecker};
use itp_types::parentchain::{IdentifyParentchain, ParentchainId};
use log::error;
use sp_runtime::{
generic::SignedBlock,
traits::{Block as ParentchainBlockTrait, Header as HeaderTrait},
Expand Down Expand Up @@ -145,6 +146,13 @@ where
let relay = self.light_validation_state.get_relay_mut();

if relay.last_finalized_block_header.hash() != *header.parent_hash() {
error!("header ancestry mismatch! last imported was block nr {:?} with hash {:?}, attempting to import nr {:?} with hash {:?} and ancestor {:?}",
relay.last_finalized_block_header.number(),
relay.last_finalized_block_header.hash(),
header.number(),
header.hash(),
header.parent_hash()
);
return Err(Error::HeaderAncestryMismatch)
}

Expand Down
1 change: 1 addition & 0 deletions enclave-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ pub unsafe extern "C" fn sync_parentchain(
immediate_import == 1,
) {
error!("Error synching parentchain: {:?}", e);
return sgx_status_t::SGX_ERROR_UNEXPECTED
}

sgx_status_t::SGX_SUCCESS
Expand Down
3 changes: 2 additions & 1 deletion service/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
);
info!("The primary worker enclave is {:?}", primary_enclave);
if enclave.get_shard_creation_header(shard).is_err() {
//obtain provisioning from last active worker
//obtain provisioning from last active worker as this hasn't been done before
info!("my state doesn't know the creation header of the shard. will request provisioning");
sync_state::sync_state::<_, _, WorkerModeProvider>(
&integritee_rpc_api,
Expand All @@ -533,6 +533,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
},
None => {
println!("We are the primary worker on this shard and the shard is untouched. Will initialize it");
enclave.init_shard(shard.encode()).unwrap();
enclave
.init_shard_creation_parentchain_header(
shard,
Expand Down
9 changes: 7 additions & 2 deletions service/src/parentchain_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ where
until_synced_header.number + 1,
min(until_synced_header.number + BLOCK_SYNC_BATCH_SIZE, curr_block_number),
)?;
info!("[{:?}] Found {} block(s) to sync in this chunk", id, block_chunk_to_sync.len());
info!(
"[{:?}] Found {} block(s) to sync in this chunk. immediate import={} ",
id,
block_chunk_to_sync.len(),
immediate_import
);
if block_chunk_to_sync.is_empty() {
return Ok(until_synced_header)
}
Expand Down Expand Up @@ -252,7 +257,7 @@ where
.ok_or(Error::EmptyChunk)?;
info!(
"[{:?}] Synced {} out of {} finalized parentchain blocks",
id, until_synced_header.number, curr_block_number,
id, api_client_until_synced_header.number, curr_block_number,
);

// #TODO: #1451: fix api/client types
Expand Down