Skip to content

Commit

Permalink
fix confirm processed parentchain block
Browse files Browse the repository at this point in the history
  • Loading branch information
brenzi committed Aug 3, 2023
1 parent 84b3102 commit 9cba146
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
6 changes: 5 additions & 1 deletion core-primitives/top-pool-author/src/author.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use jsonrpc_core::{
};
use log::*;
use sp_runtime::generic;
use std::{boxed::Box, sync::Arc, vec::Vec};
use std::{boxed::Box, sync::Arc, vec, vec::Vec};

/// Define type of TOP filter that is used in the Author
#[cfg(feature = "sidechain")]
Expand Down Expand Up @@ -319,6 +319,10 @@ where
self.top_pool.shards()
}

fn list_handled_shards(&self) -> Vec<ShardIdentifier> {
self.state_facade.list_shards().unwrap_or(vec![])
}

fn remove_calls_from_pool(
&self,
shard: ShardIdentifier,
Expand Down
5 changes: 5 additions & 0 deletions core-primitives/top-pool-author/src/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ impl AuthorApi<H256, H256> for AuthorApiMock<H256, H256> {
self.tops.read().unwrap().keys().cloned().collect()
}

fn list_handled_shards(&self) -> Vec<ShardIdentifier> {
//dummy
self.tops.read().unwrap().keys().cloned().collect()
}

fn remove_calls_from_pool(
&self,
shard: ShardIdentifier,
Expand Down
4 changes: 4 additions & 0 deletions core-primitives/top-pool-author/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ pub trait AuthorApi<Hash, BlockHash> {
account: &AccountId,
) -> Vec<TrustedOperation>;

/// returns all shards which are currently present in the tops in the pool
fn get_shards(&self) -> Vec<ShardIdentifier>;

/// returns all shards which are handled by our worker
fn list_handled_shards(&self) -> Vec<ShardIdentifier>;

/// Remove a collection of trusted operations from the pool.
/// Return operations that were not successfully removed.
fn remove_calls_from_pool(
Expand Down
15 changes: 6 additions & 9 deletions core/parentchain/indirect-calls-executor/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,13 @@ impl<
meta_data.confirm_processed_parentchain_block_call_indexes()
})??;
let root: H256 = merkle_root::<Keccak256, _>(extrinsics);
let mrenclave = self.stf_enclave_signer.ocall_api.get_mr
let shard = self.top_pool_author.get_shards().get(0).unwrap_or(),
//todo: really use mrenclave here
let mrenclave = ShardIdentifier::default();
let handled_shards = self.top_pool_author.list_handled_shards();
trace!("got handled shards: {:?}", handled_shards);
let shard = handled_shards.get(0).unwrap_or(&mrenclave);
trace!("prepared confirm_processed_parentchain_block() call for block {:?} with index {:?} and merkle root {}", block_number, call, root);
Ok(OpaqueCall::from_tuple(&(
call,
shard,
block_hash,
block_number,
root,
)))
Ok(OpaqueCall::from_tuple(&(call, shard, block_hash, block_number, root)))
}
}

Expand Down
5 changes: 3 additions & 2 deletions service/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

use crate::error::{Error, ServiceResult};
use base58::ToBase58;
use codec::Encode;
use itp_enclave_api::{enclave_base::EnclaveBase, Enclave};
use itp_settings::files::{
Expand Down Expand Up @@ -54,10 +55,10 @@ pub(crate) fn initialize_shard_and_keys(
pub(crate) fn init_shard(enclave: &Enclave, shard_identifier: &ShardIdentifier) {
match enclave.init_shard(shard_identifier.encode()) {
Err(e) => {
println!("Failed to initialize shard {:?}: {:?}", shard_identifier.to_base58(), e);
println!("Failed to initialize shard {:?}: {:?}", shard_identifier.0.to_base58(), e);
},
Ok(_) => {
println!("Successfully initialized shard {:?}", shard_identifier.to_base58());
println!("Successfully initialized shard {:?}", shard_identifier.0.to_base58());
},
}
}
Expand Down

0 comments on commit 9cba146

Please sign in to comment.