From ea324e52e769ab0609b94b381350c21ef7644e65 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Wed, 13 Sep 2023 13:13:12 +0000 Subject: [PATCH 1/2] pruntime: Detect checkpoint breaking changes in unittest --- Cargo.lock | 2 + crates/phactory/Cargo.toml | 1 + crates/phactory/api/build.rs | 8 + crates/phactory/api/src/storage_sync.rs | 10 +- crates/phactory/src/contracts/pink.rs | 4 +- crates/phactory/src/contracts/support.rs | 9 +- .../phactory/src/contracts/support/keeper.rs | 19 +- crates/phactory/src/im_helpers.rs | 7 +- crates/phactory/src/lib.rs | 40 +- crates/phactory/src/light_validation/mod.rs | 8 +- ...pe_changes_that_affect_the_checkpoint.snap | 4022 +++++++++++++++++ crates/phactory/src/system/gk.rs | 19 +- crates/phactory/src/system/master_key.rs | 2 +- crates/phactory/src/system/mod.rs | 14 +- crates/phala-mq/src/dispatcher.rs | 19 +- crates/phala-mq/src/send_queue.rs | 3 +- crates/phala-mq/src/signer/mod.rs | 3 +- crates/phala-types/src/contract.rs | 4 +- crates/pink/runner/Cargo.toml | 1 + crates/pink/runner/src/storage.rs | 3 +- standalone/pruntime/Cargo.lock | 2 + 21 files changed, 4158 insertions(+), 42 deletions(-) create mode 100644 crates/phactory/src/snapshots/phactory__show_type_changes_that_affect_the_checkpoint.snap diff --git a/Cargo.lock b/Cargo.lock index b03cf8e1e9..06d4a4eee5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8969,6 +8969,7 @@ dependencies = [ "ring 0.16.20", "rmp-serde", "ron", + "scale-info", "scopeguard", "serde", "serde_cbor", @@ -9827,6 +9828,7 @@ dependencies = [ "pink", "pink-capi", "pink-extension-runtime", + "scale-info", "serde", "sp-runtime", "sp-weights", diff --git a/crates/phactory/Cargo.toml b/crates/phactory/Cargo.toml index 93a501629a..634fba34fb 100644 --- a/crates/phactory/Cargo.toml +++ b/crates/phactory/Cargo.toml @@ -80,6 +80,7 @@ libc = "0.2" environmental = "1" once_cell = "1" im = "15" +scale-info = { version = "2.9", default-features = false, features = ["derive"] } [dev-dependencies] insta = "1.7.2" diff --git a/crates/phactory/api/build.rs b/crates/phactory/api/build.rs index 1cbc9c0f13..8382217f5f 100644 --- a/crates/phactory/api/build.rs +++ b/crates/phactory/api/build.rs @@ -23,6 +23,14 @@ fn main() { ".pruntime_rpc", "#[derive(::serde::Serialize, ::serde::Deserialize)]", ); + for name in [ + "AttestationReport", + "InitRuntimeResponse", + "Attestation", + "NetworkConfig", + ] { + builder = builder.type_attribute(name, "#[derive(::scale_info::TypeInfo)]"); + } builder = builder.field_attribute("InitRuntimeResponse.attestation", "#[serde(skip,default)]"); for field in [ "GetContractInfoRequest.contracts", diff --git a/crates/phactory/api/src/storage_sync.rs b/crates/phactory/api/src/storage_sync.rs index 3df1efde73..862e5ba43e 100644 --- a/crates/phactory/api/src/storage_sync.rs +++ b/crates/phactory/api/src/storage_sync.rs @@ -98,7 +98,7 @@ pub trait StorageSynchronizer { fn state_validated(&self) -> bool; } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct BlockSyncState { validator: Validator, main_bridge: u64, @@ -272,9 +272,10 @@ pub struct Counters { pub waiting_for_paraheaders: bool, } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct SolochainSynchronizer { sync_state: BlockSyncState, + #[codec(skip)] state_roots: VecDeque, } @@ -344,11 +345,12 @@ impl StorageSynchronizer for SolochainSynchronizer { sync_state: BlockSyncState, last_relaychain_state_root: Option, para_header_number_next: chain::BlockNumber, + #[codec(skip)] para_state_roots: VecDeque, } @@ -473,7 +475,7 @@ impl StorageSynchronizer for ParachainSynchronizer { Solo(SolochainSynchronizer), Para(ParachainSynchronizer), diff --git a/crates/phactory/src/contracts/pink.rs b/crates/phactory/src/contracts/pink.rs index 9afa7a8af6..5e12985358 100644 --- a/crates/phactory/src/contracts/pink.rs +++ b/crates/phactory/src/contracts/pink.rs @@ -37,14 +37,14 @@ pub use phala_types::contract::InkCommand; pub(crate) mod http_counters; -#[derive(Serialize, Deserialize, Default, Clone)] +#[derive(Serialize, Deserialize, Default, Clone, ::scale_info::TypeInfo)] pub struct ClusterConfig { pub log_handler: Option, pub runtime_version: (u32, u32), pub secret_salt: [u8; 32], } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct Cluster { pub id: ContractClusterId, pub config: ClusterConfig, diff --git a/crates/phactory/src/contracts/support.rs b/crates/phactory/src/contracts/support.rs index aafa64d1a0..3bbc96aa58 100644 --- a/crates/phactory/src/contracts/support.rs +++ b/crates/phactory/src/contracts/support.rs @@ -102,12 +102,13 @@ impl<'de> Deserialize<'de> for SidevmHandle { } } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] struct SidevmInfo { code: Vec, code_hash: H256, start_time: String, auto_restart: bool, + #[codec(skip)] handle: Arc>, } @@ -116,10 +117,12 @@ pub(crate) enum SidevmCode { Code(Vec), } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct Contract { send_mq: SignedMessageChannel, + #[codec(skip)] cmd_rcv_mq: SecretReceiver, + #[codec(skip)] #[serde(with = "crate::secret_channel::ecdh_serde")] ecdh_key: KeyPair, cluster_id: phala_mq::ContractClusterId, @@ -130,7 +133,7 @@ pub struct Contract { on_block_end: Option, } -#[derive(Copy, Clone, Serialize, Deserialize)] +#[derive(Copy, Clone, Serialize, Deserialize, ::scale_info::TypeInfo)] struct OnBlockEnd { selector: u32, gas_limit: u64, diff --git a/crates/phactory/src/contracts/support/keeper.rs b/crates/phactory/src/contracts/support/keeper.rs index 98704db216..aef4cdd38e 100644 --- a/crates/phactory/src/contracts/support/keeper.rs +++ b/crates/phactory/src/contracts/support/keeper.rs @@ -1,15 +1,16 @@ -use im::OrdMap as BTreeMap; use pink::types::AccountId; use serde::{Deserialize, Serialize}; use sidevm::service::Spawner; -use crate::{contracts::Contract, im_helpers::ordmap_for_each_mut}; +use crate::{contracts::Contract, im_helpers::{ordmap_for_each_mut, OrdMap}}; -type ContractMap = BTreeMap; +type ContractMap = OrdMap; -#[derive(Default, Serialize, Deserialize, Clone)] +#[derive(Default, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct ContractsKeeper { + #[cfg_attr(not(test), codec(skip))] contracts: ContractMap, + #[codec(skip)] #[serde(skip)] pub(crate) weight_changed: bool, } @@ -71,7 +72,7 @@ impl ToWeight for Contract { } pub(super) fn calc_cache_quotas + Ord, C: ToWeight>( - contracts: &BTreeMap, + contracts: &OrdMap, ) -> impl Iterator { let total_weight = contracts .values() @@ -97,7 +98,7 @@ mod tests { #[test] fn zero_quotas_works() { - let mut contracts = BTreeMap::new(); + let mut contracts = OrdMap::new(); contracts.insert(b"foo", 0_u32); contracts.insert(b"bar", 0_u32); @@ -107,7 +108,7 @@ mod tests { #[test] fn little_quotas_works() { - let mut contracts = BTreeMap::new(); + let mut contracts = OrdMap::new(); contracts.insert(b"foo", 0_u32); contracts.insert(b"bar", 1_u32); @@ -120,7 +121,7 @@ mod tests { #[test] fn it_wont_overflow() { - let mut contracts = BTreeMap::new(); + let mut contracts = OrdMap::new(); contracts.insert(b"foo", 0_u32); contracts.insert(b"bar", u32::MAX); contracts.insert(b"baz", u32::MAX); @@ -138,7 +139,7 @@ mod tests { #[test] fn fraction_works() { - let mut contracts = BTreeMap::new(); + let mut contracts = OrdMap::new(); contracts.insert(b"foo", 0_u32); contracts.insert(b"bar", 1); contracts.insert(b"baz", u32::MAX); diff --git a/crates/phactory/src/im_helpers.rs b/crates/phactory/src/im_helpers.rs index 9f125589cf..29f1fbdb52 100644 --- a/crates/phactory/src/im_helpers.rs +++ b/crates/phactory/src/im_helpers.rs @@ -1,5 +1,10 @@ +#[cfg(not(test))] +pub use im::OrdMap; +#[cfg(test)] +pub use std::collections::BTreeMap as OrdMap; + pub fn ordmap_for_each_mut( - map: &mut im::OrdMap, + map: &mut OrdMap, mut f: impl FnMut((&K, &mut V)), ) { let snapshot = map.clone(); diff --git a/crates/phactory/src/lib.rs b/crates/phactory/src/lib.rs index ffd9df0c7c..9d730c4271 100644 --- a/crates/phactory/src/lib.rs +++ b/crates/phactory/src/lib.rs @@ -30,6 +30,7 @@ use core::convert::TryInto; use parity_scale_codec::{Decode, Encode}; use phala_types::{AttestationProvider, HandoverChallenge}; use ring::rand::SecureRandom; +use scale_info::TypeInfo; use serde_json::{json, Value}; use sp_core::{crypto::Pair, sr25519, H256}; @@ -79,17 +80,21 @@ mod types; // runtime definition locally. type RuntimeHasher = ::Hashing; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] struct RuntimeState { + #[codec(skip)] send_mq: MessageSendQueue, #[serde(skip)] + #[codec(skip)] recv_mq: MessageDispatcher, // chain storage synchonizing + #[cfg_attr(not(test), codec(skip))] storage_synchronizer: Synchronizer>, // TODO.kevin: use a better serialization approach + #[codec(skip)] chain_storage: ChainStorage, #[serde(with = "more::scale_bytes")] @@ -218,11 +223,12 @@ enum RuntimeDataSeal { V1(PersistentRuntimeData), } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, TypeInfo)] #[serde(bound(deserialize = "Platform: Deserialize<'de>"))] pub struct Phactory { platform: Platform, #[serde(skip)] + #[codec(skip)] pub args: Arc, dev_mode: bool, attestation_provider: Option, @@ -231,47 +237,70 @@ pub struct Phactory { runtime_state: Option, endpoints: BTreeMap, #[serde(skip)] + #[codec(skip)] signed_endpoints: Option, // The deserialzation of system requires the mq, which inside the runtime_state, to be ready. #[serde(skip)] system: Option>, // tmp key for WorkerKey handover encryption + #[codec(skip)] #[serde(skip)] pub(crate) handover_ecdh_key: Option, + #[codec(skip)] #[serde(skip)] handover_last_challenge: Option>, + #[codec(skip)] #[serde(skip)] #[serde(default = "Instant::now")] last_checkpoint: Instant, + + #[codec(skip)] #[serde(skip)] query_scheduler: RequestScheduler, #[serde(default)] netconfig: Option, + #[codec(skip)] #[serde(skip)] can_load_chain_state: bool, + #[codec(skip)] #[serde(skip)] trusted_sk: bool, + #[codec(skip)] #[serde(skip)] pub(crate) rcu_dispatching: bool, + #[codec(skip)] #[serde(skip)] pub(crate) pending_effects: Vec<::pink::types::ExecSideEffects>, + #[codec(skip)] #[serde(skip)] #[serde(default = "Instant::now")] started_at: Instant, + #[codec(skip)] #[serde(skip)] pub(crate) cluster_state_to_apply: Option>, } +#[test] +fn show_type_changes_that_affect_the_checkpoint() { + fn travel_types() -> String { + use scale_info::{IntoPortable, PortableRegistry}; + let mut registry = Default::default(); + let _ = T::type_info().into_portable(&mut registry); + serde_json::to_string_pretty(&PortableRegistry::from(registry).types).unwrap() + } + insta::assert_display_snapshot!(travel_types::>()); +} + #[derive(Serialize, Deserialize, Clone)] struct ClusterState<'a> { block_number: BlockNumber, @@ -615,8 +644,11 @@ impl Phactory info!("Succeeded to load checkpoint file {:?}", ckpt_filename); Ok(Some(state)) } - Err(_err /*Don't leak it into the log*/) => { - error!("Failed to load checkpoint file {:?}", ckpt_filename); + Err(err /*Don't leak it into the log*/) => { + error!( + "Failed to load checkpoint file {:?}: {err:?}", + ckpt_filename + ); if args.remove_corrupted_checkpoint { error!("Removing {:?}", ckpt_filename); std::fs::remove_file(ckpt_filename) diff --git a/crates/phactory/src/light_validation/mod.rs b/crates/phactory/src/light_validation/mod.rs index d60aeffd86..5c8a97d39e 100644 --- a/crates/phactory/src/light_validation/mod.rs +++ b/crates/phactory/src/light_validation/mod.rs @@ -39,7 +39,11 @@ mod justification; pub mod storage_proof; mod types; +#[cfg(not(test))] use im::OrdMap as BTreeMap; +#[cfg(test)] +// For TypeInfo derivation +use std::collections::BTreeMap; use std::fmt; use std::marker::PhantomData; @@ -61,7 +65,7 @@ use sp_runtime::EncodedJustification; pub use types::{AuthoritySet, AuthoritySetChange, BlockHeader}; -#[derive(Encode, Decode, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Encode, Decode, Clone, PartialEq, Serialize, Deserialize, ::scale_info::TypeInfo)] pub struct BridgeInfo { #[serde(skip)] _marker: PhantomData, @@ -94,7 +98,7 @@ impl Config for chain::Runtime { type Block = chain::Block; } -#[derive(Encode, Decode, Clone, Serialize, Deserialize)] +#[derive(Encode, Decode, Clone, Serialize, Deserialize, ::scale_info::TypeInfo)] pub struct LightValidation { num_bridges: BridgeId, #[serde(bound( diff --git a/crates/phactory/src/snapshots/phactory__show_type_changes_that_affect_the_checkpoint.snap b/crates/phactory/src/snapshots/phactory__show_type_changes_that_affect_the_checkpoint.snap new file mode 100644 index 0000000000..7f7def6d0f --- /dev/null +++ b/crates/phactory/src/snapshots/phactory__show_type_changes_that_affect_the_checkpoint.snap @@ -0,0 +1,4022 @@ +--- +source: crates/phactory/src/lib.rs +assertion_line: 301 +expression: "travel_types::>()" +--- +[ + { + "id": 0, + "type": { + "def": { + "tuple": [] + } + } + }, + { + "id": 1, + "type": { + "def": { + "primitive": "bool" + } + } + }, + { + "id": 2, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 3 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 3 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 3, + "type": { + "path": [ + "phala_types", + "AttestationProvider" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Root", + "index": 0 + }, + { + "name": "Ias", + "index": 1 + } + ] + } + } + } + }, + { + "id": 4, + "type": { + "def": { + "sequence": { + "type": 5 + } + } + } + }, + { + "id": 5, + "type": { + "def": { + "primitive": "u8" + } + } + }, + { + "id": 6, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 7 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 7 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 7, + "type": { + "path": [ + "phactory_api", + "proto_generated", + "pruntime_rpc", + "InitRuntimeResponse" + ], + "def": { + "composite": { + "fields": [ + { + "name": "encoded_runtime_info", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "encoded_genesis_block_hash", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "encoded_public_key", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "encoded_ecdh_public_key", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "attestation", + "type": 8, + "typeName": "::core::option::Option" + } + ] + } + } + } + }, + { + "id": 8, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 9 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 9 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 9, + "type": { + "path": [ + "phactory_api", + "proto_generated", + "pruntime_rpc", + "Attestation" + ], + "def": { + "composite": { + "fields": [ + { + "name": "version", + "type": 10, + "typeName": "i32" + }, + { + "name": "provider", + "type": 11, + "typeName": "::prost::alloc::string::String" + }, + { + "name": "payload", + "type": 12, + "typeName": "::core::option::Option" + }, + { + "name": "encoded_report", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "timestamp", + "type": 14, + "typeName": "u64" + } + ] + } + } + } + }, + { + "id": 10, + "type": { + "def": { + "primitive": "i32" + } + } + }, + { + "id": 11, + "type": { + "def": { + "primitive": "str" + } + } + }, + { + "id": 12, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 13 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 13 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 13, + "type": { + "path": [ + "phactory_api", + "proto_generated", + "pruntime_rpc", + "AttestationReport" + ], + "def": { + "composite": { + "fields": [ + { + "name": "report", + "type": 11, + "typeName": "::prost::alloc::string::String" + }, + { + "name": "signature", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + }, + { + "name": "signing_cert", + "type": 4, + "typeName": "::prost::alloc::vec::Vec" + } + ] + } + } + } + }, + { + "id": 14, + "type": { + "def": { + "primitive": "u64" + } + } + }, + { + "id": 15, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 16 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 16 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 16, + "type": { + "path": [ + "phactory", + "RuntimeState" + ], + "def": { + "composite": { + "fields": [ + { + "name": "storage_synchronizer", + "type": 17, + "typeName": "Synchronizer>" + }, + { + "name": "genesis_block_hash", + "type": 24, + "typeName": "H256" + }, + { + "name": "para_id", + "type": 23, + "typeName": "u32" + } + ] + } + } + } + }, + { + "id": 17, + "type": { + "path": [ + "phactory_api", + "storage_sync", + "Synchronizer" + ], + "params": [ + { + "name": "Validator", + "type": 18 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "Solo", + "fields": [ + { + "type": 38, + "typeName": "SolochainSynchronizer" + } + ], + "index": 0 + }, + { + "name": "Para", + "fields": [ + { + "type": 40, + "typeName": "ParachainSynchronizer" + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 18, + "type": { + "path": [ + "phactory", + "light_validation", + "LightValidation" + ], + "params": [ + { + "name": "T", + "type": 19 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "num_bridges", + "type": 14, + "typeName": "BridgeId" + }, + { + "name": "tracked_bridges", + "type": 20, + "typeName": "BTreeMap>" + } + ] + } + } + } + }, + { + "id": 19, + "type": { + "path": [ + "phala_node_runtime", + "Runtime" + ], + "def": { + "composite": {} + } + } + }, + { + "id": 20, + "type": { + "path": [ + "BTreeMap" + ], + "params": [ + { + "name": "K", + "type": 14 + }, + { + "name": "V", + "type": 21 + } + ], + "def": { + "composite": { + "fields": [ + { + "type": 36 + } + ] + } + } + } + }, + { + "id": 21, + "type": { + "path": [ + "phactory", + "light_validation", + "BridgeInfo" + ], + "params": [ + { + "name": "T", + "type": 19 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "last_finalized_block_header", + "type": 22, + "typeName": "BlockHeader" + }, + { + "name": "current_set", + "type": 31, + "typeName": "AuthoritySet" + } + ] + } + } + } + }, + { + "id": 22, + "type": { + "path": [ + "sp_runtime", + "generic", + "header", + "Header" + ], + "params": [ + { + "name": "Number", + "type": 23 + }, + { + "name": "Hash", + "type": null + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "parent_hash", + "type": 24, + "typeName": "Hash::Output" + }, + { + "name": "number", + "type": 26, + "typeName": "Number" + }, + { + "name": "state_root", + "type": 24, + "typeName": "Hash::Output" + }, + { + "name": "extrinsics_root", + "type": 24, + "typeName": "Hash::Output" + }, + { + "name": "digest", + "type": 27, + "typeName": "Digest" + } + ] + } + } + } + }, + { + "id": 23, + "type": { + "def": { + "primitive": "u32" + } + } + }, + { + "id": 24, + "type": { + "path": [ + "primitive_types", + "H256" + ], + "def": { + "composite": { + "fields": [ + { + "type": 25, + "typeName": "[u8; 32]" + } + ] + } + } + } + }, + { + "id": 25, + "type": { + "def": { + "array": { + "len": 32, + "type": 5 + } + } + } + }, + { + "id": 26, + "type": { + "def": { + "compact": { + "type": 23 + } + } + } + }, + { + "id": 27, + "type": { + "path": [ + "sp_runtime", + "generic", + "digest", + "Digest" + ], + "def": { + "composite": { + "fields": [ + { + "name": "logs", + "type": 28, + "typeName": "Vec" + } + ] + } + } + } + }, + { + "id": 28, + "type": { + "def": { + "sequence": { + "type": 29 + } + } + } + }, + { + "id": 29, + "type": { + "path": [ + "sp_runtime", + "generic", + "digest", + "DigestItem" + ], + "def": { + "variant": { + "variants": [ + { + "name": "PreRuntime", + "fields": [ + { + "type": 30, + "typeName": "ConsensusEngineId" + }, + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 6 + }, + { + "name": "Consensus", + "fields": [ + { + "type": 30, + "typeName": "ConsensusEngineId" + }, + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 4 + }, + { + "name": "Seal", + "fields": [ + { + "type": 30, + "typeName": "ConsensusEngineId" + }, + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 5 + }, + { + "name": "Other", + "fields": [ + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 0 + }, + { + "name": "RuntimeEnvironmentUpdated", + "index": 8 + } + ] + } + } + } + }, + { + "id": 30, + "type": { + "def": { + "array": { + "len": 4, + "type": 5 + } + } + } + }, + { + "id": 31, + "type": { + "path": [ + "phactory_api", + "blocks", + "AuthoritySet" + ], + "def": { + "composite": { + "fields": [ + { + "name": "list", + "type": 32, + "typeName": "AuthorityList" + }, + { + "name": "id", + "type": 14, + "typeName": "SetId" + } + ] + } + } + } + }, + { + "id": 32, + "type": { + "def": { + "sequence": { + "type": 33 + } + } + } + }, + { + "id": 33, + "type": { + "def": { + "tuple": [ + 34, + 14 + ] + } + } + }, + { + "id": 34, + "type": { + "path": [ + "sp_consensus_grandpa", + "app", + "Public" + ], + "def": { + "composite": { + "fields": [ + { + "type": 35, + "typeName": "ed25519::Public" + } + ] + } + } + } + }, + { + "id": 35, + "type": { + "path": [ + "sp_core", + "ed25519", + "Public" + ], + "def": { + "composite": { + "fields": [ + { + "type": 25, + "typeName": "[u8; 32]" + } + ] + } + } + } + }, + { + "id": 36, + "type": { + "def": { + "sequence": { + "type": 37 + } + } + } + }, + { + "id": 37, + "type": { + "def": { + "tuple": [ + 14, + 21 + ] + } + } + }, + { + "id": 38, + "type": { + "path": [ + "phactory_api", + "storage_sync", + "SolochainSynchronizer" + ], + "params": [ + { + "name": "Validator", + "type": 18 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "sync_state", + "type": 39, + "typeName": "BlockSyncState" + } + ] + } + } + } + }, + { + "id": 39, + "type": { + "path": [ + "phactory_api", + "storage_sync", + "BlockSyncState" + ], + "params": [ + { + "name": "Validator", + "type": 18 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "validator", + "type": 18, + "typeName": "Validator" + }, + { + "name": "main_bridge", + "type": 14, + "typeName": "u64" + }, + { + "name": "header_number_next", + "type": 23, + "typeName": "chain::BlockNumber" + }, + { + "name": "block_number_next", + "type": 23, + "typeName": "chain::BlockNumber" + }, + { + "name": "genesis_state_validated", + "type": 1, + "typeName": "bool" + } + ] + } + } + } + }, + { + "id": 40, + "type": { + "path": [ + "phactory_api", + "storage_sync", + "ParachainSynchronizer" + ], + "params": [ + { + "name": "Validator", + "type": 18 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "sync_state", + "type": 39, + "typeName": "BlockSyncState" + }, + { + "name": "last_relaychain_state_root", + "type": 41, + "typeName": "Option" + }, + { + "name": "para_header_number_next", + "type": 23, + "typeName": "chain::BlockNumber" + } + ] + } + } + } + }, + { + "id": 41, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 24 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 24 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 42, + "type": { + "path": [ + "BTreeMap" + ], + "params": [ + { + "name": "K", + "type": 43 + }, + { + "name": "V", + "type": 11 + } + ], + "def": { + "composite": { + "fields": [ + { + "type": 44 + } + ] + } + } + } + }, + { + "id": 43, + "type": { + "path": [ + "phactory_api", + "endpoints", + "EndpointType" + ], + "def": { + "variant": { + "variants": [ + { + "name": "I2p", + "index": 0 + }, + { + "name": "Http", + "index": 1 + } + ] + } + } + } + }, + { + "id": 44, + "type": { + "def": { + "sequence": { + "type": 45 + } + } + } + }, + { + "id": 45, + "type": { + "def": { + "tuple": [ + 43, + 11 + ] + } + } + }, + { + "id": 46, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 47 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 47 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 47, + "type": { + "path": [ + "phactory", + "system", + "System" + ], + "params": [ + { + "name": "Platform", + "type": 0 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "platform", + "type": 0, + "typeName": "Platform" + }, + { + "name": "dev_mode", + "type": 1, + "typeName": "bool" + }, + { + "name": "sealing_path", + "type": 11, + "typeName": "String" + }, + { + "name": "storage_path", + "type": 11, + "typeName": "String" + }, + { + "name": "egress", + "type": 48, + "typeName": "SignedMessageChannel" + }, + { + "name": "system_events", + "type": 52, + "typeName": "TypedReceiver" + }, + { + "name": "gatekeeper_launch_events", + "type": 62, + "typeName": "TypedReceiver" + }, + { + "name": "gatekeeper_change_events", + "type": 69, + "typeName": "TypedReceiver" + }, + { + "name": "key_distribution_events", + "type": 72, + "typeName": "TypedReceiver>" + }, + { + "name": "cluster_key_distribution_events", + "type": 84, + "typeName": "TypedReceiver>" + }, + { + "name": "contract_operation_events", + "type": 89, + "typeName": "TypedReceiver>" + }, + { + "name": "worker_state", + "type": 94, + "typeName": "WorkerState" + }, + { + "name": "gatekeeper", + "type": 100, + "typeName": "Option>" + }, + { + "name": "contracts", + "type": 119, + "typeName": "ContractsKeeper" + }, + { + "name": "contract_cluster", + "type": 128, + "typeName": "Option" + }, + { + "name": "block_number", + "type": 23, + "typeName": "BlockNumber" + }, + { + "name": "now_ms", + "type": 14, + "typeName": "u64" + }, + { + "name": "genesis_block", + "type": 23, + "typeName": "BlockNumber" + } + ] + } + } + } + }, + { + "id": 48, + "type": { + "path": [ + "phala_mq", + "send_queue", + "msg_channel", + "MessageChannel" + ], + "params": [ + { + "name": "Si", + "type": 49 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "sender", + "type": 50, + "typeName": "SenderId" + }, + { + "name": "signer", + "type": 49, + "typeName": "Si" + } + ] + } + } + } + }, + { + "id": 49, + "type": { + "path": [ + "phala_mq", + "signer", + "signers", + "Sr25519Signer" + ], + "def": { + "composite": {} + } + } + }, + { + "id": 50, + "type": { + "path": [ + "phala_mq", + "types", + "MessageOrigin" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Pallet", + "fields": [ + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 0 + }, + { + "name": "Contract", + "fields": [ + { + "type": 24, + "typeName": "ContractId" + } + ], + "index": 1 + }, + { + "name": "Worker", + "fields": [ + { + "type": 51, + "typeName": "sp_core::sr25519::Public" + } + ], + "index": 2 + }, + { + "name": "AccountId", + "fields": [ + { + "type": 24, + "typeName": "AccountId" + } + ], + "index": 3 + }, + { + "name": "MultiLocation", + "fields": [ + { + "type": 4, + "typeName": "Vec" + } + ], + "index": 4 + }, + { + "name": "Gatekeeper", + "index": 5 + }, + { + "name": "Cluster", + "fields": [ + { + "type": 24, + "typeName": "ContractClusterId" + } + ], + "index": 6 + }, + { + "name": "Reserved", + "index": 255 + } + ] + } + } + } + }, + { + "id": 51, + "type": { + "path": [ + "sp_core", + "sr25519", + "Public" + ], + "def": { + "composite": { + "fields": [ + { + "type": 25, + "typeName": "[u8; 32]" + } + ] + } + } + } + }, + { + "id": 52, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 53 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 53, + "type": { + "path": [ + "phala_types", + "messaging", + "SystemEvent" + ], + "def": { + "variant": { + "variants": [ + { + "name": "WorkerEvent", + "fields": [ + { + "type": 54, + "typeName": "WorkerEventWithKey" + } + ], + "index": 0 + }, + { + "name": "HeartbeatChallenge", + "fields": [ + { + "type": 58, + "typeName": "HeartbeatChallenge" + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 54, + "type": { + "path": [ + "phala_types", + "messaging", + "WorkerEventWithKey" + ], + "def": { + "composite": { + "fields": [ + { + "name": "pubkey", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "event", + "type": 55, + "typeName": "WorkerEvent" + } + ] + } + } + } + }, + { + "id": 55, + "type": { + "path": [ + "phala_types", + "messaging", + "WorkerEvent" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Registered", + "fields": [ + { + "type": 56, + "typeName": "WorkerInfo" + } + ], + "index": 0 + }, + { + "name": "BenchStart", + "fields": [ + { + "name": "duration", + "type": 23, + "typeName": "u32" + } + ], + "index": 1 + }, + { + "name": "BenchScore", + "fields": [ + { + "type": 23, + "typeName": "u32" + } + ], + "index": 2 + }, + { + "name": "Started", + "fields": [ + { + "name": "session_id", + "type": 23, + "typeName": "u32" + }, + { + "name": "init_v", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "init_p", + "type": 23, + "typeName": "u32" + } + ], + "index": 3 + }, + { + "name": "Stopped", + "index": 4 + }, + { + "name": "EnterUnresponsive", + "index": 5 + }, + { + "name": "ExitUnresponsive", + "index": 6 + } + ] + } + } + } + }, + { + "id": 56, + "type": { + "path": [ + "phala_types", + "messaging", + "WorkerInfo" + ], + "def": { + "composite": { + "fields": [ + { + "name": "confidence_level", + "type": 5, + "typeName": "u8" + } + ] + } + } + } + }, + { + "id": 57, + "type": { + "def": { + "primitive": "u128" + } + } + }, + { + "id": 58, + "type": { + "path": [ + "phala_types", + "messaging", + "HeartbeatChallenge" + ], + "def": { + "composite": { + "fields": [ + { + "name": "seed", + "type": 59, + "typeName": "U256" + }, + { + "name": "online_target", + "type": 59, + "typeName": "U256" + } + ] + } + } + } + }, + { + "id": 59, + "type": { + "path": [ + "primitive_types", + "U256" + ], + "def": { + "composite": { + "fields": [ + { + "type": 60, + "typeName": "[u64; 4]" + } + ] + } + } + } + }, + { + "id": 60, + "type": { + "def": { + "array": { + "len": 4, + "type": 14 + } + } + } + }, + { + "id": 61, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "ReceiverTypeInfo" + ], + "def": { + "composite": { + "fields": [ + { + "name": "inner", + "type": 0, + "typeName": "()" + }, + { + "name": "topic", + "type": 4, + "typeName": "Vec" + } + ] + } + } + } + }, + { + "id": 62, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 63 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 63, + "type": { + "path": [ + "phala_types", + "messaging", + "GatekeeperLaunch" + ], + "def": { + "variant": { + "variants": [ + { + "name": "FirstGatekeeper", + "fields": [ + { + "type": 64, + "typeName": "NewGatekeeperEvent" + } + ], + "index": 0 + }, + { + "name": "MasterPubkeyOnChain", + "fields": [ + { + "type": 65, + "typeName": "MasterPubkeyEvent" + } + ], + "index": 1 + }, + { + "name": "RotateMasterKey", + "fields": [ + { + "type": 66, + "typeName": "RotateMasterKeyEvent" + } + ], + "index": 2 + }, + { + "name": "MasterPubkeyRotated", + "fields": [ + { + "type": 65, + "typeName": "MasterPubkeyEvent" + } + ], + "index": 3 + } + ] + } + } + } + }, + { + "id": 64, + "type": { + "path": [ + "phala_types", + "messaging", + "NewGatekeeperEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "pubkey", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "ecdh_pubkey", + "type": 51, + "typeName": "EcdhPublicKey" + } + ] + } + } + } + }, + { + "id": 65, + "type": { + "path": [ + "phala_types", + "messaging", + "MasterPubkeyEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "master_pubkey", + "type": 51, + "typeName": "MasterPublicKey" + } + ] + } + } + } + }, + { + "id": 66, + "type": { + "path": [ + "phala_types", + "messaging", + "RotateMasterKeyEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "rotation_id", + "type": 14, + "typeName": "u64" + }, + { + "name": "gk_identities", + "type": 67, + "typeName": "Vec" + } + ] + } + } + } + }, + { + "id": 67, + "type": { + "def": { + "sequence": { + "type": 68 + } + } + } + }, + { + "id": 68, + "type": { + "path": [ + "phala_types", + "WorkerIdentity" + ], + "def": { + "composite": { + "fields": [ + { + "name": "pubkey", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "ecdh_pubkey", + "type": 51, + "typeName": "EcdhPublicKey" + } + ] + } + } + } + }, + { + "id": 69, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 70 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 70, + "type": { + "path": [ + "phala_types", + "messaging", + "GatekeeperChange" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Registered", + "fields": [ + { + "type": 64, + "typeName": "NewGatekeeperEvent" + } + ], + "index": 0 + }, + { + "name": "Unregistered", + "fields": [ + { + "type": 71, + "typeName": "RemoveGatekeeperEvent" + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 71, + "type": { + "path": [ + "phala_types", + "messaging", + "RemoveGatekeeperEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "pubkey", + "type": 51, + "typeName": "WorkerPublicKey" + } + ] + } + } + } + }, + { + "id": 72, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 73 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 73, + "type": { + "path": [ + "phala_types", + "messaging", + "KeyDistribution" + ], + "params": [ + { + "name": "BlockNumber", + "type": 23 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "MasterKeyDistribution", + "fields": [ + { + "type": 74, + "typeName": "DispatchMasterKeyEvent" + } + ], + "index": 0 + }, + { + "name": "MasterKeyRotation", + "fields": [ + { + "type": 76, + "typeName": "BatchRotateMasterKeyEvent" + } + ], + "index": 1 + }, + { + "name": "MasterKeyHistory", + "fields": [ + { + "type": 81, + "typeName": "DispatchMasterKeyHistoryEvent" + } + ], + "index": 2 + } + ] + } + } + } + }, + { + "id": 74, + "type": { + "path": [ + "phala_types", + "messaging", + "DispatchMasterKeyEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "dest", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "ecdh_pubkey", + "type": 51, + "typeName": "EcdhPublicKey" + }, + { + "name": "encrypted_master_key", + "type": 4, + "typeName": "Vec" + }, + { + "name": "iv", + "type": 75, + "typeName": "AeadIV" + } + ] + } + } + } + }, + { + "id": 75, + "type": { + "def": { + "array": { + "len": 12, + "type": 5 + } + } + } + }, + { + "id": 76, + "type": { + "path": [ + "phala_types", + "messaging", + "BatchRotateMasterKeyEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "rotation_id", + "type": 14, + "typeName": "u64" + }, + { + "name": "secret_keys", + "type": 77, + "typeName": "BTreeMap" + }, + { + "name": "sender", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "sig", + "type": 4, + "typeName": "Vec" + } + ] + } + } + } + }, + { + "id": 77, + "type": { + "path": [ + "BTreeMap" + ], + "params": [ + { + "name": "K", + "type": 51 + }, + { + "name": "V", + "type": 78 + } + ], + "def": { + "composite": { + "fields": [ + { + "type": 79 + } + ] + } + } + } + }, + { + "id": 78, + "type": { + "path": [ + "phala_types", + "messaging", + "EncryptedKey" + ], + "def": { + "composite": { + "fields": [ + { + "name": "ecdh_pubkey", + "type": 51, + "typeName": "EcdhPublicKey" + }, + { + "name": "encrypted_key", + "type": 4, + "typeName": "Vec" + }, + { + "name": "iv", + "type": 75, + "typeName": "AeadIV" + } + ] + } + } + } + }, + { + "id": 79, + "type": { + "def": { + "sequence": { + "type": 80 + } + } + } + }, + { + "id": 80, + "type": { + "def": { + "tuple": [ + 51, + 78 + ] + } + } + }, + { + "id": 81, + "type": { + "path": [ + "phala_types", + "messaging", + "DispatchMasterKeyHistoryEvent" + ], + "params": [ + { + "name": "BlockNumber", + "type": 23 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "dest", + "type": 51, + "typeName": "WorkerPublicKey" + }, + { + "name": "encrypted_master_key_history", + "type": 82, + "typeName": "Vec<(u64, BlockNumber, EncryptedKey)>" + } + ] + } + } + } + }, + { + "id": 82, + "type": { + "def": { + "sequence": { + "type": 83 + } + } + } + }, + { + "id": 83, + "type": { + "def": { + "tuple": [ + 14, + 23, + 78 + ] + } + } + }, + { + "id": 84, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 85 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 85, + "type": { + "path": [ + "phala_types", + "contract", + "messaging", + "ClusterOperation" + ], + "params": [ + { + "name": "AccountId", + "type": 86 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "DispatchKeys", + "fields": [ + { + "type": 87, + "typeName": "BatchDispatchClusterKeyEvent" + } + ], + "index": 0 + }, + { + "name": "DestroyCluster", + "fields": [ + { + "type": 24, + "typeName": "ContractClusterId" + } + ], + "index": 1 + }, + { + "name": "UploadResource", + "fields": [ + { + "name": "origin", + "type": 86, + "typeName": "AccountId" + }, + { + "name": "cluster_id", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "resource_type", + "type": 88, + "typeName": "ResourceType" + }, + { + "name": "resource_data", + "type": 4, + "typeName": "Vec" + } + ], + "index": 2 + }, + { + "name": "Deposit", + "fields": [ + { + "name": "cluster_id", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "account", + "type": 86, + "typeName": "AccountId" + }, + { + "name": "amount", + "type": 57, + "typeName": "u128" + } + ], + "index": 3 + }, + { + "name": "RemoveWorker", + "fields": [ + { + "name": "cluster_id", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "worker", + "type": 51, + "typeName": "WorkerPublicKey" + } + ], + "index": 4 + } + ] + } + } + } + }, + { + "id": 86, + "type": { + "path": [ + "sp_core", + "crypto", + "AccountId32" + ], + "def": { + "composite": { + "fields": [ + { + "type": 25, + "typeName": "[u8; 32]" + } + ] + } + } + } + }, + { + "id": 87, + "type": { + "path": [ + "phala_types", + "contract", + "messaging", + "BatchDispatchClusterKeyEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "secret_keys", + "type": 77, + "typeName": "BTreeMap" + }, + { + "name": "cluster", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "owner", + "type": 86, + "typeName": "AccountId32" + }, + { + "name": "deposit", + "type": 57, + "typeName": "u128" + }, + { + "name": "gas_price", + "type": 57, + "typeName": "u128" + }, + { + "name": "deposit_per_item", + "type": 57, + "typeName": "u128" + }, + { + "name": "deposit_per_byte", + "type": 57, + "typeName": "u128" + }, + { + "name": "treasury_account", + "type": 86, + "typeName": "AccountId32" + } + ] + } + } + } + }, + { + "id": 88, + "type": { + "path": [ + "phala_types", + "contract", + "messaging", + "ResourceType" + ], + "def": { + "variant": { + "variants": [ + { + "name": "InkCode", + "index": 0 + }, + { + "name": "SidevmCode", + "index": 1 + }, + { + "name": "IndeterministicInkCode", + "index": 2 + } + ] + } + } + } + }, + { + "id": 89, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 90 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 90, + "type": { + "path": [ + "phala_types", + "contract", + "messaging", + "ContractOperation" + ], + "params": [ + { + "name": "CodeHash", + "type": 24 + }, + { + "name": "AccountId", + "type": 86 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "InstantiateCode", + "fields": [ + { + "name": "contract_info", + "type": 91, + "typeName": "ContractInfo" + }, + { + "name": "transfer", + "type": 57, + "typeName": "u128" + }, + { + "name": "gas_limit", + "type": 14, + "typeName": "u64" + }, + { + "name": "storage_deposit_limit", + "type": 93, + "typeName": "Option" + } + ], + "index": 0 + } + ] + } + } + } + }, + { + "id": 91, + "type": { + "path": [ + "phala_types", + "contract", + "ContractInfo" + ], + "params": [ + { + "name": "CodeHash", + "type": 24 + }, + { + "name": "AccountId", + "type": 86 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "deployer", + "type": 86, + "typeName": "AccountId" + }, + { + "name": "code_index", + "type": 92, + "typeName": "CodeIndex" + }, + { + "name": "salt", + "type": 4, + "typeName": "Vec" + }, + { + "name": "cluster_id", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "instantiate_data", + "type": 4, + "typeName": "Vec" + } + ] + } + } + } + }, + { + "id": 92, + "type": { + "path": [ + "phala_types", + "contract", + "CodeIndex" + ], + "params": [ + { + "name": "CodeHash", + "type": 24 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "WasmCode", + "fields": [ + { + "type": 24, + "typeName": "CodeHash" + } + ], + "index": 0 + } + ] + } + } + } + }, + { + "id": 93, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 57 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 57 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 94, + "type": { + "path": [ + "phactory", + "system", + "WorkerState" + ], + "def": { + "composite": { + "fields": [ + { + "name": "hashed_id", + "type": 59, + "typeName": "U256" + }, + { + "name": "registered", + "type": 1, + "typeName": "bool" + }, + { + "name": "bench_state", + "type": 95, + "typeName": "Option" + }, + { + "name": "working_state", + "type": 97, + "typeName": "Option" + } + ] + } + } + } + }, + { + "id": 95, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 96 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 96 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 96, + "type": { + "path": [ + "phactory", + "system", + "BenchState" + ], + "def": { + "composite": { + "fields": [ + { + "name": "start_block", + "type": 23, + "typeName": "chain::BlockNumber" + }, + { + "name": "start_time", + "type": 14, + "typeName": "u64" + }, + { + "name": "start_iter", + "type": 14, + "typeName": "u64" + }, + { + "name": "duration", + "type": 23, + "typeName": "u32" + } + ] + } + } + } + }, + { + "id": 97, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 98 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 98 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 98, + "type": { + "path": [ + "phactory", + "system", + "WorkingInfo" + ], + "def": { + "composite": { + "fields": [ + { + "name": "session_id", + "type": 23, + "typeName": "u32" + }, + { + "name": "state", + "type": 99, + "typeName": "WorkingState" + }, + { + "name": "start_time", + "type": 14, + "typeName": "u64" + }, + { + "name": "start_iter", + "type": 14, + "typeName": "u64" + } + ] + } + } + } + }, + { + "id": 99, + "type": { + "path": [ + "phactory", + "system", + "WorkingState" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Computing", + "index": 0 + }, + { + "name": "Paused", + "index": 1 + } + ] + } + } + } + }, + { + "id": 100, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 101 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 101 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 101, + "type": { + "path": [ + "phactory", + "system", + "gk", + "Gatekeeper" + ], + "params": [ + { + "name": "MsgChan", + "type": 48 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "master_pubkey_on_chain", + "type": 1, + "typeName": "bool" + }, + { + "name": "registered_on_chain", + "type": 1, + "typeName": "bool" + }, + { + "name": "master_key_history", + "type": 102, + "typeName": "Vec" + }, + { + "name": "egress", + "type": 48, + "typeName": "MsgChan" + }, + { + "name": "gatekeeper_events", + "type": 105, + "typeName": "TypedReceiver" + }, + { + "name": "cluster_events", + "type": 109, + "typeName": "TypedReceiver" + }, + { + "name": "last_random_number", + "type": 25, + "typeName": "RandomNumber" + }, + { + "name": "iv_seq", + "type": 14, + "typeName": "u64" + }, + { + "name": "computing_economics", + "type": 111, + "typeName": "ComputingEconomics" + } + ] + } + } + } + }, + { + "id": 102, + "type": { + "def": { + "sequence": { + "type": 103 + } + } + } + }, + { + "id": 103, + "type": { + "path": [ + "phactory", + "system", + "master_key", + "RotatedMasterKey" + ], + "def": { + "composite": { + "fields": [ + { + "name": "rotation_id", + "type": 14, + "typeName": "u64" + }, + { + "name": "block_height", + "type": 23, + "typeName": "chain::BlockNumber" + }, + { + "name": "secret", + "type": 104, + "typeName": "Sr25519SecretKey" + } + ] + } + } + } + }, + { + "id": 104, + "type": { + "def": { + "array": { + "len": 64, + "type": 5 + } + } + } + }, + { + "id": 105, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 106 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 106, + "type": { + "path": [ + "phala_types", + "messaging", + "GatekeeperEvent" + ], + "def": { + "variant": { + "variants": [ + { + "name": "NewRandomNumber", + "fields": [ + { + "type": 107, + "typeName": "RandomNumberEvent" + } + ], + "index": 0 + }, + { + "name": "TokenomicParametersChanged", + "fields": [ + { + "type": 108, + "typeName": "TokenomicParameters" + } + ], + "index": 1 + }, + { + "name": "_RepairV", + "index": 2 + }, + { + "name": "_PhalaLaunched", + "index": 3 + }, + { + "name": "_UnrespFix", + "index": 4 + } + ] + } + } + } + }, + { + "id": 107, + "type": { + "path": [ + "phala_types", + "messaging", + "RandomNumberEvent" + ], + "def": { + "composite": { + "fields": [ + { + "name": "block_number", + "type": 23, + "typeName": "u32" + }, + { + "name": "random_number", + "type": 25, + "typeName": "RandomNumber" + }, + { + "name": "last_random_number", + "type": 25, + "typeName": "RandomNumber" + } + ] + } + } + } + }, + { + "id": 108, + "type": { + "path": [ + "phala_types", + "messaging", + "TokenomicParameters" + ], + "def": { + "composite": { + "fields": [ + { + "name": "pha_rate", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "rho", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "budget_per_block", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "v_max", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "cost_k", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "cost_b", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "slash_rate", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "treasury_ratio", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "heartbeat_window", + "type": 23, + "typeName": "u32" + }, + { + "name": "rig_k", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "rig_b", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "re", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "k", + "type": 57, + "typeName": "U64F64Bits" + }, + { + "name": "kappa", + "type": 57, + "typeName": "U64F64Bits" + } + ] + } + } + } + }, + { + "id": 109, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 110 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 110, + "type": { + "path": [ + "phala_types", + "contract", + "messaging", + "ClusterEvent" + ], + "def": { + "variant": { + "variants": [ + { + "name": "DeployCluster", + "fields": [ + { + "name": "owner", + "type": 86, + "typeName": "AccountId32" + }, + { + "name": "cluster", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "workers", + "type": 67, + "typeName": "Vec" + }, + { + "name": "deposit", + "type": 57, + "typeName": "u128" + }, + { + "name": "gas_price", + "type": 57, + "typeName": "u128" + }, + { + "name": "deposit_per_item", + "type": 57, + "typeName": "u128" + }, + { + "name": "deposit_per_byte", + "type": 57, + "typeName": "u128" + }, + { + "name": "treasury_account", + "type": 86, + "typeName": "AccountId32" + } + ], + "index": 0 + } + ] + } + } + } + }, + { + "id": 111, + "type": { + "path": [ + "phactory", + "system", + "gk", + "ComputingEconomics" + ], + "params": [ + { + "name": "MsgChan", + "type": 48 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "egress", + "type": 48, + "typeName": "MsgChan" + }, + { + "name": "computing_events", + "type": 112, + "typeName": "TypedReceiver" + }, + { + "name": "system_events", + "type": 52, + "typeName": "TypedReceiver" + }, + { + "name": "gatekeeper_events", + "type": 105, + "typeName": "TypedReceiver" + }, + { + "name": "workers", + "type": 114, + "typeName": "OrdMap" + } + ] + } + } + } + }, + { + "id": 112, + "type": { + "path": [ + "phala_mq", + "dispatcher", + "TypedReceiver" + ], + "params": [ + { + "name": "T", + "type": 113 + } + ], + "def": { + "composite": { + "fields": [ + { + "name": "queue", + "type": 61, + "typeName": "Receiver" + } + ] + } + } + } + }, + { + "id": 113, + "type": { + "path": [ + "phala_types", + "messaging", + "WorkingReportEvent" + ], + "def": { + "variant": { + "variants": [ + { + "name": "Heartbeat", + "fields": [ + { + "name": "session_id", + "type": 23, + "typeName": "u32" + }, + { + "name": "challenge_block", + "type": 23, + "typeName": "u32" + }, + { + "name": "challenge_time", + "type": 14, + "typeName": "u64" + }, + { + "name": "iterations", + "type": 14, + "typeName": "u64" + } + ], + "index": 0 + }, + { + "name": "HeartbeatV2", + "fields": [ + { + "name": "session_id", + "type": 23, + "typeName": "u32" + }, + { + "name": "challenge_block", + "type": 23, + "typeName": "u32" + }, + { + "name": "challenge_time", + "type": 14, + "typeName": "u64" + }, + { + "name": "iterations", + "type": 14, + "typeName": "u64" + }, + { + "name": "n_clusters", + "type": 23, + "typeName": "u32" + }, + { + "name": "n_contracts", + "type": 23, + "typeName": "u32" + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 114, + "type": { + "path": [ + "BTreeMap" + ], + "params": [ + { + "name": "K", + "type": 51 + }, + { + "name": "V", + "type": 115 + } + ], + "def": { + "composite": { + "fields": [ + { + "type": 117 + } + ] + } + } + } + }, + { + "id": 115, + "type": { + "path": [ + "phactory", + "system", + "gk", + "WorkerInfo" + ], + "def": { + "composite": { + "fields": [ + { + "name": "state", + "type": 94, + "typeName": "WorkerState" + }, + { + "name": "waiting_heartbeats", + "type": 116, + "typeName": "VecDeque" + }, + { + "name": "unresponsive", + "type": 1, + "typeName": "bool" + }, + { + "name": "heartbeat_flag", + "type": 1, + "typeName": "bool" + } + ] + } + } + } + }, + { + "id": 116, + "type": { + "def": { + "sequence": { + "type": 23 + } + } + } + }, + { + "id": 117, + "type": { + "def": { + "sequence": { + "type": 118 + } + } + } + }, + { + "id": 118, + "type": { + "def": { + "tuple": [ + 51, + 115 + ] + } + } + }, + { + "id": 119, + "type": { + "path": [ + "phactory", + "contracts", + "support", + "keeper", + "ContractsKeeper" + ], + "def": { + "composite": { + "fields": [ + { + "name": "contracts", + "type": 120, + "typeName": "ContractMap" + } + ] + } + } + } + }, + { + "id": 120, + "type": { + "path": [ + "BTreeMap" + ], + "params": [ + { + "name": "K", + "type": 86 + }, + { + "name": "V", + "type": 121 + } + ], + "def": { + "composite": { + "fields": [ + { + "type": 126 + } + ] + } + } + } + }, + { + "id": 121, + "type": { + "path": [ + "phactory", + "contracts", + "support", + "Contract" + ], + "def": { + "composite": { + "fields": [ + { + "name": "send_mq", + "type": 48, + "typeName": "SignedMessageChannel" + }, + { + "name": "cluster_id", + "type": 24, + "typeName": "phala_mq::ContractClusterId" + }, + { + "name": "address", + "type": 86, + "typeName": "AccountId" + }, + { + "name": "sidevm_info", + "type": 122, + "typeName": "Option" + }, + { + "name": "weight", + "type": 23, + "typeName": "u32" + }, + { + "name": "code_hash", + "type": 41, + "typeName": "Option" + }, + { + "name": "on_block_end", + "type": 124, + "typeName": "Option" + } + ] + } + } + } + }, + { + "id": 122, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 123 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 123 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 123, + "type": { + "path": [ + "phactory", + "contracts", + "support", + "SidevmInfo" + ], + "def": { + "composite": { + "fields": [ + { + "name": "code", + "type": 4, + "typeName": "Vec" + }, + { + "name": "code_hash", + "type": 24, + "typeName": "H256" + }, + { + "name": "start_time", + "type": 11, + "typeName": "String" + }, + { + "name": "auto_restart", + "type": 1, + "typeName": "bool" + } + ] + } + } + } + }, + { + "id": 124, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 125 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 125 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 125, + "type": { + "path": [ + "phactory", + "contracts", + "support", + "OnBlockEnd" + ], + "def": { + "composite": { + "fields": [ + { + "name": "selector", + "type": 23, + "typeName": "u32" + }, + { + "name": "gas_limit", + "type": 14, + "typeName": "u64" + } + ] + } + } + } + }, + { + "id": 126, + "type": { + "def": { + "sequence": { + "type": 127 + } + } + } + }, + { + "id": 127, + "type": { + "def": { + "tuple": [ + 86, + 121 + ] + } + } + }, + { + "id": 128, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 129 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 129 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 129, + "type": { + "path": [ + "phactory", + "contracts", + "pink", + "Cluster" + ], + "def": { + "composite": { + "fields": [ + { + "name": "id", + "type": 24, + "typeName": "ContractClusterId" + }, + { + "name": "config", + "type": 130, + "typeName": "ClusterConfig" + }, + { + "name": "storage", + "type": 133, + "typeName": "pink::storage::ClusterStorage" + } + ] + } + } + } + }, + { + "id": 130, + "type": { + "path": [ + "phactory", + "contracts", + "pink", + "ClusterConfig" + ], + "def": { + "composite": { + "fields": [ + { + "name": "log_handler", + "type": 131, + "typeName": "Option" + }, + { + "name": "runtime_version", + "type": 132, + "typeName": "(u32, u32)" + }, + { + "name": "secret_salt", + "type": 25, + "typeName": "[u8; 32]" + } + ] + } + } + } + }, + { + "id": 131, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 86 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 86 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 132, + "type": { + "def": { + "tuple": [ + 23, + 23 + ] + } + } + }, + { + "id": 133, + "type": { + "path": [ + "pink_runner", + "storage", + "ClusterStorage" + ], + "def": { + "composite": { + "fields": [ + { + "name": "root", + "type": 41, + "typeName": "Option" + } + ] + } + } + } + }, + { + "id": 134, + "type": { + "path": [ + "Option" + ], + "params": [ + { + "name": "T", + "type": 135 + } + ], + "def": { + "variant": { + "variants": [ + { + "name": "None", + "index": 0 + }, + { + "name": "Some", + "fields": [ + { + "type": 135 + } + ], + "index": 1 + } + ] + } + } + } + }, + { + "id": 135, + "type": { + "path": [ + "phactory_api", + "proto_generated", + "pruntime_rpc", + "NetworkConfig" + ], + "def": { + "composite": { + "fields": [ + { + "name": "all_proxy", + "type": 11, + "typeName": "::prost::alloc::string::String" + }, + { + "name": "i2p_proxy", + "type": 11, + "typeName": "::prost::alloc::string::String" + } + ] + } + } + } + } +] diff --git a/crates/phactory/src/system/gk.rs b/crates/phactory/src/system/gk.rs index 56f7f81d86..6da1537e7c 100644 --- a/crates/phactory/src/system/gk.rs +++ b/crates/phactory/src/system/gk.rs @@ -23,7 +23,10 @@ use phala_types::{ use serde::{Deserialize, Serialize}; use sp_core::{hashing, sr25519, Pair}; -use crate::{im_helpers::ordmap_for_each_mut, types::BlockInfo}; +use crate::{ + im_helpers::{ordmap_for_each_mut, OrdMap}, + types::BlockInfo, +}; use std::{ collections::{BTreeMap, VecDeque}, @@ -77,14 +80,16 @@ struct WorkerStat { last_gk_responsive_event_at_block: chain::BlockNumber, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct WorkerInfo { state: WorkerState, waiting_heartbeats: VecDeque, unresponsive: bool, + #[codec(skip)] tokenomic: TokenomicInfo, heartbeat_flag: bool, #[cfg(feature = "gk-stat")] + #[codec(skip)] stat: WorkerStat, } @@ -110,10 +115,11 @@ impl WorkerInfo { } } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub(crate) struct Gatekeeper { /// The current master key in use #[serde(with = "more::key_bytes")] + #[codec(skip)] master_key: sr25519::Pair, /// This will be switched once when the first master key is uploaded master_pubkey_on_chain: bool, @@ -626,15 +632,18 @@ impl EconomicEventListener for F { } } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct ComputingEconomics { egress: MsgChan, // TODO.kevin: syncing the egress state while migrating. computing_events: TypedReceiver, system_events: TypedReceiver, gatekeeper_events: TypedReceiver, - workers: im::OrdMap, + #[cfg_attr(not(test), codec(skip))] + workers: OrdMap, + #[codec(skip)] tokenomic_params: tokenomic::Params, #[serde(skip, default)] + #[codec(skip)] eco_cache: EconomicCalcCache, } diff --git a/crates/phactory/src/system/master_key.rs b/crates/phactory/src/system/master_key.rs index 061789a014..90406f48b0 100644 --- a/crates/phactory/src/system/master_key.rs +++ b/crates/phactory/src/system/master_key.rs @@ -18,7 +18,7 @@ struct PersistentMasterKey { signature: Signature, } -#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone)] +#[derive(Debug, Encode, Decode, PartialEq, Eq, Clone, ::scale_info::TypeInfo)] pub struct RotatedMasterKey { pub rotation_id: u64, pub block_height: chain::BlockNumber, diff --git a/crates/phactory/src/system/mod.rs b/crates/phactory/src/system/mod.rs index 732f7d5576..6fb8bf5b4d 100644 --- a/crates/phactory/src/system/mod.rs +++ b/crates/phactory/src/system/mod.rs @@ -125,7 +125,7 @@ impl From for TransactionError { } } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] struct BenchState { start_block: chain::BlockNumber, start_time: u64, @@ -133,13 +133,13 @@ struct BenchState { duration: u32, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] enum WorkingState { Computing, Paused, } -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] struct WorkingInfo { session_id: u32, state: WorkingState, @@ -148,8 +148,9 @@ struct WorkingInfo { } // Minimum worker state machine can be reused to replay in GK. -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Debug, Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] struct WorkerState { + #[codec(skip)] #[serde(with = "more::pubkey_bytes")] pubkey: WorkerPublicKey, hashed_id: U256, @@ -429,7 +430,7 @@ fn get_contract_key(cluster_key: &sr25519::Pair, contract_id: &ContractId) -> sr .expect("should not fail with valid info") } -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct System { platform: Platform, // Configuration @@ -445,7 +446,9 @@ pub struct System { cluster_key_distribution_events: TypedReceiver>, contract_operation_events: TypedReceiver>, // Worker + #[codec(skip)] pub(crate) identity_key: WorkerIdentityKey, + #[codec(skip)] #[serde(with = "ecdh_serde")] pub(crate) ecdh_key: EcdhKey, /// Be careful to use this field, as it is not updated in safe mode. @@ -455,6 +458,7 @@ pub struct System { pub(crate) contracts: ContractsKeeper, pub(crate) contract_cluster: Option, + #[codec(skip)] #[serde(skip)] #[serde(default = "create_sidevm_service_default")] sidevm_spawner: Spawner, diff --git a/crates/phala-mq/src/dispatcher.rs b/crates/phala-mq/src/dispatcher.rs index fe72cbdd3a..765076590e 100644 --- a/crates/phala-mq/src/dispatcher.rs +++ b/crates/phala-mq/src/dispatcher.rs @@ -1,6 +1,7 @@ use core::marker::PhantomData; use alloc::vec::Vec; +use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use crate::simple_mpsc::{channel, ReceiveError, Receiver as RawReceiver, Sender, Seq}; @@ -28,6 +29,21 @@ pub struct Receiver { topic: Vec, } +#[derive(::scale_info::TypeInfo)] +#[allow(dead_code)] +pub struct ReceiverTypeInfo { + inner: (), + topic: Vec, +} + +impl scale_info::TypeInfo for Receiver { + type Identity = ::Identity; + + fn type_info() -> scale_info::Type { + ::type_info() + } +} + impl core::ops::Deref for Receiver { type Target = RawReceiver<(u64, Message)>; @@ -129,9 +145,10 @@ impl From for TypedReceiveError { } } -#[derive(Serialize, Deserialize)] +#[derive(Serialize, Deserialize, ::scale_info::TypeInfo)] pub struct TypedReceiver { queue: Receiver, + #[codec(skip)] #[serde(skip)] _t: PhantomData, } diff --git a/crates/phala-mq/src/send_queue.rs b/crates/phala-mq/src/send_queue.rs index f6866bcbb0..e35805d791 100644 --- a/crates/phala-mq/src/send_queue.rs +++ b/crates/phala-mq/src/send_queue.rs @@ -144,8 +144,9 @@ mod msg_channel { use super::*; use crate::{types::Path, MessageSigner, SenderId}; - #[derive(Clone, Serialize, Deserialize)] + #[derive(Clone, Serialize, Deserialize, ::scale_info::TypeInfo)] pub struct MessageChannel { + #[codec(skip)] #[serde(skip)] #[serde(default = "crate::checkpoint_helper::global_send_mq")] queue: MessageSendQueue, diff --git a/crates/phala-mq/src/signer/mod.rs b/crates/phala-mq/src/signer/mod.rs index 3ebd80487c..a993b8548f 100644 --- a/crates/phala-mq/src/signer/mod.rs +++ b/crates/phala-mq/src/signer/mod.rs @@ -17,9 +17,10 @@ pub mod signers { use serde::{Deserialize, Serialize}; use sp_core::{crypto::Pair as PairTrait, sr25519}; - #[derive(Serialize, Deserialize, Clone)] + #[derive(Serialize, Deserialize, Clone, ::scale_info::TypeInfo)] pub struct Sr25519Signer { #[serde(with = "more::key_bytes")] + #[codec(skip)] key: sr25519::Pair, } diff --git a/crates/phala-types/src/contract.rs b/crates/phala-types/src/contract.rs index 37d8c9618b..86c0047d2b 100644 --- a/crates/phala-types/src/contract.rs +++ b/crates/phala-types/src/contract.rs @@ -61,7 +61,7 @@ pub mod messaging { use sp_core::crypto::AccountId32; bind_topic!(ClusterEvent, b"phala/cluster/event"); - #[derive(Encode, Decode, Debug)] + #[derive(Encode, Decode, Debug, ::scale_info::TypeInfo)] pub enum ClusterEvent { // TODO.shelven: enable add and remove workers DeployCluster { @@ -77,7 +77,7 @@ pub mod messaging { } bind_topic!(ContractOperation, b"phala/contract/op"); - #[derive(Encode, Decode, Debug)] + #[derive(Encode, Decode, Debug, ::scale_info::TypeInfo)] pub enum ContractOperation { InstantiateCode { contract_info: ContractInfo, diff --git a/crates/pink/runner/Cargo.toml b/crates/pink/runner/Cargo.toml index 9223a6d9e7..839d9f21a3 100644 --- a/crates/pink/runner/Cargo.toml +++ b/crates/pink/runner/Cargo.toml @@ -15,6 +15,7 @@ libc = "0.2" log = "0.4" tracing = "0.1" environmental = "1" +scale-info = { version = "2.9", default-features = false, features = ["derive"] } [dev-dependencies] pink = { path = "../runtime" } diff --git a/crates/pink/runner/src/storage.rs b/crates/pink/runner/src/storage.rs index 40c5382360..338b30cbcf 100644 --- a/crates/pink/runner/src/storage.rs +++ b/crates/pink/runner/src/storage.rs @@ -2,9 +2,10 @@ use im::OrdMap; use pink_capi::{types::Hash, v1::ocall::StorageChanges}; use serde::{Deserialize, Serialize}; -#[derive(Clone, Default, Serialize, Deserialize)] +#[derive(Clone, Default, Serialize, Deserialize, ::scale_info::TypeInfo)] pub struct ClusterStorage { root: Option, + #[codec(skip)] kv_store: OrdMap, (i32, Vec)>, } diff --git a/standalone/pruntime/Cargo.lock b/standalone/pruntime/Cargo.lock index 38cc19456b..5c1e91800f 100644 --- a/standalone/pruntime/Cargo.lock +++ b/standalone/pruntime/Cargo.lock @@ -5288,6 +5288,7 @@ dependencies = [ "reqwest", "reqwest-env-proxy", "ring 0.16.20", + "scale-info", "scopeguard", "serde", "serde_cbor", @@ -5790,6 +5791,7 @@ dependencies = [ "phala-crypto", "pink-capi", "pink-extension-runtime", + "scale-info", "serde", "sp-weights", "tracing", From 23e3676e807660f623c29ba5597cb4ce1eec1f77 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Thu, 14 Sep 2023 00:39:57 +0000 Subject: [PATCH 2/2] code style --- .../phactory/src/contracts/support/keeper.rs | 1 + crates/phactory/src/lib.rs | 30 +++++++------------ 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/crates/phactory/src/contracts/support/keeper.rs b/crates/phactory/src/contracts/support/keeper.rs index aef4cdd38e..e978709f95 100644 --- a/crates/phactory/src/contracts/support/keeper.rs +++ b/crates/phactory/src/contracts/support/keeper.rs @@ -46,6 +46,7 @@ impl ContractsKeeper { } pub fn drain(&mut self) -> impl Iterator { + #[allow(clippy::iter_kv_map)] std::mem::take(&mut self.contracts) .into_iter() .map(|(_, v)| v) diff --git a/crates/phactory/src/lib.rs b/crates/phactory/src/lib.rs index 9d730c4271..3df04d650c 100644 --- a/crates/phactory/src/lib.rs +++ b/crates/phactory/src/lib.rs @@ -561,7 +561,7 @@ impl Phactory let file = File::create(&checkpoint_file).context("Failed to create checkpoint file")?; self.take_checkpoint_to_writer(&key, file) .context("Take checkpoint to writer failed")?; - info!("Checkpoint saved to {}", checkpoint_file); + info!("Checkpoint saved to {checkpoint_file}"); self.last_checkpoint = Instant::now(); remove_outdated_checkpoints( &self.args.storage_path, @@ -618,43 +618,33 @@ impl Phactory Ok(file) => file, Err(err) if matches!(err.kind(), ErrorKind::NotFound) => { // This should never happen unless it was removed just after the glob. - anyhow::bail!("Checkpoint file {:?} is not found", ckpt_filename); + anyhow::bail!("Checkpoint file {ckpt_filename:?} is not found"); } Err(err) => { - error!( - "Failed to open checkpoint file {:?}: {:?}", - ckpt_filename, err - ); + error!("Failed to open checkpoint file {ckpt_filename:?}: {err:?}",); if args.remove_corrupted_checkpoint { - error!("Removing {:?}", ckpt_filename); + error!("Removing {ckpt_filename:?}"); std::fs::remove_file(ckpt_filename) .context("Failed to remove corrupted checkpoint file")?; } - anyhow::bail!( - "Failed to open checkpoint file {:?}: {:?}", - ckpt_filename, - err - ); + anyhow::bail!("Failed to open checkpoint file {ckpt_filename:?}: {err:?}"); } }; - info!("Loading checkpoint from file {:?}", ckpt_filename); + info!("Loading checkpoint from file {ckpt_filename:?}"); match Self::restore_from_checkpoint_reader(&runtime_data.sk, file, args) { Ok(state) => { - info!("Succeeded to load checkpoint file {:?}", ckpt_filename); + info!("Succeeded to load checkpoint file {ckpt_filename:?}"); Ok(Some(state)) } - Err(err /*Don't leak it into the log*/) => { - error!( - "Failed to load checkpoint file {:?}: {err:?}", - ckpt_filename - ); + Err(_err /*Don't leak it into the log*/) => { + error!("Failed to load checkpoint file {ckpt_filename:?}"); if args.remove_corrupted_checkpoint { error!("Removing {:?}", ckpt_filename); std::fs::remove_file(ckpt_filename) .context("Failed to remove corrupted checkpoint file")?; } - anyhow::bail!("Failed to load checkpoint file {:?}", ckpt_filename); + anyhow::bail!("Failed to load checkpoint file {ckpt_filename:?}"); } } }