-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
propagate parentchain(s) timestamps (#1572)
* filter timestamp set extrinsic and add trusted call to set timestamp * use all extrinsic parsers to propagate parentchain timestamps * extend to target_b and generically solve parentchain instance type branching * lift patches * split out shard creation into module * WIP: get shard creation info back to service * implemented shard creation info refactoring. untested * initialize creation timestamp (has ~3 blocks delay to creation number * fix secondary validateer handling * cargo fix * carg fix ++ * clippy * fmt
- Loading branch information
Showing
50 changed files
with
777 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app-libs/parentchain-interface/src/indirect_calls/timestamp_set.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2021 Integritee AG and Supercomputing Systems AG | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
use crate::{Integritee, ParentchainInstance, TargetA, TargetB}; | ||
use codec::{Compact, Decode, Encode}; | ||
use core::{any::TypeId, marker::PhantomData}; | ||
use ita_stf::{Getter, TrustedCall, TrustedCallSigned}; | ||
use itc_parentchain_indirect_calls_executor::{ | ||
error::{Error, Result}, | ||
IndirectDispatch, | ||
}; | ||
use itp_stf_primitives::{traits::IndirectExecutor, types::TrustedOperation}; | ||
use itp_types::{parentchain::ParentchainId, Moment}; | ||
use log::info; | ||
|
||
#[derive(Debug, Clone, Encode, Decode, Eq, PartialEq)] | ||
pub struct TimestampSetArgs<I: ParentchainInstance> { | ||
now: Compact<Moment>, | ||
_phantom: PhantomData<I>, | ||
} | ||
|
||
impl<Executor: IndirectExecutor<TrustedCallSigned, Error>, I: ParentchainInstance + 'static> | ||
IndirectDispatch<Executor, TrustedCallSigned> for TimestampSetArgs<I> | ||
{ | ||
fn dispatch(&self, executor: &Executor) -> Result<()> { | ||
info!("Found TimestampSet extrinsic in block: now = {:?}", self.now); | ||
let enclave_account_id = executor.get_enclave_account()?; | ||
let parentchain_id = if TypeId::of::<I>() == TypeId::of::<Integritee>() { | ||
ParentchainId::Integritee | ||
} else if TypeId::of::<I>() == TypeId::of::<TargetA>() { | ||
ParentchainId::TargetA | ||
} else if TypeId::of::<I>() == TypeId::of::<TargetB>() { | ||
ParentchainId::TargetB | ||
} else { | ||
return Err(Error::Other("unknown parentchain instance".into())) | ||
}; | ||
let trusted_call = | ||
TrustedCall::timestamp_set(enclave_account_id, self.now.0, parentchain_id); | ||
let shard = executor.get_default_shard(); | ||
let signed_trusted_call = executor.sign_call_with_self(&trusted_call, &shard)?; | ||
let trusted_operation = | ||
TrustedOperation::<TrustedCallSigned, Getter>::indirect_call(signed_trusted_call); | ||
|
||
let encrypted_trusted_call = executor.encrypt(&trusted_operation.encode())?; | ||
executor.submit_trusted_call(shard, encrypted_trusted_call); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.