From d167a768602cdbcd23de58457e317a4fe144a25e Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 11 Oct 2024 10:26:59 +0800 Subject: [PATCH 1/2] fix starcoin-state-service --- state/service/src/service.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/state/service/src/service.rs b/state/service/src/service.rs index 75e5c63be7..41a2b2462e 100644 --- a/state/service/src/service.rs +++ b/state/service/src/service.rs @@ -10,8 +10,7 @@ use starcoin_service_registry::{ }; use starcoin_state_api::message::{StateRequest, StateResponse}; use starcoin_state_api::{ - ChainStateReader, StateNodeStore, StateReaderExt, StateView, StateWithProof, - StateWithTableItemProof, + ChainStateReader, StateNodeStore, StateReaderExt, StateWithProof, StateWithTableItemProof, }; use starcoin_state_tree::AccountStateSetIterator; use starcoin_statedb::ChainStateDB; @@ -22,6 +21,7 @@ use starcoin_types::{ access_path::AccessPath, account_address::AccountAddress, account_state::AccountState, state_set::ChainStateSet, }; +use starcoin_vm_types::state_store::errors::StateviewError; use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::state_store::state_value::StateValue; use starcoin_vm_types::state_store::table::{TableHandle, TableInfo}; @@ -82,21 +82,19 @@ impl ServiceHandler for ChainStateService { _ctx: &mut ServiceContext, ) -> Result { let response = match msg { - StateRequest::Get(access_path) => StateResponse::State( - self.service - .get_state_value(&StateKey::AccessPath(access_path))?, - ), - StateRequest::GetWithProof(access_path) => { - StateResponse::StateWithProof(Box::new(self.service.get_with_proof(&access_path)?)) + StateRequest::Get(state_key) => { + StateResponse::State(self.service.get_state_value(&state_key)?) + } + StateRequest::GetWithProof(state_key) => { + StateResponse::StateWithProof(Box::new(self.service.get_with_proof(&state_key)?)) } StateRequest::GetAccountState(address) => { StateResponse::AccountState(self.service.get_account_state(&address)?) } StateRequest::StateRoot() => StateResponse::StateRoot(self.service.state_root()), - StateRequest::GetWithProofByRoot(access_path, state_root) => { + StateRequest::GetWithProofByRoot(state_key, state_root) => { StateResponse::StateWithProof(Box::new( - self.service - .get_with_proof_by_root(access_path, state_root)?, + self.service.get_with_proof_by_root(state_key, state_root)?, )) } StateRequest::GetAccountStateByRoot(account, state_root) => { @@ -255,12 +253,16 @@ impl ChainStateReader for Inner { impl TStateView for Inner { type Key = StateKey; - fn get_state_value(&self, state_key: &StateKey) -> Result> { + fn get_state_value(&self, state_key: &StateKey) -> Result, StateviewError> { self.state_db.get_state_value(state_key) } - fn is_genesis(&self) -> bool { - false + fn get_usage( + &self, + ) -> starcoin_vm_types::state_store::Result< + starcoin_vm_types::state_store::state_storage_usage::StateStorageUsage, + > { + todo!("not impl get_usage") } } From f0adbb99007b1fa87a33a2eca923c8eb7a65cfd6 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 11 Oct 2024 20:21:27 +0800 Subject: [PATCH 2/2] fix starcoin-state-service errors --- state/service/src/service.rs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/state/service/src/service.rs b/state/service/src/service.rs index 41a2b2462e..7803dc1c3a 100644 --- a/state/service/src/service.rs +++ b/state/service/src/service.rs @@ -22,6 +22,7 @@ use starcoin_types::{ state_set::ChainStateSet, }; use starcoin_vm_types::state_store::errors::StateviewError; +use starcoin_vm_types::state_store::state_key::inner::StateKeyInner; use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::state_store::state_value::StateValue; use starcoin_vm_types::state_store::table::{TableHandle, TableInfo}; @@ -83,18 +84,31 @@ impl ServiceHandler for ChainStateService { ) -> Result { let response = match msg { StateRequest::Get(state_key) => { - StateResponse::State(self.service.get_state_value(&state_key)?) + StateResponse::State(self.service.get_state_value_bytes(&state_key)?) } StateRequest::GetWithProof(state_key) => { - StateResponse::StateWithProof(Box::new(self.service.get_with_proof(&state_key)?)) + let access_path = match state_key.inner() { + StateKeyInner::AccessPath(access_path) => access_path, + _ => { + return Err(format_err!("Invalid StateKey.")); + } + }; + StateResponse::StateWithProof(Box::new(self.service.get_with_proof(access_path)?)) } StateRequest::GetAccountState(address) => { StateResponse::AccountState(self.service.get_account_state(&address)?) } StateRequest::StateRoot() => StateResponse::StateRoot(self.service.state_root()), StateRequest::GetWithProofByRoot(state_key, state_root) => { + let access_path = match state_key.inner() { + StateKeyInner::AccessPath(access_path) => access_path, + _ => { + return Err(format_err!("Invalid StateKey.")); + } + }; StateResponse::StateWithProof(Box::new( - self.service.get_with_proof_by_root(state_key, state_root)?, + self.service + .get_with_proof_by_root(access_path, state_root)?, )) } StateRequest::GetAccountStateByRoot(account, state_root) => { @@ -171,11 +185,11 @@ impl Inner { pub(crate) fn get_with_proof_by_root( &self, - access_path: AccessPath, + access_path: &AccessPath, state_root: HashValue, ) -> Result { let reader = self.state_db.fork_at(state_root); - reader.get_with_proof(&access_path) + reader.get_with_proof(access_path) } pub(crate) fn get_with_table_item_proof_by_root(