From 577b30460e82631f56108b86c2374541a5c94d86 Mon Sep 17 00:00:00 2001 From: Yan Mingzhi Date: Thu, 8 Feb 2024 08:22:55 +0000 Subject: [PATCH] feat: add is first startup init mode request --- codecs/runtime-codec/src/vmh/env.rs | 1 + system-actors/src/env/mod.rs | 9 +++++++++ system-actors/src/tokenstate_service/mod.rs | 8 ++++++++ utils/wasm-actor-utils/src/enclave/actors/libp2p.rs | 10 ++++++++-- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/codecs/runtime-codec/src/vmh/env.rs b/codecs/runtime-codec/src/vmh/env.rs index e9f5b45..9b2ab2f 100644 --- a/codecs/runtime-codec/src/vmh/env.rs +++ b/codecs/runtime-codec/src/vmh/env.rs @@ -21,6 +21,7 @@ pub struct EnvSettings { pub replica_test_mode: bool, pub apply_validator: bool, pub test_mode: bool, + pub first_startup_init_mode: bool, pub lastest_topup_height: u64, pub startup_proof: Option, pub settings: HashMap, diff --git a/system-actors/src/env/mod.rs b/system-actors/src/env/mod.rs index 2f76231..f801eae 100644 --- a/system-actors/src/env/mod.rs +++ b/system-actors/src/env/mod.rs @@ -264,6 +264,15 @@ pub struct IsMainNetRequest; #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] pub struct IsMainNetResponse(pub bool); +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] +#[price(10000)] +pub struct IsFirstStartupInitModeRequest; + +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct IsFirstStartupInitModeResponse(pub bool); + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId, Priced)] #[price(10000)] diff --git a/system-actors/src/tokenstate_service/mod.rs b/system-actors/src/tokenstate_service/mod.rs index 7089b50..9400195 100644 --- a/system-actors/src/tokenstate_service/mod.rs +++ b/system-actors/src/tokenstate_service/mod.rs @@ -14,6 +14,14 @@ pub struct IsOutdatedRequest(pub ActorId); #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] pub struct IsOutdatedResponse(pub bool); +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct HasStateInitRequest; + +#[doc(hidden)] +#[derive(Debug, Clone, Serialize, Deserialize, TypeId)] +pub struct HasStateInitResponse(pub bool); + #[doc(hidden)] #[derive(Debug, Clone, Serialize, Deserialize, TypeId)] #[response(Vec)] diff --git a/utils/wasm-actor-utils/src/enclave/actors/libp2p.rs b/utils/wasm-actor-utils/src/enclave/actors/libp2p.rs index 6b3fd8d..a091d53 100644 --- a/utils/wasm-actor-utils/src/enclave/actors/libp2p.rs +++ b/utils/wasm-actor-utils/src/enclave/actors/libp2p.rs @@ -45,11 +45,17 @@ pub async fn my_conn_id() -> Result { } #[doc(hidden)] -pub async fn is_connection_healthy() -> Result { +pub async fn has_libp2p_cooldown() -> Result { let cooldown = ActorId::Static(tea_system_actors::libp2p::NAME) .call(HasCooldownRequest) .await?; - if !cooldown.0 { + Ok(cooldown.0) +} + +#[doc(hidden)] +pub async fn is_connection_healthy() -> Result { + let cooldown = has_libp2p_cooldown().await?; + if !cooldown { return Ok(false); } match connected_peers().await {