diff --git a/core/parentchain/block-importer/src/block_importer.rs b/core/parentchain/block-importer/src/block_importer.rs index d93c19f38e..785e72be30 100644 --- a/core/parentchain/block-importer/src/block_importer.rs +++ b/core/parentchain/block-importer/src/block_importer.rs @@ -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< @@ -117,15 +117,25 @@ impl< let mut calls = Vec::::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> = 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()) } diff --git a/core/parentchain/light-client/src/light_validation.rs b/core/parentchain/light-client/src/light_validation.rs index 5da9db71d6..37d41ba757 100644 --- a/core/parentchain/light-client/src/light_validation.rs +++ b/core/parentchain/light-client/src/light_validation.rs @@ -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}, @@ -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) } diff --git a/enclave-runtime/src/lib.rs b/enclave-runtime/src/lib.rs index 4a4c6f2d16..d055baaf9d 100644 --- a/enclave-runtime/src/lib.rs +++ b/enclave-runtime/src/lib.rs @@ -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 diff --git a/service/src/main_impl.rs b/service/src/main_impl.rs index 1436576d7f..26a4732aa0 100644 --- a/service/src/main_impl.rs +++ b/service/src/main_impl.rs @@ -513,7 +513,7 @@ fn start_worker( ); 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, @@ -533,6 +533,7 @@ fn start_worker( }, 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, diff --git a/service/src/parentchain_handler.rs b/service/src/parentchain_handler.rs index dc1841f9d1..2680297f2a 100644 --- a/service/src/parentchain_handler.rs +++ b/service/src/parentchain_handler.rs @@ -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) } @@ -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