= ::Public;
type ShardIdentifierFor =
<<::Block as SidechainBlockTrait>::HeaderType as HeaderTrait>::ShardIdentifier;
-impl
- SimpleSlotWorker
- for Aura
-where
+impl<
+ AuthorityPair,
+ ParentchainBlock,
+ SignedSidechainBlock,
+ E,
+ OcallApi,
+ ImportTrigger,
+ Updater,
+ StateHandler,
+ > SimpleSlotWorker
+ for Aura<
+ AuthorityPair,
+ ParentchainBlock,
+ SignedSidechainBlock,
+ E,
+ OcallApi,
+ ImportTrigger,
+ Updater,
+ StateHandler,
+ > where
AuthorityPair: Pair,
// todo: Relax hash trait bound, but this needs a change to some other parts in the code.
ParentchainBlock: ParentchainBlockTrait,
@@ -132,11 +176,15 @@ where
OcallApi: ValidateerFetch + EnclaveOnChainOCallApi + Send + 'static,
ImportTrigger:
TriggerParentchainBlockImport>,
+ Updater: UpdaterTrait,
+ StateHandler: HandleState,
{
type Proposer = E::Proposer;
type Claim = AuthorityPair::Public;
type EpochData = Vec>;
type Output = SignedSidechainBlock;
+ type Updater = Updater;
+ type StateHandler = StateHandler;
fn logging_target(&self) -> &'static str {
"aura"
@@ -187,6 +235,14 @@ where
self.environment.init(header, shard)
}
+ fn updater(&mut self) -> Arc {
+ self.updater.clone()
+ }
+
+ fn state_handler(&mut self) -> Arc {
+ self.state_handler.clone()
+ }
+
fn proposing_remaining_duration(&self, slot_info: &SlotInfo) -> Duration {
proposing_remaining_duration(slot_info, duration_now())
}
@@ -256,7 +312,10 @@ where
mod tests {
use super::*;
use crate::test::{
- fixtures::{types::TestAura, validateer, SLOT_DURATION},
+ fixtures::{
+ types::{TestAura, UpdaterMock},
+ validateer, SLOT_DURATION,
+ },
mocks::environment_mock::EnvironmentMock,
};
use itc_parentchain_block_import_dispatcher::trigger_parentchain_block_import_mock::TriggerParentchainBlockImportMock;
@@ -264,7 +323,7 @@ mod tests {
parentchain_block_builder::ParentchainBlockBuilder,
parentchain_header_builder::ParentchainHeaderBuilder,
};
- use itp_test::mock::onchain_mock::OnchainMock;
+ use itp_test::mock::{handle_state_mock::HandleStateMock, onchain_mock::OnchainMock};
use itp_types::{
Block as ParentchainBlock, Enclave, Header as ParentchainHeader,
SignedBlock as SignedParentchainBlock,
@@ -277,7 +336,14 @@ mod tests {
onchain_mock: OnchainMock,
trigger_parentchain_import: Arc>,
) -> TestAura {
- Aura::new(Keyring::Alice.pair(), onchain_mock, trigger_parentchain_import, EnvironmentMock)
+ Aura::new(
+ Keyring::Alice.pair(),
+ onchain_mock,
+ trigger_parentchain_import,
+ EnvironmentMock,
+ Arc::new(UpdaterMock),
+ Arc::new(HandleStateMock::default()),
+ )
}
fn get_default_aura() -> TestAura {
diff --git a/tee-worker/sidechain/consensus/aura/src/test/fixtures/types.rs b/tee-worker/sidechain/consensus/aura/src/test/fixtures/types.rs
index 39aa4ef3f4..f5885cba4c 100644
--- a/tee-worker/sidechain/consensus/aura/src/test/fixtures/types.rs
+++ b/tee-worker/sidechain/consensus/aura/src/test/fixtures/types.rs
@@ -17,8 +17,9 @@
use crate::{test::mocks::environment_mock::EnvironmentMock, Aura};
use itc_parentchain_block_import_dispatcher::trigger_parentchain_block_import_mock::TriggerParentchainBlockImportMock;
-use itp_test::mock::onchain_mock::OnchainMock;
+use itp_test::mock::{handle_state_mock::HandleStateMock, onchain_mock::OnchainMock};
use itp_types::Block as ParentchainBlock;
+use its_consensus_common::UpdaterTrait;
use its_primitives::{
traits::{
Block as SidechainBlockTrait, Header as SidechainHeaderTrait,
@@ -33,6 +34,10 @@ type AuthorityPair = ed25519::Pair;
pub type ShardIdentifierFor =
<<::Block as SidechainBlockTrait>::HeaderType as SidechainHeaderTrait>::ShardIdentifier;
+#[derive(Default)]
+pub struct UpdaterMock;
+impl UpdaterTrait for UpdaterMock {}
+
pub type TestAura = Aura<
AuthorityPair,
ParentchainBlock,
@@ -40,4 +45,6 @@ pub type TestAura = Aura<
EnvironmentMock,
OnchainMock,
TriggerParentchainBlockImportMock>,
+ UpdaterMock,
+ HandleStateMock,
>;
diff --git a/tee-worker/sidechain/consensus/common/Cargo.toml b/tee-worker/sidechain/consensus/common/Cargo.toml
index e703b5b709..023bb6628d 100644
--- a/tee-worker/sidechain/consensus/common/Cargo.toml
+++ b/tee-worker/sidechain/consensus/common/Cargo.toml
@@ -10,8 +10,11 @@ log = { version = "0.4", default-features = false }
thiserror = { version = "1.0.26", optional = true }
# local deps
+itc-parentchain-indirect-calls-executor = { path = "../../../core/parentchain/indirect-calls-executor", default-features = false }
itc-parentchain-light-client = { path = "../../../core/parentchain/light-client", default-features = false }
itp-block-import-queue = { path = "../../../core-primitives/block-import-queue", default-features = false }
+itp-component-container = { path = "../../../core-primitives/component-container", default-features = false }
+itp-enclave-scheduled = { path = "../../../core-primitives/sgx/enclave-scheduled", default-features = false }
itp-extrinsics-factory = { path = "../../../core-primitives/extrinsics-factory", default-features = false }
itp-node-api-metadata = { path = "../../../core-primitives/node-api/metadata", default-features = false }
itp-node-api-metadata-provider = { path = "../../../core-primitives/node-api/metadata-provider", default-features = false }
@@ -50,10 +53,13 @@ sgx = [
"itc-parentchain-light-client/sgx",
"itp-block-import-queue/sgx",
"itp-extrinsics-factory/sgx",
+ #"itp-component-container/sgx",
+ "itp-enclave-scheduled/sgx",
"itp-node-api-metadata-provider/sgx",
"itp-sgx-crypto/sgx",
"itp-sgx-externalities/sgx",
"its-state/sgx",
+ "itc-parentchain-indirect-calls-executor/sgx",
# scs
"its-block-verification/sgx",
]
@@ -63,10 +69,13 @@ std = [
"thiserror",
# local
"itc-parentchain-light-client/std",
+ "itp-component-container/std",
"itp-block-import-queue/std",
"itp-extrinsics-factory/std",
"itp-node-api-metadata/std",
"itp-node-api-metadata-provider/std",
+ "itp-enclave-scheduled/std",
+ "itc-parentchain-indirect-calls-executor/std",
"itp-ocall-api/std",
"itp-sgx-crypto/std",
"itp-sgx-externalities/std",
diff --git a/tee-worker/sidechain/consensus/common/src/error.rs b/tee-worker/sidechain/consensus/common/src/error.rs
index 1f1b1f21f8..77aec1c32c 100644
--- a/tee-worker/sidechain/consensus/common/src/error.rs
+++ b/tee-worker/sidechain/consensus/common/src/error.rs
@@ -66,6 +66,8 @@ pub enum Error {
FailedToPopBlockImportQueue(#[from] itp_block_import_queue::error::Error),
#[error("Verification Error: {0}")]
VerificationError(its_block_verification::error::Error),
+ #[error("Can't get scheduled enclaves")]
+ GetScheduledEnclavesFailed,
}
impl core::convert::From for Error {
diff --git a/tee-worker/sidechain/consensus/common/src/lib.rs b/tee-worker/sidechain/consensus/common/src/lib.rs
index 60ce5d17e3..07b9299074 100644
--- a/tee-worker/sidechain/consensus/common/src/lib.rs
+++ b/tee-worker/sidechain/consensus/common/src/lib.rs
@@ -37,6 +37,7 @@ mod block_import_confirmation_handler;
mod block_import_queue_worker;
mod error;
mod peer_block_sync;
+mod updater;
#[cfg(test)]
mod test;
@@ -46,6 +47,7 @@ pub use block_import_confirmation_handler::*;
pub use block_import_queue_worker::*;
pub use error::*;
pub use peer_block_sync::*;
+pub use updater::{Updater, UpdaterTrait};
pub trait Verifier: Send + Sync
where
diff --git a/tee-worker/sidechain/consensus/common/src/updater.rs b/tee-worker/sidechain/consensus/common/src/updater.rs
new file mode 100644
index 0000000000..3d8fbcd864
--- /dev/null
+++ b/tee-worker/sidechain/consensus/common/src/updater.rs
@@ -0,0 +1,95 @@
+// Copyright 2020-2023 Litentry Technologies GmbH.
+// This file is part of Litentry.
+//
+// Litentry is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Litentry is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Litentry. If not, see .
+
+use crate::error::{Error, Result};
+use itc_parentchain_indirect_calls_executor::executor::litentry::get_scheduled_enclave::GLOBAL_SIDECHAIN_SCHEDULED_ENCLABES;
+use itp_component_container::ComponentGetter;
+use itp_enclave_scheduled::ScheduledEnclaveHandle;
+use itp_types::{MrEnclave, SidechainBlockNumber};
+
+/// Trait to suspend the production of sidechain blocks.
+pub trait UpdaterTrait {
+ /// current mr enclave
+ fn current_mr_enclave(&self) -> MrEnclave {
+ MrEnclave::default()
+ }
+
+ /// Trait to query if sidechain block production is suspended.
+ fn is_block_suspended(&self, _current_sidechain_num: SidechainBlockNumber) -> Result {
+ Ok(false)
+ }
+
+ /// check if need to merge return next mrenclave
+ fn get_merge_mr_enclave(
+ &self,
+ _current_sidechain_num: SidechainBlockNumber,
+ ) -> Result