diff --git a/chain/api/src/message.rs b/chain/api/src/message.rs index 4f8dd1aedd..0867a38e8f 100644 --- a/chain/api/src/message.rs +++ b/chain/api/src/message.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2 -use crate::range_locate::RangeInPruningPoint; +use crate::range_locate::RangeInLocation; use crate::{ChainType, TransactionInfoWithProof}; use anyhow::Result; use starcoin_crypto::HashValue; @@ -109,5 +109,5 @@ pub enum ChainResponse { CheckChainType(ChainType), GhostdagDataOption(Box>), IsAncestorOfCommand { reachability_view: ReachabilityView }, - GetRangeInLocation { range: RangeInPruningPoint }, + GetRangeInLocation { range: RangeInLocation }, } diff --git a/chain/api/src/range_locate.rs b/chain/api/src/range_locate.rs index 67c2687df3..30966edaa5 100644 --- a/chain/api/src/range_locate.rs +++ b/chain/api/src/range_locate.rs @@ -25,7 +25,7 @@ pub enum FindCommonHeaderError { } #[derive(Debug, PartialEq, Eq)] -pub enum RangeInPruningPoint { +pub enum RangeInLocation { NotInSelectedChain, InSelectedChain(HashValue, Vec), } @@ -88,19 +88,19 @@ pub fn get_range_in_location( storage: Arc, start_id: HashValue, end_id: Option, -) -> anyhow::Result { +) -> anyhow::Result { let start_block_header = match storage.get_block_header_by_hash(start_id)? { Some(header) => header, - None => return anyhow::Result::Ok(RangeInPruningPoint::NotInSelectedChain), + None => return anyhow::Result::Ok(RangeInLocation::NotInSelectedChain), }; match chain.get_block_info_by_number(start_block_header.number())? { Some(block_info) => { if *block_info.block_id() != start_id { - return Ok(RangeInPruningPoint::NotInSelectedChain); + return Ok(RangeInLocation::NotInSelectedChain); } } - None => return Ok(RangeInPruningPoint::NotInSelectedChain), + None => return Ok(RangeInLocation::NotInSelectedChain), } let mut result = vec![]; @@ -131,5 +131,5 @@ pub fn get_range_in_location( result.push(block_id); } - Ok(RangeInPruningPoint::InSelectedChain(start_id, result)) + Ok(RangeInLocation::InSelectedChain(start_id, result)) } diff --git a/chain/api/src/service.rs b/chain/api/src/service.rs index f2dfb2cae5..66a0b31969 100644 --- a/chain/api/src/service.rs +++ b/chain/api/src/service.rs @@ -1,7 +1,7 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2 use crate::message::{ChainRequest, ChainResponse}; -use crate::range_locate::RangeInPruningPoint; +use crate::range_locate::RangeInLocation; use crate::{ChainType, TransactionInfoWithProof}; use anyhow::{bail, Result}; use starcoin_crypto::HashValue; @@ -83,7 +83,7 @@ pub trait ReadableChainService { &self, start_id: HashValue, end_id: Option, - ) -> Result; + ) -> Result; } /// Writeable block chain service trait @@ -485,12 +485,12 @@ where .await??; if let ChainResponse::GetRangeInLocation { range } = response { match range { - RangeInPruningPoint::NotInSelectedChain => Ok(GetRangeInLocationResponse { - range: starcoin_network_rpc_api::RangeInPruningPoint::NotInSelectedChain, + RangeInLocation::NotInSelectedChain => Ok(GetRangeInLocationResponse { + range: starcoin_network_rpc_api::RangeInLocation::NotInSelectedChain, }), - RangeInPruningPoint::InSelectedChain(hash_value, hash_values) => { + RangeInLocation::InSelectedChain(hash_value, hash_values) => { Ok(GetRangeInLocationResponse { - range: starcoin_network_rpc_api::RangeInPruningPoint::InSelectedChain( + range: starcoin_network_rpc_api::RangeInLocation::InSelectedChain( hash_value, hash_values, ), diff --git a/chain/service/src/chain_service.rs b/chain/service/src/chain_service.rs index 3143cb84fc..86eab9f957 100644 --- a/chain/service/src/chain_service.rs +++ b/chain/service/src/chain_service.rs @@ -4,7 +4,7 @@ use anyhow::{format_err, Error, Result}; use starcoin_chain::BlockChain; use starcoin_chain_api::message::{ChainRequest, ChainResponse}; -use starcoin_chain_api::range_locate::{self, RangeInPruningPoint}; +use starcoin_chain_api::range_locate::{self, RangeInLocation}; use starcoin_chain_api::{ ChainReader, ChainType, ChainWriter, ReadableChainService, TransactionInfoWithProof, }; @@ -492,7 +492,7 @@ impl ReadableChainService for ChainReaderServiceInner { &self, start_id: HashValue, end_id: Option, - ) -> Result { + ) -> Result { range_locate::get_range_in_location(self.get_main(), self.storage.clone(), start_id, end_id) } } diff --git a/chain/tests/test_range_locate.rs b/chain/tests/test_range_locate.rs index 6764e2c490..9956f54cc0 100644 --- a/chain/tests/test_range_locate.rs +++ b/chain/tests/test_range_locate.rs @@ -2,7 +2,7 @@ use anyhow::{bail, format_err}; use starcoin_chain::ChainReader; use starcoin_chain_api::{ range_locate::{ - find_common_header_in_range, get_range_in_location, FindCommonHeader, RangeInPruningPoint, + find_common_header_in_range, get_range_in_location, FindCommonHeader, RangeInLocation, }, ExecutedBlock, }; @@ -84,8 +84,8 @@ fn test_range_locate() -> anyhow::Result<()> { remote_start_id, remote_end_id, )? { - RangeInPruningPoint::NotInSelectedChain => bail!("all are no in selected chain!"), - RangeInPruningPoint::InSelectedChain(_hash_value, hash_values) => hash_values, + RangeInLocation::NotInSelectedChain => bail!("all are no in selected chain!"), + RangeInLocation::InSelectedChain(_hash_value, hash_values) => hash_values, }; result.iter().for_each(|block_id| { @@ -163,7 +163,7 @@ fn test_not_in_range_locate() -> anyhow::Result<()> { assert_eq!( result, - RangeInPruningPoint::NotInSelectedChain, + RangeInLocation::NotInSelectedChain, "expect not in selected chain" ); @@ -185,8 +185,8 @@ fn test_same_range_request() -> anyhow::Result<()> { mock_chain_remote.head().current_header().id(), Some(mock_chain_remote.head().current_header().id()), )? { - RangeInPruningPoint::NotInSelectedChain => bail!("expect in selected chain"), - RangeInPruningPoint::InSelectedChain(hash_value, hash_values) => { + RangeInLocation::NotInSelectedChain => bail!("expect in selected chain"), + RangeInLocation::InSelectedChain(hash_value, hash_values) => { assert_eq!(hash_value, mock_chain_remote.head().current_header().id()); assert_eq!(hash_values.len(), 0); } @@ -203,8 +203,8 @@ fn test_same_range_request() -> anyhow::Result<()> { *block_header.block_id(), Some(*block_header.block_id()), )? { - RangeInPruningPoint::NotInSelectedChain => bail!("expect in selected chain"), - RangeInPruningPoint::InSelectedChain(hash_value, hash_values) => { + RangeInLocation::NotInSelectedChain => bail!("expect in selected chain"), + RangeInLocation::InSelectedChain(hash_value, hash_values) => { assert_eq!(hash_value, block_header.block_id().clone()); assert_eq!(hash_values.len(), 0); } diff --git a/network-rpc/api/src/lib.rs b/network-rpc/api/src/lib.rs index 1d2e34166c..e7c07cc891 100644 --- a/network-rpc/api/src/lib.rs +++ b/network-rpc/api/src/lib.rs @@ -323,12 +323,12 @@ pub struct GetRangeInLocationRequest { } #[derive(Debug, Serialize, Deserialize, Clone)] -pub enum RangeInPruningPoint { +pub enum RangeInLocation { NotInSelectedChain, InSelectedChain(HashValue, Vec), } #[derive(Debug, Serialize, Deserialize, Clone)] pub struct GetRangeInLocationResponse { - pub range: RangeInPruningPoint, + pub range: RangeInLocation, } diff --git a/sync/src/tasks/find_common_ancestor_task.rs b/sync/src/tasks/find_common_ancestor_task.rs index 8e66eefe8b..6a396f4172 100644 --- a/sync/src/tasks/find_common_ancestor_task.rs +++ b/sync/src/tasks/find_common_ancestor_task.rs @@ -8,7 +8,7 @@ use starcoin_chain_api::range_locate::{find_common_header_in_range, FindCommonHe use starcoin_crypto::HashValue; use starcoin_dag::blockdag::BlockDAG; use starcoin_logger::prelude::error; -use starcoin_network_rpc_api::RangeInPruningPoint; +use starcoin_network_rpc_api::RangeInLocation; use starcoin_storage::Store; use starcoin_types::block::BlockIdAndNumber; use std::sync::Arc; @@ -60,7 +60,7 @@ impl TaskState for FindRangeLocateTask { .fetch_range_locate(None, start_id, end_id) .await? { - RangeInPruningPoint::NotInSelectedChain => { + RangeInLocation::NotInSelectedChain => { let block_header = self .storage .get_block_header_by_hash(start_id)? @@ -75,7 +75,7 @@ impl TaskState for FindRangeLocateTask { })?; } } - RangeInPruningPoint::InSelectedChain(hash_value, hash_values) => { + RangeInLocation::InSelectedChain(hash_value, hash_values) => { if hash_values.is_empty() { let header = self .storage diff --git a/sync/src/tasks/mock.rs b/sync/src/tasks/mock.rs index 3b2eaa47e0..7f1fa46b15 100644 --- a/sync/src/tasks/mock.rs +++ b/sync/src/tasks/mock.rs @@ -437,7 +437,7 @@ impl BlockIdRangeFetcher for SyncNodeMocker { _peer: Option, _start_id: HashValue, _end_id: Option, - ) -> BoxFuture> { + ) -> BoxFuture> { unimplemented!() } } diff --git a/sync/src/tasks/mod.rs b/sync/src/tasks/mod.rs index a411e5ee9d..5ea85fcbbf 100644 --- a/sync/src/tasks/mod.rs +++ b/sync/src/tasks/mod.rs @@ -20,7 +20,7 @@ use starcoin_chain_api::ChainType; use starcoin_crypto::HashValue; use starcoin_dag::blockdag::BlockDAG; use starcoin_logger::prelude::*; -use starcoin_network_rpc_api::{RangeInPruningPoint, MAX_BLOCK_IDS_REQUEST_SIZE}; +use starcoin_network_rpc_api::{RangeInLocation, MAX_BLOCK_IDS_REQUEST_SIZE}; use starcoin_service_registry::{ActorService, EventHandler, ServiceRef}; use starcoin_storage::Store; use starcoin_sync_api::SyncTarget; @@ -242,7 +242,7 @@ pub trait BlockIdRangeFetcher: Send + Sync { peer: Option, start_id: HashValue, end_id: Option, - ) -> BoxFuture>; + ) -> BoxFuture>; } impl PeerOperator for VerifiedRpcClient { @@ -278,7 +278,7 @@ impl BlockIdRangeFetcher for VerifiedRpcClient { peer: Option, start_id: HashValue, end_id: Option, - ) -> BoxFuture> { + ) -> BoxFuture> { self.fetch_range_locate(peer, start_id, end_id) .map_err(fetcher_err_map) .boxed() @@ -318,7 +318,7 @@ where peer: Option, start_id: HashValue, end_id: Option, - ) -> BoxFuture> { + ) -> BoxFuture> { BlockIdRangeFetcher::fetch_range_locate(self.as_ref(), peer, start_id, end_id) } } diff --git a/sync/src/verified_rpc_client.rs b/sync/src/verified_rpc_client.rs index c7f36d41a6..dfc8bfc53d 100644 --- a/sync/src/verified_rpc_client.rs +++ b/sync/src/verified_rpc_client.rs @@ -15,7 +15,7 @@ use starcoin_network_rpc_api::{ gen_client::NetworkRpcClient, BlockBody, GetAccumulatorNodeByNodeHash, GetBlockHeadersByNumber, GetBlockIds, GetTxnsWithHash, RawRpcClient, }; -use starcoin_network_rpc_api::{GetRangeInLocationRequest, RangeInPruningPoint}; +use starcoin_network_rpc_api::{GetRangeInLocationRequest, RangeInLocation}; use starcoin_state_tree::StateNode; use starcoin_types::block::Block; use starcoin_types::transaction::{SignedUserTransaction, Transaction}; @@ -900,7 +900,7 @@ impl VerifiedRpcClient { peer: Option, start_id: HashValue, end_id: Option, - ) -> Result { + ) -> Result { let peer_id = if let Some(peer) = peer { peer } else {