Skip to content

Validate and Access all Parentchain Events in Enclave #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 58 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
83e6dc4
Initial addition of retrieving event proof from parent-chain
coax1d Mar 30, 2023
47d6b80
Adding in events retrieval
coax1d Mar 30, 2023
4d4b047
removing old comments
coax1d Mar 30, 2023
9c6f320
Passing in events and proofs per block to enclave
coax1d Apr 4, 2023
938c9ac
refactoring a bit
coax1d Apr 4, 2023
998384b
Fixing compiler errors
coax1d Apr 4, 2023
5d17e02
slight refactor plus comment
coax1d Apr 5, 2023
2ad6878
Clippy and fmt
coax1d Apr 5, 2023
9c9486a
Rebasing
coax1d Apr 6, 2023
9d508f4
Addressing clippy concerns
coax1d Apr 6, 2023
99a159d
Taplo
coax1d Apr 6, 2023
415154d
unpack events
coax1d Apr 6, 2023
fdd6209
validated events
coax1d Apr 6, 2023
c6f5bc6
rebasing
coax1d Apr 14, 2023
cb04488
adding in NodeMetaData extrinsic success and failed requests
coax1d Apr 14, 2023
0b75b73
Refactor and implement groundwork
coax1d Apr 16, 2023
0af91f0
passing events to correct place
coax1d Apr 20, 2023
f9ca237
Adding in infra for events
coax1d Apr 20, 2023
9c565ee
importing api client types and decoding events to log per block
coax1d Apr 25, 2023
be4020a
refactoring for passing events to triggered dispatcher
coax1d Apr 26, 2023
b348b1c
Renaming module refactoring for triggered dispatcher refactor
coax1d Apr 26, 2023
7cb57b2
adding in queue methods for events queue
coax1d Apr 27, 2023
da085cc
cargo fmt
coax1d Apr 27, 2023
8bb7213
fixing bug with chris on generic type
coax1d May 4, 2023
925f964
Debugging decoding issue
coax1d May 12, 2023
f3d5436
Was using storage key call incorrectly...
coax1d May 15, 2023
bc1ebba
small refactoring
coax1d May 15, 2023
61d2d73
cargo fmt and taplo fmt
coax1d May 15, 2023
7ecb549
adding in filtering of events for extrinsics
coax1d May 16, 2023
05d246b
cargo fmt
coax1d May 16, 2023
e453511
taplo and cargo fmt in enclave
coax1d May 16, 2023
f39d7ab
refactoring for clippy
coax1d May 16, 2023
b3729cf
cargo fmt
coax1d May 16, 2023
a2d0567
Rebasing with master
coax1d May 16, 2023
7022222
changing log back
coax1d May 16, 2023
40acada
minor comment removal
coax1d May 16, 2023
f5a4936
refactoring to include new traits for testing
coax1d May 19, 2023
ffac2d5
cargo fmt
coax1d May 19, 2023
dbf25c9
refactoring for addressing comments
coax1d May 19, 2023
de3fe25
cargo fmt
coax1d May 19, 2023
b8d3ada
rebasing
coax1d May 19, 2023
4e42aae
clippy satisfaction
coax1d May 19, 2023
8bee2df
cargo fmt
coax1d May 19, 2023
cd7474d
fix for top pool tests
coax1d May 21, 2023
5bb1acb
cargo fmt
coax1d May 21, 2023
cb3b00d
refactor for comments
coax1d May 21, 2023
b677b46
making clippy happy
coax1d May 21, 2023
43bd742
adding back pallet system
coax1d May 22, 2023
84a7cf7
addressing comments
coax1d May 22, 2023
a98daf2
refactor for comments
coax1d May 22, 2023
e651d11
adding some space
coax1d May 22, 2023
7351a0e
add debug trait for logging
coax1d May 22, 2023
4ff6d36
cargo fmt
coax1d May 22, 2023
b86f44a
addressing comments
coax1d May 23, 2023
eaa8424
trace logs
coax1d May 23, 2023
003b293
name changes
coax1d May 23, 2023
f070a74
couple log changes
coax1d May 23, 2023
b9dae0c
indentation fix
coax1d May 23, 2023
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
26 changes: 14 additions & 12 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2770,6 +2770,7 @@ dependencies = [
"itc-rest-client",
"itc-rpc-client",
"itc-rpc-server",
"itp-api-client-types",
"itp-enclave-api",
"itp-enclave-metrics",
"itp-node-api",
Expand Down Expand Up @@ -3034,7 +3035,7 @@ name = "itc-parentchain-block-import-dispatcher"
version = "0.9.0"
dependencies = [
"itc-parentchain-block-importer",
"itp-block-import-queue",
"itp-import-queue",
"itp-types",
"log 0.4.17",
"sgx_tstd",
Expand Down Expand Up @@ -3075,6 +3076,7 @@ dependencies = [
"futures 0.3.8",
"ita-stf",
"itc-parentchain-test",
"itp-api-client-types",
"itp-node-api",
"itp-ocall-api",
"itp-sgx-crypto",
Expand Down Expand Up @@ -3325,16 +3327,6 @@ dependencies = [
"yasna 0.3.1",
]

[[package]]
name = "itp-block-import-queue"
version = "0.8.0"
dependencies = [
"sgx_tstd",
"sgx_types",
"thiserror 1.0.40",
"thiserror 1.0.9",
]

[[package]]
name = "itp-component-container"
version = "0.8.0"
Expand Down Expand Up @@ -3408,6 +3400,16 @@ dependencies = [
"sp-core",
]

[[package]]
name = "itp-import-queue"
version = "0.8.0"
dependencies = [
"sgx_tstd",
"sgx_types",
"thiserror 1.0.40",
"thiserror 1.0.9",
]

[[package]]
name = "itp-networking-utils"
version = "0.9.0"
Expand Down Expand Up @@ -3895,8 +3897,8 @@ dependencies = [
"fork-tree",
"itc-parentchain-light-client",
"itc-parentchain-test",
"itp-block-import-queue",
"itp-extrinsics-factory",
"itp-import-queue",
"itp-node-api-metadata",
"itp-node-api-metadata-provider",
"itp-ocall-api",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ members = [
"core/rpc-server",
"core/tls-websocket-server",
"core-primitives/attestation-handler",
"core-primitives/block-import-queue",
"core-primitives/import-queue",
"core-primitives/component-container",
"core-primitives/enclave-api",
"core-primitives/enclave-api/ffi",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "itp-block-import-queue"
name = "itp-import-queue"
version = "0.8.0"
authors = ["Integritee AG <hello@integritee.network>"]
edition = "2021"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

*/

//! Block import queue implementation
//! Import queue implementation

#[cfg(feature = "sgx")]
use std::sync::SgxRwLock as RwLock;
Expand All @@ -25,64 +25,64 @@ use std::sync::RwLock;

use crate::{
error::{Error, Result},
PeekBlockQueue, PopFromBlockQueue, PushToBlockQueue,
PeekQueue, PopFromQueue, PushToQueue,
};
use std::{collections::VecDeque, vec::Vec};

/// Block import queue.
/// Any import queue.
///
/// Uses RwLock internally to guard against concurrent access and ensure all operations are atomic.
pub struct BlockImportQueue<SignedBlock> {
queue: RwLock<VecDeque<SignedBlock>>,
pub struct ImportQueue<Item> {
queue: RwLock<VecDeque<Item>>,
}

impl<SignedBlock> BlockImportQueue<SignedBlock> {
impl<Item> ImportQueue<Item> {
pub fn is_empty(&self) -> Result<bool> {
let queue_lock = self.queue.read().map_err(|_| Error::PoisonedLock)?;
Ok(queue_lock.is_empty())
}
}

impl<SignedBlock> Default for BlockImportQueue<SignedBlock> {
impl<Item> Default for ImportQueue<Item> {
fn default() -> Self {
BlockImportQueue { queue: Default::default() }
ImportQueue { queue: Default::default() }
}
}

impl<SignedBlock> PushToBlockQueue<SignedBlock> for BlockImportQueue<SignedBlock> {
fn push_multiple(&self, blocks: Vec<SignedBlock>) -> Result<()> {
impl<Item> PushToQueue<Item> for ImportQueue<Item> {
fn push_multiple(&self, items: Vec<Item>) -> Result<()> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
queue_lock.extend(blocks);
queue_lock.extend(items);
Ok(())
}

fn push_single(&self, block: SignedBlock) -> Result<()> {
fn push_single(&self, item: Item) -> Result<()> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
queue_lock.push_back(block);
queue_lock.push_back(item);
Ok(())
}
}

impl<SignedBlock> PopFromBlockQueue for BlockImportQueue<SignedBlock> {
type BlockType = SignedBlock;
impl<Item> PopFromQueue for ImportQueue<Item> {
type ItemType = Item;

fn pop_all_but_last(&self) -> Result<Vec<SignedBlock>> {
fn pop_all_but_last(&self) -> Result<Vec<Item>> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
let queue_length = queue_lock.len();
if queue_length < 2 {
return Ok(Vec::<SignedBlock>::default())
return Ok(Vec::<Item>::default())
}
Ok(queue_lock.drain(..queue_length - 1).collect::<Vec<_>>())
}

fn pop_all(&self) -> Result<Vec<SignedBlock>> {
fn pop_all(&self) -> Result<Vec<Item>> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
Ok(queue_lock.drain(..).collect::<Vec<_>>())
}

fn pop_until<Predicate>(&self, predicate: Predicate) -> Result<Vec<Self::BlockType>>
fn pop_until<Predicate>(&self, predicate: Predicate) -> Result<Vec<Self::ItemType>>
where
Predicate: FnMut(&Self::BlockType) -> bool,
Predicate: FnMut(&Self::ItemType) -> bool,
{
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
match queue_lock.iter().position(predicate) {
Expand All @@ -91,28 +91,38 @@ impl<SignedBlock> PopFromBlockQueue for BlockImportQueue<SignedBlock> {
}
}

fn pop_front(&self) -> Result<Option<Self::BlockType>> {
fn pop_front(&self) -> Result<Option<Self::ItemType>> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
Ok(queue_lock.pop_front())
}

fn pop_from_front_until(&self, amount: usize) -> Result<Vec<Self::ItemType>> {
let mut queue_lock = self.queue.write().map_err(|_| Error::PoisonedLock)?;
if amount > queue_lock.len() {
return Err(Error::Other(
"Cannot Pop more items from the queue than are available".into(),
))
}
Ok(queue_lock.drain(..amount).collect::<Vec<_>>())
}
}

impl<SignedBlock> PeekBlockQueue for BlockImportQueue<SignedBlock>
impl<Item> PeekQueue for ImportQueue<Item>
where
SignedBlock: Clone,
Item: Clone,
{
type BlockType = SignedBlock;
type ItemType = Item;

fn peek_find<Predicate>(&self, predicate: Predicate) -> Result<Option<Self::BlockType>>
fn peek_find<Predicate>(&self, predicate: Predicate) -> Result<Option<Self::ItemType>>
where
Predicate: Fn(&Self::BlockType) -> bool,
Predicate: Fn(&Self::ItemType) -> bool,
{
let queue_lock = self.queue.read().map_err(|_| Error::PoisonedLock)?;
let maybe_block = queue_lock.iter().find(|&b| predicate(b));
Ok(maybe_block.cloned())
let maybe_item = queue_lock.iter().find(|&b| predicate(b));
Ok(maybe_item.cloned())
}

fn peek_last(&self) -> Result<Option<Self::BlockType>> {
fn peek_last(&self) -> Result<Option<Self::ItemType>> {
let queue_lock = self.queue.read().map_err(|_| Error::PoisonedLock)?;
Ok(queue_lock.back().cloned())
}
Expand All @@ -132,26 +142,26 @@ mod tests {

#[test]
fn default_queue_is_empty() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert!(queue.is_empty().unwrap());
}

#[test]
fn pop_all_on_default_returns_empty_vec() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert!(queue.pop_all().unwrap().is_empty());
}

#[test]
fn after_inserting_queue_is_not_empty() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_single(TestBlock::default()).unwrap();
assert!(!queue.is_empty().unwrap());
}

#[test]
fn pop_all_after_inserting_leaves_empty_queue() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue
.push_multiple(vec![TestBlock::default(), TestBlock::default(), TestBlock::default()])
.unwrap();
Expand All @@ -163,20 +173,20 @@ mod tests {

#[test]
fn pop_all_except_last_on_default_returns_empty_vec() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert!(queue.pop_all_but_last().unwrap().is_empty());
}

#[test]
fn pop_all_except_last_with_single_element_returns_empty_vec() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_single(TestBlock::default()).unwrap();
assert!(queue.pop_all_but_last().unwrap().is_empty());
}

#[test]
fn pop_all_except_last_with_multiple_elements_returns_all_but_last_inserted() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 3, 5, 7]).unwrap();
assert_eq!(3, queue.pop_all_but_last().unwrap().len());
assert!(!queue.is_empty().unwrap());
Expand All @@ -185,7 +195,7 @@ mod tests {

#[test]
fn pop_until_returns_empty_vec_if_nothing_matches() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 3, 5, 7]).unwrap();

let popped_elements = queue.pop_until(|i| i > &10u32).unwrap();
Expand All @@ -194,36 +204,36 @@ mod tests {

#[test]
fn pop_until_returns_elements_until_and_including_match() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 2, 3, 10]).unwrap();

assert_eq!(queue.pop_until(|i| i == &3).unwrap(), vec![1, 2, 3]);
}

#[test]
fn pop_until_returns_all_elements_if_last_matches() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 2, 3, 10]).unwrap();

assert_eq!(queue.pop_until(|i| i == &10).unwrap(), vec![1, 2, 3, 10]);
}

#[test]
fn pop_until_returns_first_element_if_it_matches() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_single(4).unwrap();
assert_eq!(queue.pop_until(|i| i == &4).unwrap(), vec![4])
}

#[test]
fn pop_front_returns_none_if_queue_is_empty() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert_matches!(queue.pop_front().unwrap(), None);
}

#[test]
fn pop_front_works() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 2, 3, 5]).unwrap();
assert_eq!(queue.pop_front().unwrap(), Some(1));
assert_eq!(queue.pop_front().unwrap(), Some(2));
Expand All @@ -234,7 +244,7 @@ mod tests {

#[test]
fn peek_find_works() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 2, 3, 5]).unwrap();

assert_eq!(None, queue.peek_find(|i| i == &4).unwrap());
Expand All @@ -244,20 +254,20 @@ mod tests {

#[test]
fn peek_find_on_empty_queue_returns_none() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert_eq!(None, queue.peek_find(|i| i == &1).unwrap());
}

#[test]
fn peek_last_works() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
queue.push_multiple(vec![1, 2, 3, 5, 6, 9, 10]).unwrap();
assert_eq!(queue.peek_last().unwrap(), Some(10));
}

#[test]
fn peek_last_on_empty_queue_returns_none() {
let queue = BlockImportQueue::<TestBlock>::default();
let queue = ImportQueue::<TestBlock>::default();
assert_eq!(None, queue.peek_last().unwrap());
}
}
Loading