From 5c52182eb3a5156e8d9f69c10ca1441214ee6662 Mon Sep 17 00:00:00 2001 From: brenzi Date: Sat, 15 Jul 2023 21:22:51 +0200 Subject: [PATCH] Clean up Events and Errors and add docstrings (#207) * turn all enclave-bridge events with tuples into structs * more struct events * clean up enclave events * more cleanup and docstrings --- Cargo.lock | 80 ++++++++--------- enclave-bridge/src/lib.rs | 61 ++++++++----- .../src/tests/test_indirect_invocation.rs | 31 ++++--- enclave-bridge/src/tests/test_publish_hash.rs | 4 +- parentchain/src/lib.rs | 1 + sidechain/src/lib.rs | 30 ++++--- sidechain/src/tests.rs | 66 ++++++++------ teeracle/src/lib.rs | 80 +++++++++-------- teeracle/src/tests.rs | 86 +++++++++---------- teerex/src/lib.rs | 75 ++++++++-------- 10 files changed, 285 insertions(+), 229 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c7889389..a9360bf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -990,7 +990,7 @@ dependencies = [ [[package]] name = "frame-benchmarking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-support", "frame-support-procedural", @@ -1027,7 +1027,7 @@ dependencies = [ [[package]] name = "frame-support" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "bitflags", "environmental", @@ -1060,7 +1060,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "Inflector", "cfg-expr", @@ -1076,7 +1076,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate", @@ -1088,7 +1088,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "3.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "proc-macro2", "quote", @@ -1098,7 +1098,7 @@ dependencies = [ [[package]] name = "frame-system" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-support", "log", @@ -2111,7 +2111,7 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "pallet-balances" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-benchmarking", "frame-support", @@ -2277,7 +2277,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-benchmarking", "frame-support", @@ -2295,7 +2295,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-benchmarking", "frame-support", @@ -3385,7 +3385,7 @@ dependencies = [ [[package]] name = "sp-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "hash-db", "log", @@ -3405,7 +3405,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "Inflector", "blake2", @@ -3419,7 +3419,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "scale-info", @@ -3432,7 +3432,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "integer-sqrt", "num-traits", @@ -3446,7 +3446,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "scale-info", @@ -3459,7 +3459,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "scale-info", @@ -3471,7 +3471,7 @@ dependencies = [ [[package]] name = "sp-core" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "array-bytes", "bitflags", @@ -3515,7 +3515,7 @@ dependencies = [ [[package]] name = "sp-core-hashing" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "blake2b_simd", "byteorder", @@ -3544,7 +3544,7 @@ dependencies = [ [[package]] name = "sp-core-hashing-proc-macro" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "proc-macro2", "quote", @@ -3555,7 +3555,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "proc-macro2", "quote", @@ -3565,7 +3565,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "environmental", "parity-scale-codec", @@ -3576,7 +3576,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -3591,7 +3591,7 @@ dependencies = [ [[package]] name = "sp-io" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "bytes", "ed25519", @@ -3617,7 +3617,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "lazy_static", "sp-core", @@ -3628,7 +3628,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "futures", "parity-scale-codec", @@ -3642,7 +3642,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.1.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -3653,7 +3653,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "backtrace", "lazy_static", @@ -3663,7 +3663,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "either", "hash256-std-hasher", @@ -3685,7 +3685,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -3703,7 +3703,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "Inflector", "proc-macro-crate", @@ -3715,7 +3715,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "scale-info", @@ -3728,7 +3728,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.13.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "hash-db", "log", @@ -3748,7 +3748,7 @@ dependencies = [ [[package]] name = "sp-std" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" [[package]] name = "sp-std" @@ -3759,7 +3759,7 @@ checksum = "1de8eef39962b5b97478719c493bed2926cf70cb621005bbf68ebe58252ff986" [[package]] name = "sp-storage" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "impl-serde", "parity-scale-codec", @@ -3772,7 +3772,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "async-trait", "futures-timer", @@ -3787,7 +3787,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "6.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "sp-std 5.0.0", @@ -3799,7 +3799,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "ahash 0.8.3", "hash-db", @@ -3822,7 +3822,7 @@ dependencies = [ [[package]] name = "sp-version" version = "5.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "impl-serde", "parity-scale-codec", @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -3850,7 +3850,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -3864,7 +3864,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "4.0.0" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#569aae5341ea0c1d10426fa1ec13a36c0b64393b" dependencies = [ "parity-scale-codec", "scale-info", diff --git a/enclave-bridge/src/lib.rs b/enclave-bridge/src/lib.rs index caa3dffb..c44aad7f 100644 --- a/enclave-bridge/src/lib.rs +++ b/enclave-bridge/src/lib.rs @@ -73,19 +73,46 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { + /// an indirect invocation has been registered for execution on L2 IndirectInvocationRegistered(ShardIdentifier), - ShieldFunds(Vec, BalanceOf), - UnshieldedFunds(T::AccountId, BalanceOf), - ProcessedParentchainBlock(ShardIdentifier, H256, H256, T::BlockNumber), - /// An enclave with [mr_enclave] has published some [hash] with some metadata [data]. + /// funds have been shielded to L2 + ShieldFunds { + shard: ShardIdentifier, + encrypted_beneficiary: Vec, + amount: BalanceOf, + }, + /// funds have been unshielded from L2 back to L1 + UnshieldedFunds { + shard: ShardIdentifier, + beneficiary: T::AccountId, + amount: BalanceOf, + }, + /// L2 confirmed processing of a parentchain block + ProcessedParentchainBlock { + shard: ShardIdentifier, + block_hash: H256, + trusted_calls_merkle_root: H256, + block_number: T::BlockNumber, + }, + /// An enclave has published some [hash] with some metadata [data]. PublishedHash { - fingerprint: EnclaveFingerprint, + enclave_fingerprint: EnclaveFingerprint, hash: H256, data: Vec, }, ShardConfigUpdated(ShardIdentifier), } + #[pallet::error] + pub enum Error { + /// The shard doesn't match the enclave. + WrongFingerprintForShard, + /// The number of `extra_topics` passed to `publish_hash` exceeds the limit. + TooManyTopics, + /// The length of the `data` passed to `publish_hash` exceeds the limit. + DataTooLong, + } + #[pallet::storage] #[pallet::getter(fn shard_status)] pub type ShardStatus = StorageMap< @@ -154,12 +181,12 @@ pub mod pallet { shard, block_hash ); - Self::deposit_event(Event::ProcessedParentchainBlock( + Self::deposit_event(Event::ProcessedParentchainBlock { shard, block_hash, trusted_calls_merkle_root, block_number, - )); + }); Ok(().into()) } @@ -183,7 +210,11 @@ pub mod pallet { amount, ExistenceRequirement::AllowDeath, )?; - Self::deposit_event(Event::ShieldFunds(incognito_account_encrypted, amount)); + Self::deposit_event(Event::ShieldFunds { + shard, + encrypted_beneficiary: incognito_account_encrypted, + amount, + }); Ok(().into()) } @@ -214,7 +245,7 @@ pub mod pallet { ExistenceRequirement::AllowDeath, )?; >::insert(call_hash, 0); - Self::deposit_event(Event::UnshieldedFunds(beneficiary, amount)); + Self::deposit_event(Event::UnshieldedFunds { shard, beneficiary, amount }); } else { log::info!( target: ENCLAVE_BRIDGE, @@ -263,7 +294,7 @@ pub mod pallet { Self::deposit_event_indexed( &topics, - Event::PublishedHash { fingerprint: enclave.fingerprint(), hash, data }, + Event::PublishedHash { enclave_fingerprint: enclave.fingerprint(), hash, data }, ); Ok(().into()) @@ -315,16 +346,6 @@ pub mod pallet { Ok(().into()) } } - - #[pallet::error] - pub enum Error { - /// The shard doesn't match the enclave. - WrongFingerprintForShard, - /// The number of `extra_topics` passed to `publish_hash` exceeds the limit. - TooManyTopics, - /// The length of the `data` passed to `publish_hash` exceeds the limit. - DataTooLong, - } } impl Pallet { diff --git a/enclave-bridge/src/tests/test_indirect_invocation.rs b/enclave-bridge/src/tests/test_indirect_invocation.rs index da7ab6d8..4fcf70e5 100644 --- a/enclave-bridge/src/tests/test_indirect_invocation.rs +++ b/enclave-bridge/src/tests/test_indirect_invocation.rs @@ -69,10 +69,11 @@ fn unshield_is_only_executed_once_for_the_same_call_hash() { call_hash ) .is_ok()); - let expected_event = RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::UnshieldedFunds( - beneficiary.clone(), + let expected_event = RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::UnshieldedFunds { + shard, + beneficiary: beneficiary.clone(), amount, - )); + }); assert!(System::events().iter().any(|a| a.event == expected_event)); System::reset_events(); @@ -117,10 +118,11 @@ fn verify_unshield_funds_works() { assert_eq!(Balances::free_balance(bonding_account.clone()), 100); - let expected_event = RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ShieldFunds( - incognito_account_encrypted, - 100, - )); + let expected_event = RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ShieldFunds { + shard, + encrypted_beneficiary: incognito_account_encrypted, + amount: 100, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert!(EnclaveBridge::unshield_funds( @@ -133,8 +135,11 @@ fn verify_unshield_funds_works() { .is_ok()); assert_eq!(Balances::free_balance(bonding_account), 50); - let expected_event = - RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::UnshieldedFunds(beneficiary, 50)); + let expected_event = RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::UnshieldedFunds { + shard, + beneficiary, + amount: 50, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); }) } @@ -230,12 +235,12 @@ fn confirm_processed_parentchain_block_works() { )); let expected_event = - RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ProcessedParentchainBlock( - ShardIdentifier::default(), + RuntimeEvent::EnclaveBridge(EnclaveBridgeEvent::ProcessedParentchainBlock { + shard: ShardIdentifier::default(), block_hash, - merkle_root, + trusted_calls_merkle_root: merkle_root, block_number, - )); + }); assert!(System::events().iter().any(|a| a.event == expected_event)); }) } diff --git a/enclave-bridge/src/tests/test_publish_hash.rs b/enclave-bridge/src/tests/test_publish_hash.rs index fa0b8cb7..bf6e1472 100644 --- a/enclave-bridge/src/tests/test_publish_hash.rs +++ b/enclave-bridge/src/tests/test_publish_hash.rs @@ -65,7 +65,7 @@ fn publish_hash_works() { EventRecord { phase: Phase::Initialization, event: EnclaveBridgeEvent::PublishedHash { - fingerprint: fingerprint.into(), + enclave_fingerprint: fingerprint.into(), hash, data } @@ -75,7 +75,7 @@ fn publish_hash_works() { EventRecord { phase: Phase::Initialization, event: EnclaveBridgeEvent::PublishedHash { - fingerprint: fingerprint.into(), + enclave_fingerprint: fingerprint.into(), hash, data: vec![] } diff --git a/parentchain/src/lib.rs b/parentchain/src/lib.rs index bf864e87..9bdd993c 100644 --- a/parentchain/src/lib.rs +++ b/parentchain/src/lib.rs @@ -21,6 +21,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { + /// a parentchain block has been registered SetBlock { block_number: T::BlockNumber, parent_hash: T::Hash, block_hash: T::Hash }, } diff --git a/sidechain/src/lib.rs b/sidechain/src/lib.rs index e1f3a0fb..5624d062 100644 --- a/sidechain/src/lib.rs +++ b/sidechain/src/lib.rs @@ -57,8 +57,20 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - ProposedSidechainBlock(T::AccountId, H256), - FinalizedSidechainBlock(T::AccountId, H256), + /// a sidechain block has been finalized + FinalizedSidechainBlock { + shard: ShardIdentifier, + block_header_hash: H256, + validateer: T::AccountId, + }, + } + + #[pallet::error] + pub enum Error { + /// A proposed block is unexpected. + ReceivedUnexpectedSidechainBlock, + /// The value for the next finalization candidate is invalid. + InvalidNextFinalizationCandidateBlockNumber, } #[pallet::storage] @@ -123,14 +135,6 @@ pub mod pallet { Ok(().into()) } } - - #[pallet::error] - pub enum Error { - /// A proposed block is unexpected. - ReceivedUnexpectedSidechainBlock, - /// The value for the next finalization candidate is invalid. - InvalidNextFinalizationCandidateBlockNumber, - } } impl Pallet { @@ -146,7 +150,11 @@ impl Pallet { shard, block_header_hash ); - Self::deposit_event(Event::FinalizedSidechainBlock(sender.clone(), block_header_hash)); + Self::deposit_event(Event::FinalizedSidechainBlock { + shard, + block_header_hash, + validateer: sender.clone(), + }); } } diff --git a/sidechain/src/tests.rs b/sidechain/src/tests.rs index 73e07b6b..b9d0c9bc 100644 --- a/sidechain/src/tests.rs +++ b/sidechain/src/tests.rs @@ -79,8 +79,11 @@ fn confirm_imported_sidechain_block_works_for_correct_shard() { hash )); - let expected_event = - RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock(signer7, hash)); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard: shard7, + block_header_hash: hash, + validateer: signer7, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); }) } @@ -201,10 +204,11 @@ fn dont_process_confirmation_of_second_registered_enclave() { System::reset_events(); assert_ok!(confirm_sidechain_block(shard7, TEST6_SIGNER_PUB, 1, 2, H256::default(), false)); - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - get_signer(TEST6_SIGNER_PUB), - H256::default(), - )); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard: shard7, + block_header_hash: H256::default(), + validateer: get_signer(TEST6_SIGNER_PUB), + }); assert!(!System::events().iter().any(|a| a.event == expected_event)); }) } @@ -235,10 +239,11 @@ fn confirm_imported_sidechain_block_works_for_correct_shard_with_updated_fingerp hash )); - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - enclave_signer.clone(), - hash, - )); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard, + block_header_hash: hash, + validateer: enclave_signer.clone(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); let new_fingerprint = EnclaveFingerprint::from([2u8; 32]); @@ -259,10 +264,11 @@ fn confirm_imported_sidechain_block_works_for_correct_shard_with_updated_fingerp hash )); - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - enclave_signer.clone(), - hash, - )); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard, + block_header_hash: hash, + validateer: enclave_signer.clone(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); run_to_block(2); @@ -279,8 +285,11 @@ fn confirm_imported_sidechain_block_works_for_correct_shard_with_updated_fingerp hash )); - let expected_event = - RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock(enclave_signer, hash)); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard, + block_header_hash: hash, + validateer: enclave_signer, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); }) } @@ -303,10 +312,11 @@ fn two_sidechains_with_different_fingerprint_works() { hash1 )); - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - enclave_signer1.clone(), - hash1, - )); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard: shard1, + block_header_hash: hash1, + validateer: enclave_signer1.clone(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); run_to_block(2); @@ -325,10 +335,11 @@ fn two_sidechains_with_different_fingerprint_works() { hash2 )); - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - enclave_signer2.clone(), - hash2, - )); + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard: shard2, + block_header_hash: hash2, + validateer: enclave_signer2.clone(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); let shard_status1 = EnclaveBridge::shard_status(shard1).unwrap(); @@ -411,10 +422,11 @@ fn confirm_sidechain_block( )?; if assert_event { - let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock( - signer, + let expected_event = RuntimeEvent::Sidechain(SidechainEvent::FinalizedSidechainBlock { + shard, block_header_hash, - )); + validateer: signer, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); } Ok(().into()) diff --git a/teeracle/src/lib.rs b/teeracle/src/lib.rs index 17ddc952..2a4b8477 100644 --- a/teeracle/src/lib.rs +++ b/teeracle/src/lib.rs @@ -103,30 +103,40 @@ pub mod pallet { ValueQuery, >; - // pub(super) type Whitelist = - // StorageValue<_, WeakBoundedVec<[u8; 32], T::MaxWhitelistedReleases>, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - /// The exchange rate of trading pair was set/updated with value from source. \[data_source], [trading_pair], [new value\] - ExchangeRateUpdated(DataSource, TradingPairString, Option), - ExchangeRateDeleted(DataSource, TradingPairString), - OracleUpdated(OracleDataName, DataSource), - AddedToWhitelist(DataSource, EnclaveFingerprint), - RemovedFromWhitelist(DataSource, EnclaveFingerprint), + /// The exchange rate of trading pair was set/updated with value from source. + ExchangeRateUpdated { + data_source: DataSource, + trading_pair: TradingPairString, + exchange_rate: ExchangeRate, + }, + /// The exchange rate of trading pair was deleted. + ExchangeRateDeleted { data_source: DataSource, trading_pair: TradingPairString }, + /// a generic named oracle has updated its data blob + OracleUpdated { oracle_data_name: OracleDataName, data_source: DataSource }, + /// an oracle fingerprint has been added to the whitelist + AddedToWhitelist { data_source: DataSource, enclave_fingerprint: EnclaveFingerprint }, + /// an oracle fingerprint has been removed from the whitelist + RemovedFromWhitelist { data_source: DataSource, enclave_fingerprint: EnclaveFingerprint }, } #[pallet::error] pub enum Error { - InvalidCurrency, - /// Too many MrEnclave in the whitelist. - ReleaseWhitelistOverflow, - ReleaseNotWhitelisted, - ReleaseAlreadyWhitelisted, + /// Too many enclave fingerprints in the whitelist for this data source. + FingerprintWhitelistOverflow, + /// calling enclave fingerprint not whitelisted for this data source. + FingerprintNotWhitelisted, + /// enclave fingerprint already whitelisted for this data source. + FingerprintAlreadyWhitelisted, + /// trading pair string too long TradingPairStringTooLong, + /// generic oracle data name string too long OracleDataNameStringTooLong, + /// data source string too long DataSourceStringTooLong, + /// generic oracle blob too big OracleBlobTooBig, } @@ -140,19 +150,19 @@ pub mod pallet { pub fn add_to_whitelist( origin: OriginFor, data_source: DataSource, - fingerprint: EnclaveFingerprint, + enclave_fingerprint: EnclaveFingerprint, ) -> DispatchResult { ensure_root(origin)?; ensure!(data_source.len() <= MAX_SOURCE_LEN, Error::::DataSourceStringTooLong); ensure!( - !Self::is_whitelisted(&data_source, fingerprint), - >::ReleaseAlreadyWhitelisted + !Self::is_whitelisted(&data_source, enclave_fingerprint), + >::FingerprintAlreadyWhitelisted ); >::try_mutate(data_source.clone(), |fingerprints| { - fingerprints.try_push(fingerprint) + fingerprints.try_push(enclave_fingerprint) }) - .map_err(|_| Error::::ReleaseWhitelistOverflow)?; - Self::deposit_event(Event::AddedToWhitelist(data_source, fingerprint)); + .map_err(|_| Error::::FingerprintWhitelistOverflow)?; + Self::deposit_event(Event::AddedToWhitelist { data_source, enclave_fingerprint }); Ok(()) } #[pallet::call_index(1)] @@ -160,17 +170,17 @@ pub mod pallet { pub fn remove_from_whitelist( origin: OriginFor, data_source: DataSource, - fingerprint: EnclaveFingerprint, + enclave_fingerprint: EnclaveFingerprint, ) -> DispatchResult { ensure_root(origin)?; ensure!( - Self::is_whitelisted(&data_source, fingerprint), - >::ReleaseNotWhitelisted + Self::is_whitelisted(&data_source, enclave_fingerprint), + >::FingerprintNotWhitelisted ); >::mutate(&data_source, |fingerprints| { - fingerprints.retain(|m| *m != fingerprint) + fingerprints.retain(|m| *m != enclave_fingerprint) }); - Self::deposit_event(Event::RemovedFromWhitelist(data_source, fingerprint)); + Self::deposit_event(Event::RemovedFromWhitelist { data_source, enclave_fingerprint }); Ok(()) } @@ -178,7 +188,7 @@ pub mod pallet { #[pallet::weight((::WeightInfo::update_oracle(), DispatchClass::Normal, Pays::Yes))] pub fn update_oracle( origin: OriginFor, - oracle_name: OracleDataName, + oracle_data_name: OracleDataName, data_source: DataSource, new_blob: OracleDataBlob, ) -> DispatchResultWithPostInfo { @@ -188,10 +198,10 @@ pub mod pallet { ensure!( Self::is_whitelisted(&data_source, enclave.fingerprint()), - >::ReleaseNotWhitelisted + >::FingerprintNotWhitelisted ); ensure!( - oracle_name.len() <= MAX_ORACLE_DATA_NAME_LEN, + oracle_data_name.len() <= MAX_ORACLE_DATA_NAME_LEN, Error::::OracleDataNameStringTooLong ); ensure!(data_source.len() <= MAX_SOURCE_LEN, Error::::DataSourceStringTooLong); @@ -200,8 +210,8 @@ pub mod pallet { Error::::OracleBlobTooBig ); - OracleData::::insert(&oracle_name, &data_source, new_blob); - Self::deposit_event(Event::::OracleUpdated(oracle_name, data_source)); + OracleData::::insert(&oracle_data_name, &data_source, new_blob); + Self::deposit_event(Event::::OracleUpdated { oracle_data_name, data_source }); Ok(().into()) } @@ -224,22 +234,22 @@ pub mod pallet { ); ensure!( Self::is_whitelisted(&data_source, enclave.fingerprint()), - >::ReleaseNotWhitelisted + >::FingerprintNotWhitelisted ); if new_value.is_none() || new_value == Some(U32F32::from_num(0)) { log::info!("Delete exchange rate : {:?}", new_value); ExchangeRates::::mutate_exists(&trading_pair, &data_source, |rate| *rate = None); - Self::deposit_event(Event::ExchangeRateDeleted(data_source, trading_pair)); + Self::deposit_event(Event::ExchangeRateDeleted { data_source, trading_pair }); } else { log::info!("Update exchange rate : {:?}", new_value); ExchangeRates::::mutate_exists(&trading_pair, &data_source, |rate| { *rate = new_value }); - Self::deposit_event(Event::ExchangeRateUpdated( + Self::deposit_event(Event::ExchangeRateUpdated { data_source, trading_pair, - new_value, - )); + exchange_rate: new_value.expect("previously checked that is Some"), + }); } Ok(().into()) } diff --git a/teeracle/src/tests.rs b/teeracle/src/tests.rs index c09adca0..f3ca5354 100644 --- a/teeracle/src/tests.rs +++ b/teeracle/src/tests.rs @@ -67,11 +67,11 @@ fn update_exchange_rate_works() { let rate = U32F32::from_num(43.65); update_exchange_rate_dot_dollars_ok(COINGECKO_SRC, Some(rate)); - let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateUpdated( - COINGECKO_SRC.to_owned(), - DOT_USD_TRADING_PAIR.to_owned(), - Some(rate), - )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateUpdated { + data_source: COINGECKO_SRC.to_owned(), + trading_pair: DOT_USD_TRADING_PAIR.to_owned(), + exchange_rate: rate, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert_eq!( Teeracle::exchange_rate(DOT_USD_TRADING_PAIR.to_owned(), COINGECKO_SRC.to_owned()), @@ -100,10 +100,10 @@ fn update_oracle_works() { DataSource::from("Test_Source_Name"), oracle_blob.clone() ),); - let expected_event = RuntimeEvent::Teeracle(crate::Event::OracleUpdated( - OracleDataName::from("Test_Oracle_Name"), - DataSource::from("Test_Source_Name"), - )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::OracleUpdated { + oracle_data_name: OracleDataName::from("Test_Oracle_Name"), + data_source: DataSource::from("Test_Source_Name"), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert_eq!( @@ -152,10 +152,10 @@ fn update_exchange_rate_to_none_delete_exchange_rate() { update_exchange_rate_dot_dollars_ok(COINGECKO_SRC, None); - let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateDeleted( - COINGECKO_SRC.to_owned(), - DOT_USD_TRADING_PAIR.to_owned(), - )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateDeleted { + data_source: COINGECKO_SRC.to_owned(), + trading_pair: DOT_USD_TRADING_PAIR.to_owned(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert!(!ExchangeRates::::contains_key( DOT_USD_TRADING_PAIR.to_owned(), @@ -173,10 +173,10 @@ fn update_exchange_rate_to_zero_delete_exchange_rate() { update_exchange_rate_dot_dollars_ok(COINGECKO_SRC, Some(U32F32::from_num(0))); - let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateDeleted( - COINGECKO_SRC.to_owned(), - DOT_USD_TRADING_PAIR.to_owned(), - )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::ExchangeRateDeleted { + data_source: COINGECKO_SRC.to_owned(), + trading_pair: DOT_USD_TRADING_PAIR.to_owned(), + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert!(!ExchangeRates::::contains_key( @@ -239,7 +239,7 @@ fn update_exchange_rate_from_not_whitelisted_oracle_fails() { DOT_USD_TRADING_PAIR.to_owned(), Some(rate) ), - crate::Error::::ReleaseNotWhitelisted + crate::Error::::FingerprintNotWhitelisted ); }) } @@ -263,7 +263,7 @@ fn update_oracle_from_not_whitelisted_oracle_fails() { DataSource::from("Test_Source_Name"), vec![0].try_into().expect("Can Convert to BoundedVec; QED") ), - crate::Error::::ReleaseNotWhitelisted + crate::Error::::FingerprintNotWhitelisted ); }) } @@ -291,16 +291,16 @@ fn update_exchange_rate_with_too_long_trading_pair_fails() { #[test] fn add_to_whitelist_works() { new_test_ext().execute_with(|| { - let fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); + let enclave_fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); assert_ok!(Teeracle::add_to_whitelist( RuntimeOrigin::root(), COINGECKO_SRC.to_owned(), - fingerprint - )); - let expected_event = RuntimeEvent::Teeracle(crate::Event::AddedToWhitelist( - COINGECKO_SRC.to_owned(), - fingerprint, + enclave_fingerprint )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::AddedToWhitelist { + data_source: COINGECKO_SRC.to_owned(), + enclave_fingerprint, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 1); }) @@ -309,21 +309,21 @@ fn add_to_whitelist_works() { #[test] fn add_mulitple_src_to_whitelists_works() { new_test_ext().execute_with(|| { - let fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); + let enclave_fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); assert_ok!(Teeracle::add_to_whitelist( RuntimeOrigin::root(), COINGECKO_SRC.to_owned(), - fingerprint + enclave_fingerprint )); assert_ok!(Teeracle::add_to_whitelist( RuntimeOrigin::root(), COINMARKETCAP_SRC.to_owned(), - fingerprint - )); - let expected_event = RuntimeEvent::Teeracle(crate::Event::AddedToWhitelist( - COINMARKETCAP_SRC.to_owned(), - fingerprint, + enclave_fingerprint )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::AddedToWhitelist { + data_source: COINMARKETCAP_SRC.to_owned(), + enclave_fingerprint, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 1); @@ -346,7 +346,7 @@ fn add_two_times_to_whitelist_fails() { COINGECKO_SRC.to_owned(), fingerprint ), - crate::Error::::ReleaseAlreadyWhitelisted + crate::Error::::FingerprintAlreadyWhitelisted ); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 1); }) @@ -427,7 +427,7 @@ fn add_too_many_oracles_to_whitelist_fails() { COINGECKO_SRC.to_owned(), EnclaveFingerprint::from(TEST8_MRENCLAVE) ), - crate::Error::::ReleaseWhitelistOverflow + crate::Error::::FingerprintWhitelistOverflow ); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 10); }) @@ -467,21 +467,21 @@ fn non_root_add_to_whitelist_fails() { #[test] fn remove_from_whitelist_works() { new_test_ext().execute_with(|| { - let fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); + let enclave_fingerprint = EnclaveFingerprint::from(TEST4_MRENCLAVE); assert_ok!(Teeracle::add_to_whitelist( RuntimeOrigin::root(), COINGECKO_SRC.to_owned(), - fingerprint + enclave_fingerprint )); assert_ok!(Teeracle::remove_from_whitelist( RuntimeOrigin::root(), COINGECKO_SRC.to_owned(), - fingerprint - )); - let expected_event = RuntimeEvent::Teeracle(crate::Event::RemovedFromWhitelist( - COINGECKO_SRC.to_owned(), - fingerprint, + enclave_fingerprint )); + let expected_event = RuntimeEvent::Teeracle(crate::Event::RemovedFromWhitelist { + data_source: COINGECKO_SRC.to_owned(), + enclave_fingerprint, + }); assert!(System::events().iter().any(|a| a.event == expected_event)); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 0); }) @@ -501,7 +501,7 @@ fn remove_from_whitelist_not_whitelisted_fails() { COINGECKO_SRC.to_owned(), EnclaveFingerprint::from(TEST5_MRENCLAVE) ), - crate::Error::::ReleaseNotWhitelisted + crate::Error::::FingerprintNotWhitelisted ); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 1); }) @@ -517,7 +517,7 @@ fn remove_from_empty_whitelist_doesnt_crash() { COINGECKO_SRC.to_owned(), EnclaveFingerprint::from(TEST5_MRENCLAVE) ), - crate::Error::::ReleaseNotWhitelisted + crate::Error::::FingerprintNotWhitelisted ); assert_eq!(Teeracle::whitelist(COINGECKO_SRC.to_owned()).len(), 0); }) diff --git a/teerex/src/lib.rs b/teerex/src/lib.rs index 5a4160ee..f66bdac1 100644 --- a/teerex/src/lib.rs +++ b/teerex/src/lib.rs @@ -73,25 +73,51 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { + /// An Intel SGX enclave has been added to the enclave registry AddedSgxEnclave { registered_by: T::AccountId, worker_url: Option>, tcb_status: Option, attestation_method: SgxAttestationMethod, }, + /// a sovereign enclave has been removed from the enclave registry RemovedSovereignEnclave(T::AccountId), + /// a proxied enclave has been removed from the enclave registry RemovedProxiedEnclave(EnclaveInstanceAddress), - SgxTcbInfoRegistered { - fmspc: Fmspc, - on_chain_info: SgxTcbInfoOnChain, - }, - SgxQuotingEnclaveRegistered { - quoting_enclave: SgxQuotingEnclave, - }, - UpdatedSecurityFlags { - allow_skipping_attestation: bool, - sgx_allow_debug_mode: bool, - }, + /// Intel SGX TCB info has been registered + SgxTcbInfoRegistered { fmspc: Fmspc, on_chain_info: SgxTcbInfoOnChain }, + /// An Intel SGX quoting enclave has been registered + SgxQuotingEnclaveRegistered { quoting_enclave: SgxQuotingEnclave }, + /// the enclave registry security flags have been updated + UpdatedSecurityFlags { allow_skipping_attestation: bool, sgx_allow_debug_mode: bool }, + } + + #[pallet::error] + pub enum Error { + /// Failed to decode enclave signer. + EnclaveSignerDecodeError, + /// Sender does not match attested enclave in report. + SenderIsNotAttestedEnclave, + /// Verifying RA report failed. + RemoteAttestationVerificationFailed, + /// IAS remote attestation is too old + RemoteAttestationTooOld, + /// The enclave cannot attest, because its building mode is not allowed. + SgxModeNotAllowed, + /// The enclave is not registered. + EnclaveIsNotRegistered, + /// The worker url is too long. + EnclaveUrlTooLong, + /// The Remote Attestation proof is too long. + RaProofTooLong, + /// No enclave is registered. + EmptyEnclaveRegistry, + /// The provided collateral data is invalid + CollateralInvalid, + /// It is not allowed to unregister enclaves with recent activity + UnregisterActiveEnclaveNotAllowed, + /// skipping attestation not allowed by configuration + SkippingAttestationNotAllowed, } #[pallet::storage] @@ -409,33 +435,6 @@ pub mod pallet { Ok(().into()) } } - - #[pallet::error] - pub enum Error { - /// Failed to decode enclave signer. - EnclaveSignerDecodeError, - /// Sender does not match attested enclave in report. - SenderIsNotAttestedEnclave, - /// Verifying RA report failed. - RemoteAttestationVerificationFailed, - RemoteAttestationTooOld, - /// The enclave cannot attest, because its building mode is not allowed. - SgxModeNotAllowed, - /// The enclave is not registered. - EnclaveIsNotRegistered, - /// The worker url is too long. - EnclaveUrlTooLong, - /// The Remote Attestation proof is too long. - RaProofTooLong, - /// No enclave is registered. - EmptyEnclaveRegistry, - /// The provided collateral data is invalid - CollateralInvalid, - /// It is not allowed to unregister enclaves with recent activity - UnregisterActiveEnclaveNotAllowed, - /// skipping attestation not allowed by configuration - SkippingAttestationNotAllowed, - } } impl Pallet {