From 28850f6bdde9468963548d4f66e86f185e31aabf Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 18 Apr 2024 06:49:29 +0200 Subject: [PATCH 01/26] expose vspc_from_block batching possibilities to rpc. --- components/consensusmanager/src/session.rs | 4 ++-- consensus/core/src/api/mod.rs | 9 ++++++- consensus/core/src/errors/consensus.rs | 3 +++ consensus/src/consensus/mod.rs | 24 +++++++++++++++---- .../pipeline/virtual_processor/processor.rs | 2 +- consensus/src/processes/sync/mod.rs | 2 +- consensus/src/processes/traversal_manager.rs | 22 +++++++++++++---- rpc/service/src/service.rs | 7 +++--- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index e241fd327..7ee5c023f 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -252,8 +252,8 @@ impl ConsensusSessionOwned { self.clone().spawn_blocking(|c| c.is_nearly_synced()).await } - pub async fn async_get_virtual_chain_from_block(&self, hash: Hash) -> ConsensusResult { - self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(hash)).await + pub async fn async_get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { + self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, high, max_blocks)).await } pub async fn async_get_virtual_utxos( diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index 23e7abb53..cb7888433 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -147,7 +147,14 @@ pub trait ConsensusApi: Send + Sync { unimplemented!() } - fn get_virtual_chain_from_block(&self, hash: Hash) -> ConsensusResult { + /// Gets the virtual chain paths from `low` to the `high` hash, or until max_blocks is reached + /// + /// Note: + /// 1) Specifying the `high` hash as `None` will calculate the chain path up to the current sink. + /// 2) Specifying `max_blocks` as `None` will impose no limit. + /// 3) `max_blocks` limit will populate removed & added chain path, up to max_blocks. + /// 3.1) use usize::MAX to get all blocks in the chain path, with optimized performance, (in cases where batching is not required) + fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { unimplemented!() } diff --git a/consensus/core/src/errors/consensus.rs b/consensus/core/src/errors/consensus.rs index 51d8b3f4d..57764282a 100644 --- a/consensus/core/src/errors/consensus.rs +++ b/consensus/core/src/errors/consensus.rs @@ -17,6 +17,9 @@ pub enum ConsensusError { #[error("some data is missing for block {0}")] MissingData(Hash), + #[error("expected block: {0} to be an ancestor of block: {1}")] + ExpectedAncestor(Hash, Hash), + #[error("got unexpected pruning point")] UnexpectedPruningPoint, diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 80babbef0..642c6e758 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -534,14 +534,28 @@ impl ConsensusApi for Consensus { self.config.is_nearly_synced(compact.timestamp, compact.daa_score) } - fn get_virtual_chain_from_block(&self, hash: Hash) -> ConsensusResult { - // Calculate chain changes between the given hash and the - // sink. Note that we explicitly don't + fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { + // Calculate chain changes between the given `low` and `high` hash (or up to `max_blocks`). + // Note: + // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. + // 2) high will default to the sink, if `None``. + // 3) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); - self.validate_block_exists(hash)?; - Ok(self.services.dag_traversal_manager.calculate_chain_path(hash, self.get_sink())) + + self.validate_block_exists(low)?; + let high = if let Some(high) = high { + self.validate_block_exists(high)?; + if !self.services.reachability_service.is_chain_ancestor_of(low, high) { + return Err(ConsensusError::ExpectedAncestor(low, high)); + }; + self.services.sync_manager.find_highest_common_chain_block(low, high) + } else { + self.get_sink() + }; + + Ok(self.services.dag_traversal_manager.calculate_chain_path(low, high, max_blocks)) } /// Returns a Vec of header samples since genesis diff --git a/consensus/src/pipeline/virtual_processor/processor.rs b/consensus/src/pipeline/virtual_processor/processor.rs index ded062251..c59395a0b 100644 --- a/consensus/src/pipeline/virtual_processor/processor.rs +++ b/consensus/src/pipeline/virtual_processor/processor.rs @@ -289,7 +289,7 @@ impl VirtualStateProcessor { assert_eq!(virtual_ghostdag_data.selected_parent, new_sink); let sink_multiset = self.utxo_multisets_store.get(new_sink).unwrap(); - let chain_path = self.dag_traversal_manager.calculate_chain_path(prev_sink, new_sink); + let chain_path = self.dag_traversal_manager.calculate_chain_path(prev_sink, new_sink, usize::MAX); let new_virtual_state = self .calculate_and_commit_virtual_state( virtual_read, diff --git a/consensus/src/processes/sync/mod.rs b/consensus/src/processes/sync/mod.rs index 7b8480111..f7a769b4f 100644 --- a/consensus/src/processes/sync/mod.rs +++ b/consensus/src/processes/sync/mod.rs @@ -111,7 +111,7 @@ impl< (blocks, highest_reached) } - fn find_highest_common_chain_block(&self, low: Hash, high: Hash) -> Hash { + pub fn find_highest_common_chain_block(&self, low: Hash, high: Hash) -> Hash { self.reachability_service .default_backward_chain_iterator(low) .find(|candidate| self.reachability_service.is_chain_ancestor_of(*candidate, high)) diff --git a/consensus/src/processes/traversal_manager.rs b/consensus/src/processes/traversal_manager.rs index 3ae0aef5d..dc3373138 100644 --- a/consensus/src/processes/traversal_manager.rs +++ b/consensus/src/processes/traversal_manager.rs @@ -31,10 +31,10 @@ impl ChainPath { + pub fn calculate_chain_path(&self, from: Hash, to: Hash, max_traversal_allowed: usize) -> ChainPath { let mut removed = Vec::new(); let mut common_ancestor = from; - for current in self.reachability_service.default_backward_chain_iterator(from) { + for current in self.reachability_service.default_backward_chain_iterator(from).take(max_traversal_allowed) { if !self.reachability_service.is_chain_ancestor_of(current, to) { removed.push(current); } else { @@ -42,9 +42,21 @@ impl RpcResult { let session = self.consensus_manager.consensus().session().await; - let virtual_chain = session.async_get_virtual_chain_from_block(request.start_hash).await?; + // TODO: discuss and implement batching either by high hash, or max_traversal limit, in `get_virtual_chain_from_block` + let virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, None, usize::MAX).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { - self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain).await? + self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch).await? } else { vec![] }; - Ok(GetVirtualChainFromBlockResponse::new(virtual_chain.removed, virtual_chain.added, accepted_transaction_ids)) + Ok(GetVirtualChainFromBlockResponse::new(virtual_chain_batch.removed, virtual_chain_batch.added, accepted_transaction_ids)) } async fn get_block_count_call(&self, _: GetBlockCountRequest) -> RpcResult { From f01d84de0c3c3429b2e894d2f8722cb1c405fcb6 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 18 Apr 2024 06:56:59 +0200 Subject: [PATCH 02/26] fmt --- components/consensusmanager/src/session.rs | 7 ++++++- consensus/src/consensus/mod.rs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index 7ee5c023f..8569579f5 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -252,7 +252,12 @@ impl ConsensusSessionOwned { self.clone().spawn_blocking(|c| c.is_nearly_synced()).await } - pub async fn async_get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { + pub async fn async_get_virtual_chain_from_block( + &self, + low: Hash, + high: Option, + max_blocks: usize, + ) -> ConsensusResult { self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, high, max_blocks)).await } diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 642c6e758..9650cd04d 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -535,13 +535,13 @@ impl ConsensusApi for Consensus { } fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { - // Calculate chain changes between the given `low` and `high` hash (or up to `max_blocks`). - // Note: + // Calculate chain changes between the given `low` and `high` hash (or up to `max_blocks`). + // Note: // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. // 2) high will default to the sink, if `None``. - // 3) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. + // 3) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); self.validate_block_exists(low)?; From 20934b9a2b0918013012f3c006a066b1c8ad9a21 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 18 Apr 2024 20:57:15 +0200 Subject: [PATCH 03/26] limit by merged blocks, set source as def. start. --- components/consensusmanager/src/session.rs | 8 ++++++-- consensus/core/src/api/mod.rs | 2 +- consensus/src/consensus/mod.rs | 20 +++++++++++++++++-- rpc/core/src/api/rpc.rs | 2 +- rpc/core/src/model/message.rs | 4 ++-- rpc/grpc/core/src/convert/message.rs | 4 ++-- rpc/service/src/converter/consensus.rs | 3 ++- rpc/service/src/service.rs | 17 +++++++++++++--- .../src/daemon_integration_tests.rs | 4 ++-- testing/integration/src/rpc_tests.rs | 4 ++-- 10 files changed, 50 insertions(+), 18 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index 8569579f5..822785e62 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -370,8 +370,12 @@ impl ConsensusSessionOwned { /// Returns acceptance data for a set of blocks belonging to the selected parent chain. /// /// See `self::get_virtual_chain` - pub async fn async_get_blocks_acceptance_data(&self, hashes: Vec) -> ConsensusResult>> { - self.clone().spawn_blocking(move |c| c.get_blocks_acceptance_data(&hashes)).await + pub async fn async_get_blocks_acceptance_data( + &self, + hashes: Vec, + merged_blocks_limit: usize, + ) -> ConsensusResult>> { + self.clone().spawn_blocking(move |c| c.get_blocks_acceptance_data(&hashes, merged_blocks_limit)).await } pub async fn async_is_chain_block(&self, hash: Hash) -> ConsensusResult { diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index cb7888433..32dfc3d48 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -290,7 +290,7 @@ pub trait ConsensusApi: Send + Sync { /// Returns acceptance data for a set of blocks belonging to the selected parent chain. /// /// See `self::get_virtual_chain` - fn get_blocks_acceptance_data(&self, hashes: &[Hash]) -> ConsensusResult>> { + fn get_blocks_acceptance_data(&self, hashes: &[Hash], merged_blocks_limit: usize) -> ConsensusResult>> { unimplemented!() } diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 9650cd04d..344c4ff6c 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -850,11 +850,27 @@ impl ConsensusApi for Consensus { self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash)) } - fn get_blocks_acceptance_data(&self, hashes: &[Hash]) -> ConsensusResult>> { + fn get_blocks_acceptance_data(&self, hashes: &[Hash], merged_blocks_limit: usize) -> ConsensusResult>> { + if merged_blocks_limit == usize::MAX { + return hashes + .iter() + .copied() + .map(|hash| self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash))) + .collect::>>(); + } + let mut num_of_merged_blocks = 0usize; hashes .iter() .copied() - .map(|hash| self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash))) + .map_while(|hash| { + let entry = self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash)); + num_of_merged_blocks += entry.as_ref().map_or(0, |entry| entry.len()); + if num_of_merged_blocks > merged_blocks_limit { + None + } else { + Some(entry) + } + }) .collect::>>() } diff --git a/rpc/core/src/api/rpc.rs b/rpc/core/src/api/rpc.rs index 36f8ef308..4030c5977 100644 --- a/rpc/core/src/api/rpc.rs +++ b/rpc/core/src/api/rpc.rs @@ -147,7 +147,7 @@ pub trait RpcApi: Sync + Send + AnySync { /// Requests the virtual selected parent chain from some `start_hash` to this node's current virtual. async fn get_virtual_chain_from_block( &self, - start_hash: RpcHash, + start_hash: Option, include_accepted_transaction_ids: bool, ) -> RpcResult { self.get_virtual_chain_from_block_call(GetVirtualChainFromBlockRequest::new(start_hash, include_accepted_transaction_ids)) diff --git a/rpc/core/src/model/message.rs b/rpc/core/src/model/message.rs index 8538558e5..2922d610b 100644 --- a/rpc/core/src/model/message.rs +++ b/rpc/core/src/model/message.rs @@ -324,12 +324,12 @@ impl GetSubnetworkResponse { #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] #[serde(rename_all = "camelCase")] pub struct GetVirtualChainFromBlockRequest { - pub start_hash: RpcHash, + pub start_hash: Option, pub include_accepted_transaction_ids: bool, } impl GetVirtualChainFromBlockRequest { - pub fn new(start_hash: RpcHash, include_accepted_transaction_ids: bool) -> Self { + pub fn new(start_hash: Option, include_accepted_transaction_ids: bool) -> Self { Self { start_hash, include_accepted_transaction_ids } } } diff --git a/rpc/grpc/core/src/convert/message.rs b/rpc/grpc/core/src/convert/message.rs index 9babf29c8..c9bf75712 100644 --- a/rpc/grpc/core/src/convert/message.rs +++ b/rpc/grpc/core/src/convert/message.rs @@ -258,7 +258,7 @@ from!(item: RpcResult<&kaspa_rpc_core::GetSubnetworkResponse>, protowire::GetSub // ~~~ from!(item: &kaspa_rpc_core::GetVirtualChainFromBlockRequest, protowire::GetVirtualChainFromBlockRequestMessage, { - Self { start_hash: item.start_hash.to_string(), include_accepted_transaction_ids: item.include_accepted_transaction_ids } + Self { start_hash: item.start_hash.map_or(Default::default(), |x| x.to_string()), include_accepted_transaction_ids: item.include_accepted_transaction_ids } }); from!(item: RpcResult<&kaspa_rpc_core::GetVirtualChainFromBlockResponse>, protowire::GetVirtualChainFromBlockResponseMessage, { Self { @@ -655,7 +655,7 @@ try_from!(item: &protowire::GetSubnetworkResponseMessage, RpcResult, { Self { diff --git a/rpc/service/src/converter/consensus.rs b/rpc/service/src/converter/consensus.rs index 9f3f5b661..d02a41777 100644 --- a/rpc/service/src/converter/consensus.rs +++ b/rpc/service/src/converter/consensus.rs @@ -162,8 +162,9 @@ impl ConsensusConverter { &self, consensus: &ConsensusProxy, chain_path: &ChainPath, + merged_blocks_limit: usize, // limit by number of transactions ) -> RpcResult> { - let acceptance_data = consensus.async_get_blocks_acceptance_data(chain_path.added.clone()).await.unwrap(); + let acceptance_data = consensus.async_get_blocks_acceptance_data(chain_path.added.clone(), merged_blocks_limit).await.unwrap(); Ok(chain_path .added .iter() diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index cc1ceb423..b62a3d718 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -528,10 +528,21 @@ NOTE: This error usually indicates an RPC conversion error between the node and request: GetVirtualChainFromBlockRequest, ) -> RpcResult { let session = self.consensus_manager.consensus().session().await; - // TODO: discuss and implement batching either by high hash, or max_traversal limit, in `get_virtual_chain_from_block` - let virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, None, usize::MAX).await?; + + // If start_hash is empty - use ORIGIN instead. + let start_hash = match request.start_hash { + Some(start_hash) => { + // Make sure start_hash points to an existing and valid block + session.async_get_ghostdag_data(start_hash).await?; + start_hash + } + None => session.async_get_source().await, + }; + + let limit = (self.config.mergeset_size_limit * 10) as usize; + let virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { - self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch).await? + self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await? } else { vec![] }; diff --git a/testing/integration/src/daemon_integration_tests.rs b/testing/integration/src/daemon_integration_tests.rs index 9c0e11718..09cf1f500 100644 --- a/testing/integration/src/daemon_integration_tests.rs +++ b/testing/integration/src/daemon_integration_tests.rs @@ -104,7 +104,7 @@ async fn daemon_mining_test() { assert_eq!(dag_info.sink, last_block_hash.unwrap()); // Check that acceptance data contains the expected coinbase tx ids - let vc = rpc_client2.get_virtual_chain_from_block(kaspa_consensus::params::SIMNET_GENESIS.hash, true).await.unwrap(); + let vc = rpc_client2.get_virtual_chain_from_block(None, true).await.unwrap(); assert_eq!(vc.removed_chain_block_hashes.len(), 0); assert_eq!(vc.added_chain_block_hashes.len(), 10); assert_eq!(vc.accepted_transaction_ids.len(), 10); @@ -222,7 +222,7 @@ async fn daemon_utxos_propagation_test() { assert_eq!(dag_info.sink, last_block_hash.unwrap()); // Check that acceptance data contains the expected coinbase tx ids - let vc = rpc_client2.get_virtual_chain_from_block(kaspa_consensus::params::SIMNET_GENESIS.hash, true).await.unwrap(); + let vc = rpc_client2.get_virtual_chain_from_block(Some(kaspa_consensus::params::SIMNET_GENESIS.hash), true).await.unwrap(); assert_eq!(vc.removed_chain_block_hashes.len(), 0); assert_eq!(vc.added_chain_block_hashes.len() as u64, initial_blocks); assert_eq!(vc.accepted_transaction_ids.len() as u64, initial_blocks); diff --git a/testing/integration/src/rpc_tests.rs b/testing/integration/src/rpc_tests.rs index 4fbb4155b..9c260df98 100644 --- a/testing/integration/src/rpc_tests.rs +++ b/testing/integration/src/rpc_tests.rs @@ -90,7 +90,7 @@ async fn sanity_test() { // and the virtual chain is the genesis only let response = rpc_client .get_virtual_chain_from_block_call(GetVirtualChainFromBlockRequest { - start_hash: SIMNET_GENESIS.hash, + start_hash: Some(SIMNET_GENESIS.hash), include_accepted_transaction_ids: false, }) .await @@ -140,7 +140,7 @@ async fn sanity_test() { // and the virtual chain from genesis contains the added block let response = rpc_client .get_virtual_chain_from_block_call(GetVirtualChainFromBlockRequest { - start_hash: SIMNET_GENESIS.hash, + start_hash: None, // None implicitly means genesis include_accepted_transaction_ids: false, }) .await From 992f6237bed5b8d80df635de6dc3df33d0bedcfe Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:02:29 +0200 Subject: [PATCH 04/26] small clean-up --- rpc/service/src/service.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index b62a3d718..1ba3c294e 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -529,16 +529,9 @@ NOTE: This error usually indicates an RPC conversion error between the node and ) -> RpcResult { let session = self.consensus_manager.consensus().session().await; - // If start_hash is empty - use ORIGIN instead. - let start_hash = match request.start_hash { - Some(start_hash) => { - // Make sure start_hash points to an existing and valid block - session.async_get_ghostdag_data(start_hash).await?; - start_hash - } - None => session.async_get_source().await, - }; - + // If start_hash is empty - use source instead. + let start_hash = request.start_hash.unwrap_or(session.async_get_source().await); + // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; let virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { From 79421273ba8e31fcf0a731fdcbca88f915312715 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:03:29 +0200 Subject: [PATCH 05/26] fmt --- rpc/service/src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 1ba3c294e..17f796234 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -531,7 +531,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and // If start_hash is empty - use source instead. let start_hash = request.start_hash.unwrap_or(session.async_get_source().await); - // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. + // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; let virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { From 071d1bc8fb1ac5ab15d0c9dbb15ddccf13a517f9 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:45:42 +0200 Subject: [PATCH 06/26] actually bound by num of merged blocks, in include transactions case. --- rpc/service/src/service.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 17f796234..cb65fdc2b 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -533,9 +533,12 @@ NOTE: This error usually indicates an RPC conversion error between the node and let start_hash = request.start_hash.unwrap_or(session.async_get_source().await); // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; - let virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; + let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { - self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await? + let accepted_transaction_ids = self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; + // bound added to the length of the accepted transaction ids, which is bounded by merged blocks + virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec(); + accepted_transaction_ids } else { vec![] }; From 0e77804e475d75ec0fa6b8d23e0fbce8fb8cb5d7 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Fri, 19 Apr 2024 08:46:11 +0200 Subject: [PATCH 07/26] fmt --- rpc/service/src/service.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index cb65fdc2b..53e0da04f 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -535,7 +535,8 @@ NOTE: This error usually indicates an RPC conversion error between the node and let limit = (self.config.mergeset_size_limit * 10) as usize; let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { - let accepted_transaction_ids = self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; + let accepted_transaction_ids = + self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; // bound added to the length of the accepted transaction ids, which is bounded by merged blocks virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec(); accepted_transaction_ids From 1774a4586ddd1f33f0217ab794e397bb244465c2 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:48:10 +0200 Subject: [PATCH 08/26] update. --- consensus/src/consensus/mod.rs | 11 +++++------ rpc/grpc/core/proto/rpc.proto | 5 +++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 344c4ff6c..7f6d89359 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -535,22 +535,21 @@ impl ConsensusApi for Consensus { } fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { - // Calculate chain changes between the given `low` and `high` hash (or up to `max_blocks`). + // Calculate chain changes between the given `low` and `high` hash (up to `max_blocks`). // Note: // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. // 2) high will default to the sink, if `None``. - // 3) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. + // 3) if high is not a chain block it will get the virtual chain to the highest common chain block between high and sink. + // 4) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); self.validate_block_exists(low)?; let high = if let Some(high) = high { self.validate_block_exists(high)?; - if !self.services.reachability_service.is_chain_ancestor_of(low, high) { - return Err(ConsensusError::ExpectedAncestor(low, high)); - }; - self.services.sync_manager.find_highest_common_chain_block(low, high) + self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); + high } else { self.get_sink() }; diff --git a/rpc/grpc/core/proto/rpc.proto b/rpc/grpc/core/proto/rpc.proto index e558c6548..447a366c2 100644 --- a/rpc/grpc/core/proto/rpc.proto +++ b/rpc/grpc/core/proto/rpc.proto @@ -362,6 +362,11 @@ message GetSubnetworkResponseMessage{ // GetVirtualChainFromBlockRequestMessage requests the virtual selected // parent chain from some startHash to this kaspad's current virtual +// note: +// 1) this call batches the response to: +// a. the network's `mergeset size limit * 10` amount of chain blocks, if `includeAcceptedTransactionIds = false` +// b. the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` +// 2) if startHash is not supplied it will default to the node's source hash message GetVirtualChainFromBlockRequestMessage{ string startHash = 1; bool includeAcceptedTransactionIds = 2; From 21efe132daa989624cc5a43d5993affa365f29e7 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:52:17 +0200 Subject: [PATCH 09/26] update_2 --- consensus/src/consensus/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 7f6d89359..242d61ad3 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -548,7 +548,10 @@ impl ConsensusApi for Consensus { self.validate_block_exists(low)?; let high = if let Some(high) = high { self.validate_block_exists(high)?; - self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); + high = self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); + if !self.is_chain_ancestor_of(low, new_high)? { + return Err(ConsensusError::ExpectedAncestor(low, high)); + } high } else { self.get_sink() From fc5264af11aa667db4d91282ce32dbd07e4dc0ee Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 16:54:37 +0200 Subject: [PATCH 10/26] new_high = high --- consensus/src/consensus/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 242d61ad3..2a158b751 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -548,8 +548,8 @@ impl ConsensusApi for Consensus { self.validate_block_exists(low)?; let high = if let Some(high) = high { self.validate_block_exists(high)?; - high = self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); - if !self.is_chain_ancestor_of(low, new_high)? { + let high = self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); + if !self.is_chain_ancestor_of(low, high)? { return Err(ConsensusError::ExpectedAncestor(low, high)); } high From 15d6e8df7f5ff88d95f7838f38485ba4e183d44c Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:48:05 +0200 Subject: [PATCH 11/26] remove high hash in consensus api.. as it is not required. --- components/consensusmanager/src/session.rs | 9 ++------ consensus/core/src/api/mod.rs | 10 ++++----- consensus/src/consensus/mod.rs | 22 +++++-------------- rpc/service/src/service.rs | 2 +- .../src/daemon_integration_tests.rs | 8 ++++++- testing/integration/src/rpc_tests.rs | 2 +- 6 files changed, 21 insertions(+), 32 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index 822785e62..38a1835c9 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -252,13 +252,8 @@ impl ConsensusSessionOwned { self.clone().spawn_blocking(|c| c.is_nearly_synced()).await } - pub async fn async_get_virtual_chain_from_block( - &self, - low: Hash, - high: Option, - max_blocks: usize, - ) -> ConsensusResult { - self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, high, max_blocks)).await + pub async fn async_get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { + self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, limit)).await } pub async fn async_get_virtual_utxos( diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index 32dfc3d48..15e57605d 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -147,14 +147,12 @@ pub trait ConsensusApi: Send + Sync { unimplemented!() } - /// Gets the virtual chain paths from `low` to the `high` hash, or until max_blocks is reached + /// Gets the virtual chain paths from `low` to the `sink` hash, or until `limit`` is reached /// /// Note: - /// 1) Specifying the `high` hash as `None` will calculate the chain path up to the current sink. - /// 2) Specifying `max_blocks` as `None` will impose no limit. - /// 3) `max_blocks` limit will populate removed & added chain path, up to max_blocks. - /// 3.1) use usize::MAX to get all blocks in the chain path, with optimized performance, (in cases where batching is not required) - fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { + /// 1) `limit` will populate removed and then the added chain path, up to the specified amount. + /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. + fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { unimplemented!() } diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 2a158b751..a26a8c257 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -534,30 +534,18 @@ impl ConsensusApi for Consensus { self.config.is_nearly_synced(compact.timestamp, compact.daa_score) } - fn get_virtual_chain_from_block(&self, low: Hash, high: Option, max_blocks: usize) -> ConsensusResult { - // Calculate chain changes between the given `low` and `high` hash (up to `max_blocks`). + fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { + // Calculate chain changes between the given `low` and the current sink hash (up to `limit` amount of block hashes). // Note: // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. - // 2) high will default to the sink, if `None``. - // 3) if high is not a chain block it will get the virtual chain to the highest common chain block between high and sink. - // 4) supplying `usize::MAX` as `max_blocks` will result in the full chain path, with optimized performance. + // 2) supplying `usize::MAX` as `limit` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); self.validate_block_exists(low)?; - let high = if let Some(high) = high { - self.validate_block_exists(high)?; - let high = self.services.sync_manager.find_highest_common_chain_block(high, self.get_sink()); - if !self.is_chain_ancestor_of(low, high)? { - return Err(ConsensusError::ExpectedAncestor(low, high)); - } - high - } else { - self.get_sink() - }; - Ok(self.services.dag_traversal_manager.calculate_chain_path(low, high, max_blocks)) + Ok(self.services.dag_traversal_manager.calculate_chain_path(low, self.get_sink(), limit)) } /// Returns a Vec of header samples since genesis @@ -853,6 +841,8 @@ impl ConsensusApi for Consensus { } fn get_blocks_acceptance_data(&self, hashes: &[Hash], merged_blocks_limit: usize) -> ConsensusResult>> { + // Note: merged_blocks_limit will limit after the sum of merged blocks is breached along the supplied hash's acceptance data + // and not limit the acceptance data within a queried hash. i.e. It has mergeset_size_limit granularity, this is to guarantee full acceptance data coverage. if merged_blocks_limit == usize::MAX { return hashes .iter() diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 53e0da04f..ce5324bc4 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -533,7 +533,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and let start_hash = request.start_hash.unwrap_or(session.async_get_source().await); // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; - let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, None, limit).await?; + let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { let accepted_transaction_ids = self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; diff --git a/testing/integration/src/daemon_integration_tests.rs b/testing/integration/src/daemon_integration_tests.rs index 09cf1f500..37a47902a 100644 --- a/testing/integration/src/daemon_integration_tests.rs +++ b/testing/integration/src/daemon_integration_tests.rs @@ -104,7 +104,13 @@ async fn daemon_mining_test() { assert_eq!(dag_info.sink, last_block_hash.unwrap()); // Check that acceptance data contains the expected coinbase tx ids - let vc = rpc_client2.get_virtual_chain_from_block(None, true).await.unwrap(); + let vc = rpc_client2 + .get_virtual_chain_from_block( + None, // `None` defaults to genesis i.e. the node's source hash. + true, + ) + .await + .unwrap(); assert_eq!(vc.removed_chain_block_hashes.len(), 0); assert_eq!(vc.added_chain_block_hashes.len(), 10); assert_eq!(vc.accepted_transaction_ids.len(), 10); diff --git a/testing/integration/src/rpc_tests.rs b/testing/integration/src/rpc_tests.rs index 9c260df98..f51b80138 100644 --- a/testing/integration/src/rpc_tests.rs +++ b/testing/integration/src/rpc_tests.rs @@ -140,7 +140,7 @@ async fn sanity_test() { // and the virtual chain from genesis contains the added block let response = rpc_client .get_virtual_chain_from_block_call(GetVirtualChainFromBlockRequest { - start_hash: None, // None implicitly means genesis + start_hash: None, // `None` defaults to genesis i.e. the node's source hash. include_accepted_transaction_ids: false, }) .await From c67ba7265545db91df7205600f9bc73da5655ddc Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:50:39 +0200 Subject: [PATCH 12/26] fmt --- consensus/core/src/api/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index 15e57605d..d48ea618f 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -151,7 +151,7 @@ pub trait ConsensusApi: Send + Sync { /// /// Note: /// 1) `limit` will populate removed and then the added chain path, up to the specified amount. - /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. + /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { unimplemented!() } From c8dce10864882ccd68c990f99c1a0142227d3d17 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:54:39 +0200 Subject: [PATCH 13/26] make proto comment more accurate. --- rpc/grpc/core/proto/rpc.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/grpc/core/proto/rpc.proto b/rpc/grpc/core/proto/rpc.proto index 447a366c2..774b66072 100644 --- a/rpc/grpc/core/proto/rpc.proto +++ b/rpc/grpc/core/proto/rpc.proto @@ -365,7 +365,7 @@ message GetSubnetworkResponseMessage{ // note: // 1) this call batches the response to: // a. the network's `mergeset size limit * 10` amount of chain blocks, if `includeAcceptedTransactionIds = false` -// b. the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` +// b. when the acceptance data queried exceeds the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` // 2) if startHash is not supplied it will default to the node's source hash message GetVirtualChainFromBlockRequestMessage{ string startHash = 1; From d546cb6c1adb0d6d123e15c196278683d860c93c Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Wed, 28 Aug 2024 21:28:58 +0200 Subject: [PATCH 14/26] fix tests, and lints, add to ser / der correctly. --- consensus/core/src/api/mod.rs | 4 ++-- rpc/core/src/model/message.rs | 4 ++-- rpc/grpc/core/proto/rpc.proto | 14 +++++++------- testing/integration/src/rpc_tests.rs | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index ea3b602c1..08cfae76f 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -160,8 +160,8 @@ pub trait ConsensusApi: Send + Sync { /// Gets the virtual chain paths from `low` to the `sink` hash, or until `limit`` is reached /// /// Note: - /// 1) `limit` will populate removed and then the added chain path, up to the specified amount. - /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. + /// 1) `limit` will populate removed and then the added chain path, up to the specified amount. + /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { unimplemented!() } diff --git a/rpc/core/src/model/message.rs b/rpc/core/src/model/message.rs index 87dc89929..aa9ae916c 100644 --- a/rpc/core/src/model/message.rs +++ b/rpc/core/src/model/message.rs @@ -870,7 +870,7 @@ impl GetVirtualChainFromBlockRequest { impl Serializer for GetVirtualChainFromBlockRequest { fn serialize(&self, writer: &mut W) -> std::io::Result<()> { store!(u16, &1, writer)?; - store!(RpcHash, &self.start_hash, writer)?; + store!(Option, &self.start_hash, writer)?; store!(bool, &self.include_accepted_transaction_ids, writer)?; Ok(()) @@ -880,7 +880,7 @@ impl Serializer for GetVirtualChainFromBlockRequest { impl Deserializer for GetVirtualChainFromBlockRequest { fn deserialize(reader: &mut R) -> std::io::Result { let _version = load!(u16, reader)?; - let start_hash = load!(RpcHash, reader)?; + let start_hash = load!(Option, reader)?; let include_accepted_transaction_ids = load!(bool, reader)?; Ok(Self { start_hash, include_accepted_transaction_ids }) diff --git a/rpc/grpc/core/proto/rpc.proto b/rpc/grpc/core/proto/rpc.proto index 9e3b0801e..76f048cf0 100644 --- a/rpc/grpc/core/proto/rpc.proto +++ b/rpc/grpc/core/proto/rpc.proto @@ -375,13 +375,13 @@ message GetSubnetworkResponseMessage{ RPCError error = 1000; } -// GetVirtualChainFromBlockRequestMessage requests the virtual selected -// parent chain from some startHash to this kaspad's current virtual -// note: -// 1) this call batches the response to: -// a. the network's `mergeset size limit * 10` amount of chain blocks, if `includeAcceptedTransactionIds = false` -// b. when the acceptance data queried exceeds the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` -// 2) if startHash is not supplied it will default to the node's source hash +/// GetVirtualChainFromBlockRequestMessage requests the virtual selected +/// parent chain from some startHash to this kaspad's current virtual +/// Note: +/// 1) this call batches the response to: +/// a. the network's `mergeset size limit * 10` amount of chain blocks, if `includeAcceptedTransactionIds = false` +/// b. when the acceptance data queried exceeds the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` +/// 2) if startHash is not supplied it will default to the node's source hash message GetVirtualChainFromBlockRequestMessage{ string startHash = 1; bool includeAcceptedTransactionIds = 2; diff --git a/testing/integration/src/rpc_tests.rs b/testing/integration/src/rpc_tests.rs index 3c4df601b..fa2f8145f 100644 --- a/testing/integration/src/rpc_tests.rs +++ b/testing/integration/src/rpc_tests.rs @@ -93,7 +93,7 @@ async fn sanity_test() { .get_virtual_chain_from_block_call( None, GetVirtualChainFromBlockRequest { - start_hash: SIMNET_GENESIS.hash, + start_hash: Some(SIMNET_GENESIS.hash), include_accepted_transaction_ids: false, }, ) @@ -153,7 +153,7 @@ async fn sanity_test() { .get_virtual_chain_from_block_call( None, GetVirtualChainFromBlockRequest { - start_hash: SIMNET_GENESIS.hash, + start_hash: Some(SIMNET_GENESIS.hash), include_accepted_transaction_ids: false, }, ) From 536459c0e5fabbb73255952230e25874bd78a0f6 Mon Sep 17 00:00:00 2001 From: Michael Sutton Date: Mon, 16 Sep 2024 06:25:37 +0000 Subject: [PATCH 15/26] change two freq warns to debug --- mining/src/mempool/remove_transaction.rs | 6 +++--- rpc/service/src/service.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mining/src/mempool/remove_transaction.rs b/mining/src/mempool/remove_transaction.rs index 960ebc264..3aac8a20b 100644 --- a/mining/src/mempool/remove_transaction.rs +++ b/mining/src/mempool/remove_transaction.rs @@ -4,7 +4,7 @@ use crate::mempool::{ Mempool, }; use kaspa_consensus_core::tx::TransactionId; -use kaspa_core::{debug, warn}; +use kaspa_core::debug; use kaspa_utils::iter::IterExtensions; impl Mempool { @@ -43,8 +43,8 @@ impl Mempool { TxRemovalReason::Muted => {} TxRemovalReason::DoubleSpend => match removed_transactions.len() { 0 => {} - 1 => warn!("Removed transaction ({}) {}{}", reason, removed_transactions[0], extra_info), - n => warn!( + 1 => debug!("Removed transaction ({}) {}{}", reason, removed_transactions[0], extra_info), + n => debug!( "Removed {} transactions ({}): {}{}", n, reason, diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 2c22fd6bb..6ad34e896 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -539,7 +539,7 @@ NOTE: This error usually indicates an RPC conversion error between the node and ) -> RpcResult { let allow_orphan = self.config.unsafe_rpc && request.allow_orphan; if !self.config.unsafe_rpc && request.allow_orphan { - warn!("SubmitTransaction RPC command called with AllowOrphan enabled while node in safe RPC mode -- switching to ForbidOrphan."); + debug!("SubmitTransaction RPC command called with AllowOrphan enabled while node in safe RPC mode -- switching to ForbidOrphan."); } let transaction: Transaction = request.transaction.try_into()?; From a9f1bfc73cbe9b3f8432fcf2df37347b75131809 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:00:19 +0200 Subject: [PATCH 16/26] remove option, default to pp. not source. --- rpc/core/src/api/rpc.rs | 2 +- rpc/core/src/model/message.rs | 8 ++++---- rpc/grpc/core/src/convert/message.rs | 6 +++--- rpc/service/src/service.rs | 14 ++++++++++++-- testing/integration/src/rpc_tests.rs | 4 ++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/rpc/core/src/api/rpc.rs b/rpc/core/src/api/rpc.rs index b69c9c7b3..85713e547 100644 --- a/rpc/core/src/api/rpc.rs +++ b/rpc/core/src/api/rpc.rs @@ -243,7 +243,7 @@ pub trait RpcApi: Sync + Send + AnySync { /// Requests the virtual selected parent chain from some `start_hash` to this node's current virtual. async fn get_virtual_chain_from_block( &self, - start_hash: Option, + start_hash: RpcHash, include_accepted_transaction_ids: bool, ) -> RpcResult { self.get_virtual_chain_from_block_call( diff --git a/rpc/core/src/model/message.rs b/rpc/core/src/model/message.rs index 66895366b..ba8d6abf7 100644 --- a/rpc/core/src/model/message.rs +++ b/rpc/core/src/model/message.rs @@ -857,12 +857,12 @@ impl Deserializer for GetSubnetworkResponse { #[derive(Clone, Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct GetVirtualChainFromBlockRequest { - pub start_hash: Option, + pub start_hash: RpcHash, pub include_accepted_transaction_ids: bool, } impl GetVirtualChainFromBlockRequest { - pub fn new(start_hash: Option, include_accepted_transaction_ids: bool) -> Self { + pub fn new(start_hash: RpcHash, include_accepted_transaction_ids: bool) -> Self { Self { start_hash, include_accepted_transaction_ids } } } @@ -870,7 +870,7 @@ impl GetVirtualChainFromBlockRequest { impl Serializer for GetVirtualChainFromBlockRequest { fn serialize(&self, writer: &mut W) -> std::io::Result<()> { store!(u16, &1, writer)?; - store!(Option, &self.start_hash, writer)?; + store!(RpcHash, &self.start_hash, writer)?; store!(bool, &self.include_accepted_transaction_ids, writer)?; Ok(()) @@ -880,7 +880,7 @@ impl Serializer for GetVirtualChainFromBlockRequest { impl Deserializer for GetVirtualChainFromBlockRequest { fn deserialize(reader: &mut R) -> std::io::Result { let _version = load!(u16, reader)?; - let start_hash = load!(Option, reader)?; + let start_hash = load!(RpcHash, reader)?; let include_accepted_transaction_ids = load!(bool, reader)?; Ok(Self { start_hash, include_accepted_transaction_ids }) diff --git a/rpc/grpc/core/src/convert/message.rs b/rpc/grpc/core/src/convert/message.rs index b29253e37..b188bc09a 100644 --- a/rpc/grpc/core/src/convert/message.rs +++ b/rpc/grpc/core/src/convert/message.rs @@ -19,7 +19,7 @@ //! The SubmitBlockResponse is a notable exception to this general rule. use crate::protowire::{self, submit_block_response_message::RejectReason}; -use kaspa_consensus_core::network::NetworkId; +use kaspa_consensus_core::{blockhash::BlockHashExtensions, network::NetworkId}; use kaspa_core::debug; use kaspa_notify::subscription::Command; use kaspa_rpc_core::{ @@ -266,7 +266,7 @@ from!(item: RpcResult<&kaspa_rpc_core::GetSubnetworkResponse>, protowire::GetSub // ~~~ from!(item: &kaspa_rpc_core::GetVirtualChainFromBlockRequest, protowire::GetVirtualChainFromBlockRequestMessage, { - Self { start_hash: item.start_hash.map_or(Default::default(), |x| x.to_string()), include_accepted_transaction_ids: item.include_accepted_transaction_ids } + Self { start_hash: if item.start_hash.is_none() { String::default() } else { item.start_hash.to_string() }, include_accepted_transaction_ids: item.include_accepted_transaction_ids } }); from!(item: RpcResult<&kaspa_rpc_core::GetVirtualChainFromBlockResponse>, protowire::GetVirtualChainFromBlockResponseMessage, { Self { @@ -746,7 +746,7 @@ try_from!(item: &protowire::GetSubnetworkResponseMessage, RpcResult, { Self { diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 3784e18ae..7d76e4883 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -6,6 +6,7 @@ use crate::converter::{consensus::ConsensusConverter, index::IndexConverter, pro use crate::service::NetworkType::{Mainnet, Testnet}; use async_trait::async_trait; use kaspa_consensus_core::api::counters::ProcessingCounters; +use kaspa_consensus_core::blockhash::BlockHashExtensions; use kaspa_consensus_core::errors::block::RuleError; use kaspa_consensus_core::{ block::Block, @@ -611,8 +612,17 @@ NOTE: This error usually indicates an RPC conversion error between the node and let session = self.consensus_manager.consensus().session().await; // If start_hash is empty - use source instead. - let start_hash = request.start_hash.unwrap_or(session.async_get_source().await); - // limit is set to 10 times the mergeset_size_limit, bounded by number of merged blocks. + let start_hash = if request.start_hash.is_none() { + // we default to the pruning point if the start hash is not provided + session.async_pruning_point().await + } else { + request.start_hash + }; + + // limit is set to 10 times the mergeset_size_limit. + // this means limit is 2480 on 10 bps, and 1800 on mainnet. + // this bounds by number of merged blocks, if include_accepted_transactions = true + // else it returns the limit amount on pure chain blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { diff --git a/testing/integration/src/rpc_tests.rs b/testing/integration/src/rpc_tests.rs index fa2f8145f..3c4df601b 100644 --- a/testing/integration/src/rpc_tests.rs +++ b/testing/integration/src/rpc_tests.rs @@ -93,7 +93,7 @@ async fn sanity_test() { .get_virtual_chain_from_block_call( None, GetVirtualChainFromBlockRequest { - start_hash: Some(SIMNET_GENESIS.hash), + start_hash: SIMNET_GENESIS.hash, include_accepted_transaction_ids: false, }, ) @@ -153,7 +153,7 @@ async fn sanity_test() { .get_virtual_chain_from_block_call( None, GetVirtualChainFromBlockRequest { - start_hash: Some(SIMNET_GENESIS.hash), + start_hash: SIMNET_GENESIS.hash, include_accepted_transaction_ids: false, }, ) From f3cf2356ed1388d6226a9317f3311ddab9f73c97 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:02:31 +0200 Subject: [PATCH 17/26] fix integration test, some Option left. --- testing/integration/src/daemon_integration_tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/integration/src/daemon_integration_tests.rs b/testing/integration/src/daemon_integration_tests.rs index 07187eb1c..d3c26513a 100644 --- a/testing/integration/src/daemon_integration_tests.rs +++ b/testing/integration/src/daemon_integration_tests.rs @@ -11,6 +11,7 @@ use kaspa_consensus_core::header::Header; use kaspa_consensusmanager::ConsensusManager; use kaspa_core::{task::runtime::AsyncRuntime, trace}; use kaspa_grpc_client::GrpcClient; +use kaspa_hashes::ZERO_HASH; use kaspa_notify::scope::{BlockAddedScope, UtxosChangedScope, VirtualDaaScoreChangedScope}; use kaspa_rpc_core::{api::rpc::RpcApi, Notification, RpcTransactionId}; use kaspa_txscript::pay_to_address_script; @@ -108,7 +109,7 @@ async fn daemon_mining_test() { // Check that acceptance data contains the expected coinbase tx ids let vc = rpc_client2 .get_virtual_chain_from_block( - None, // `None` defaults to genesis i.e. the node's source hash. + ZERO_HASH, // `ZERO_HASH` defaults to genesis i.e. the node's pp hash. true, ) .await @@ -231,7 +232,7 @@ async fn daemon_utxos_propagation_test() { assert_eq!(dag_info.sink, last_block_hash.unwrap()); // Check that acceptance data contains the expected coinbase tx ids - let vc = rpc_client2.get_virtual_chain_from_block(Some(kaspa_consensus::params::SIMNET_GENESIS.hash), true).await.unwrap(); + let vc = rpc_client2.get_virtual_chain_from_block(kaspa_consensus::params::SIMNET_GENESIS.hash, true).await.unwrap(); assert_eq!(vc.removed_chain_block_hashes.len(), 0); assert_eq!(vc.added_chain_block_hashes.len() as u64, initial_blocks); assert_eq!(vc.accepted_transaction_ids.len() as u64, initial_blocks); From 06b546b645506a8de27ea637aa4a7cec064cecd2 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:09:43 +0200 Subject: [PATCH 18/26] =?UTF-8?q?bump=20version:=20=C2=B40.15.1=20=3D>=200?= =?UTF-8?q?.15.2`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 116 ++++++++++++++++++++++++++--------------------------- Cargo.toml | 112 +++++++++++++++++++++++++-------------------------- 2 files changed, 114 insertions(+), 114 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f23aca0f..1296a8922 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2363,7 +2363,7 @@ dependencies = [ [[package]] name = "kaspa-addresses" -version = "0.15.1" +version = "0.15.2" dependencies = [ "borsh", "criterion", @@ -2380,7 +2380,7 @@ dependencies = [ [[package]] name = "kaspa-addressmanager" -version = "0.15.1" +version = "0.15.2" dependencies = [ "borsh", "igd-next", @@ -2403,14 +2403,14 @@ dependencies = [ [[package]] name = "kaspa-alloc" -version = "0.15.1" +version = "0.15.2" dependencies = [ "mimalloc", ] [[package]] name = "kaspa-bip32" -version = "0.15.1" +version = "0.15.2" dependencies = [ "borsh", "bs58", @@ -2437,7 +2437,7 @@ dependencies = [ [[package]] name = "kaspa-cli" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "borsh", @@ -2484,7 +2484,7 @@ dependencies = [ [[package]] name = "kaspa-connectionmanager" -version = "0.15.1" +version = "0.15.2" dependencies = [ "duration-string", "futures-util", @@ -2501,7 +2501,7 @@ dependencies = [ [[package]] name = "kaspa-consensus" -version = "0.15.1" +version = "0.15.2" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -2544,7 +2544,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-client" -version = "0.15.1" +version = "0.15.2" dependencies = [ "ahash", "cfg-if 1.0.0", @@ -2572,7 +2572,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "bincode", @@ -2610,7 +2610,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-notify" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -2629,7 +2629,7 @@ dependencies = [ [[package]] name = "kaspa-consensus-wasm" -version = "0.15.1" +version = "0.15.2" dependencies = [ "cfg-if 1.0.0", "faster-hex", @@ -2653,7 +2653,7 @@ dependencies = [ [[package]] name = "kaspa-consensusmanager" -version = "0.15.1" +version = "0.15.2" dependencies = [ "duration-string", "futures", @@ -2671,7 +2671,7 @@ dependencies = [ [[package]] name = "kaspa-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "cfg-if 1.0.0", "ctrlc", @@ -2689,7 +2689,7 @@ dependencies = [ [[package]] name = "kaspa-daemon" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "borsh", @@ -2711,7 +2711,7 @@ dependencies = [ [[package]] name = "kaspa-database" -version = "0.15.1" +version = "0.15.2" dependencies = [ "bincode", "enum-primitive-derive", @@ -2733,7 +2733,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-client" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2765,7 +2765,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2794,7 +2794,7 @@ dependencies = [ [[package]] name = "kaspa-grpc-server" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-stream", @@ -2830,7 +2830,7 @@ dependencies = [ [[package]] name = "kaspa-hashes" -version = "0.15.1" +version = "0.15.2" dependencies = [ "blake2b_simd", "borsh", @@ -2851,7 +2851,7 @@ dependencies = [ [[package]] name = "kaspa-index-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2870,7 +2870,7 @@ dependencies = [ [[package]] name = "kaspa-index-processor" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -2898,7 +2898,7 @@ dependencies = [ [[package]] name = "kaspa-math" -version = "0.15.1" +version = "0.15.2" dependencies = [ "borsh", "criterion", @@ -2919,14 +2919,14 @@ dependencies = [ [[package]] name = "kaspa-merkle" -version = "0.15.1" +version = "0.15.2" dependencies = [ "kaspa-hashes", ] [[package]] name = "kaspa-metrics-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "borsh", @@ -2942,7 +2942,7 @@ dependencies = [ [[package]] name = "kaspa-mining" -version = "0.15.1" +version = "0.15.2" dependencies = [ "criterion", "futures-util", @@ -2969,7 +2969,7 @@ dependencies = [ [[package]] name = "kaspa-mining-errors" -version = "0.15.1" +version = "0.15.2" dependencies = [ "kaspa-consensus-core", "thiserror", @@ -2977,7 +2977,7 @@ dependencies = [ [[package]] name = "kaspa-muhash" -version = "0.15.1" +version = "0.15.2" dependencies = [ "criterion", "kaspa-hashes", @@ -2990,7 +2990,7 @@ dependencies = [ [[package]] name = "kaspa-notify" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3026,7 +3026,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-flows" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "chrono", @@ -3057,7 +3057,7 @@ dependencies = [ [[package]] name = "kaspa-p2p-lib" -version = "0.15.1" +version = "0.15.2" dependencies = [ "borsh", "ctrlc", @@ -3088,7 +3088,7 @@ dependencies = [ [[package]] name = "kaspa-perf-monitor" -version = "0.15.1" +version = "0.15.2" dependencies = [ "kaspa-core", "log", @@ -3100,7 +3100,7 @@ dependencies = [ [[package]] name = "kaspa-pow" -version = "0.15.1" +version = "0.15.2" dependencies = [ "criterion", "js-sys", @@ -3116,7 +3116,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3158,7 +3158,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-macros" -version = "0.15.1" +version = "0.15.2" dependencies = [ "convert_case 0.6.0", "proc-macro-error", @@ -3170,7 +3170,7 @@ dependencies = [ [[package]] name = "kaspa-rpc-service" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "kaspa-addresses", @@ -3199,7 +3199,7 @@ dependencies = [ [[package]] name = "kaspa-testing-integration" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "async-trait", @@ -3259,7 +3259,7 @@ dependencies = [ [[package]] name = "kaspa-txscript" -version = "0.15.1" +version = "0.15.2" dependencies = [ "blake2b_simd", "borsh", @@ -3291,7 +3291,7 @@ dependencies = [ [[package]] name = "kaspa-txscript-errors" -version = "0.15.1" +version = "0.15.2" dependencies = [ "secp256k1", "thiserror", @@ -3299,7 +3299,7 @@ dependencies = [ [[package]] name = "kaspa-utils" -version = "0.15.1" +version = "0.15.2" dependencies = [ "arc-swap", "async-channel 2.3.1", @@ -3335,7 +3335,7 @@ dependencies = [ [[package]] name = "kaspa-utils-tower" -version = "0.15.1" +version = "0.15.2" dependencies = [ "cfg-if 1.0.0", "futures", @@ -3349,7 +3349,7 @@ dependencies = [ [[package]] name = "kaspa-utxoindex" -version = "0.15.1" +version = "0.15.2" dependencies = [ "futures", "kaspa-consensus", @@ -3370,7 +3370,7 @@ dependencies = [ [[package]] name = "kaspa-wallet" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-std", "async-trait", @@ -3382,7 +3382,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-cli-wasm" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "js-sys", @@ -3396,7 +3396,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "aes", "ahash", @@ -3477,7 +3477,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-keys" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "borsh", @@ -3510,7 +3510,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-macros" -version = "0.15.1" +version = "0.15.2" dependencies = [ "convert_case 0.5.0", "proc-macro-error", @@ -3523,7 +3523,7 @@ dependencies = [ [[package]] name = "kaspa-wallet-pskt" -version = "0.15.1" +version = "0.15.2" dependencies = [ "bincode", "derive_builder", @@ -3550,7 +3550,7 @@ dependencies = [ [[package]] name = "kaspa-wasm" -version = "0.15.1" +version = "0.15.2" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3578,7 +3578,7 @@ dependencies = [ [[package]] name = "kaspa-wasm-core" -version = "0.15.1" +version = "0.15.2" dependencies = [ "faster-hex", "hexplay", @@ -3589,7 +3589,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-client" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-std", "async-trait", @@ -3625,7 +3625,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-example-subscriber" -version = "0.15.1" +version = "0.15.2" dependencies = [ "ctrlc", "futures", @@ -3640,7 +3640,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-proxy" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "clap 4.5.16", @@ -3659,7 +3659,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-server" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-trait", "borsh", @@ -3687,7 +3687,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-simple-client-example" -version = "0.15.1" +version = "0.15.2" dependencies = [ "futures", "kaspa-rpc-core", @@ -3697,7 +3697,7 @@ dependencies = [ [[package]] name = "kaspa-wrpc-wasm" -version = "0.15.1" +version = "0.15.2" dependencies = [ "ahash", "async-std", @@ -3727,7 +3727,7 @@ dependencies = [ [[package]] name = "kaspad" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", @@ -5151,7 +5151,7 @@ dependencies = [ [[package]] name = "rothschild" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "clap 4.5.16", @@ -5603,7 +5603,7 @@ dependencies = [ [[package]] name = "simpa" -version = "0.15.1" +version = "0.15.2" dependencies = [ "async-channel 2.3.1", "cfg-if 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index eaf07936e..37acfb172 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,7 +63,7 @@ members = [ [workspace.package] rust-version = "1.81.0" -version = "0.15.1" +version = "0.15.2" authors = ["Kaspa developers"] license = "ISC" repository = "https://github.com/kaspanet/rusty-kaspa" @@ -80,61 +80,61 @@ include = [ ] [workspace.dependencies] -# kaspa-testing-integration = { version = "0.15.1", path = "testing/integration" } -kaspa-addresses = { version = "0.15.1", path = "crypto/addresses" } -kaspa-addressmanager = { version = "0.15.1", path = "components/addressmanager" } -kaspa-bip32 = { version = "0.15.1", path = "wallet/bip32" } -kaspa-cli = { version = "0.15.1", path = "cli" } -kaspa-connectionmanager = { version = "0.15.1", path = "components/connectionmanager" } -kaspa-consensus = { version = "0.15.1", path = "consensus" } -kaspa-consensus-core = { version = "0.15.1", path = "consensus/core" } -kaspa-consensus-client = { version = "0.15.1", path = "consensus/client" } -kaspa-consensus-notify = { version = "0.15.1", path = "consensus/notify" } -kaspa-consensus-wasm = { version = "0.15.1", path = "consensus/wasm" } -kaspa-consensusmanager = { version = "0.15.1", path = "components/consensusmanager" } -kaspa-core = { version = "0.15.1", path = "core" } -kaspa-daemon = { version = "0.15.1", path = "daemon" } -kaspa-database = { version = "0.15.1", path = "database" } -kaspa-grpc-client = { version = "0.15.1", path = "rpc/grpc/client" } -kaspa-grpc-core = { version = "0.15.1", path = "rpc/grpc/core" } -kaspa-grpc-server = { version = "0.15.1", path = "rpc/grpc/server" } -kaspa-hashes = { version = "0.15.1", path = "crypto/hashes" } -kaspa-index-core = { version = "0.15.1", path = "indexes/core" } -kaspa-index-processor = { version = "0.15.1", path = "indexes/processor" } -kaspa-math = { version = "0.15.1", path = "math" } -kaspa-merkle = { version = "0.15.1", path = "crypto/merkle" } -kaspa-metrics-core = { version = "0.15.1", path = "metrics/core" } -kaspa-mining = { version = "0.15.1", path = "mining" } -kaspa-mining-errors = { version = "0.15.1", path = "mining/errors" } -kaspa-muhash = { version = "0.15.1", path = "crypto/muhash" } -kaspa-notify = { version = "0.15.1", path = "notify" } -kaspa-p2p-flows = { version = "0.15.1", path = "protocol/flows" } -kaspa-p2p-lib = { version = "0.15.1", path = "protocol/p2p" } -kaspa-perf-monitor = { version = "0.15.1", path = "metrics/perf_monitor" } -kaspa-pow = { version = "0.15.1", path = "consensus/pow" } -kaspa-rpc-core = { version = "0.15.1", path = "rpc/core" } -kaspa-rpc-macros = { version = "0.15.1", path = "rpc/macros" } -kaspa-rpc-service = { version = "0.15.1", path = "rpc/service" } -kaspa-txscript = { version = "0.15.1", path = "crypto/txscript" } -kaspa-txscript-errors = { version = "0.15.1", path = "crypto/txscript/errors" } -kaspa-utils = { version = "0.15.1", path = "utils" } -kaspa-utils-tower = { version = "0.15.1", path = "utils/tower" } -kaspa-utxoindex = { version = "0.15.1", path = "indexes/utxoindex" } -kaspa-wallet = { version = "0.15.1", path = "wallet/native" } -kaspa-wallet-cli-wasm = { version = "0.15.1", path = "wallet/wasm" } -kaspa-wallet-keys = { version = "0.15.1", path = "wallet/keys" } -kaspa-wallet-pskt = { version = "0.15.1", path = "wallet/pskt" } -kaspa-wallet-core = { version = "0.15.1", path = "wallet/core" } -kaspa-wallet-macros = { version = "0.15.1", path = "wallet/macros" } -kaspa-wasm = { version = "0.15.1", path = "wasm" } -kaspa-wasm-core = { version = "0.15.1", path = "wasm/core" } -kaspa-wrpc-client = { version = "0.15.1", path = "rpc/wrpc/client" } -kaspa-wrpc-proxy = { version = "0.15.1", path = "rpc/wrpc/proxy" } -kaspa-wrpc-server = { version = "0.15.1", path = "rpc/wrpc/server" } -kaspa-wrpc-wasm = { version = "0.15.1", path = "rpc/wrpc/wasm" } -kaspa-wrpc-example-subscriber = { version = "0.15.1", path = "rpc/wrpc/examples/subscriber" } -kaspad = { version = "0.15.1", path = "kaspad" } -kaspa-alloc = { version = "0.15.1", path = "utils/alloc" } +# kaspa-testing-integration = { version = "0.15.2", path = "testing/integration" } +kaspa-addresses = { version = "0.15.2", path = "crypto/addresses" } +kaspa-addressmanager = { version = "0.15.2", path = "components/addressmanager" } +kaspa-bip32 = { version = "0.15.2", path = "wallet/bip32" } +kaspa-cli = { version = "0.15.2", path = "cli" } +kaspa-connectionmanager = { version = "0.15.2", path = "components/connectionmanager" } +kaspa-consensus = { version = "0.15.2", path = "consensus" } +kaspa-consensus-core = { version = "0.15.2", path = "consensus/core" } +kaspa-consensus-client = { version = "0.15.2", path = "consensus/client" } +kaspa-consensus-notify = { version = "0.15.2", path = "consensus/notify" } +kaspa-consensus-wasm = { version = "0.15.2", path = "consensus/wasm" } +kaspa-consensusmanager = { version = "0.15.2", path = "components/consensusmanager" } +kaspa-core = { version = "0.15.2", path = "core" } +kaspa-daemon = { version = "0.15.2", path = "daemon" } +kaspa-database = { version = "0.15.2", path = "database" } +kaspa-grpc-client = { version = "0.15.2", path = "rpc/grpc/client" } +kaspa-grpc-core = { version = "0.15.2", path = "rpc/grpc/core" } +kaspa-grpc-server = { version = "0.15.2", path = "rpc/grpc/server" } +kaspa-hashes = { version = "0.15.2", path = "crypto/hashes" } +kaspa-index-core = { version = "0.15.2", path = "indexes/core" } +kaspa-index-processor = { version = "0.15.2", path = "indexes/processor" } +kaspa-math = { version = "0.15.2", path = "math" } +kaspa-merkle = { version = "0.15.2", path = "crypto/merkle" } +kaspa-metrics-core = { version = "0.15.2", path = "metrics/core" } +kaspa-mining = { version = "0.15.2", path = "mining" } +kaspa-mining-errors = { version = "0.15.2", path = "mining/errors" } +kaspa-muhash = { version = "0.15.2", path = "crypto/muhash" } +kaspa-notify = { version = "0.15.2", path = "notify" } +kaspa-p2p-flows = { version = "0.15.2", path = "protocol/flows" } +kaspa-p2p-lib = { version = "0.15.2", path = "protocol/p2p" } +kaspa-perf-monitor = { version = "0.15.2", path = "metrics/perf_monitor" } +kaspa-pow = { version = "0.15.2", path = "consensus/pow" } +kaspa-rpc-core = { version = "0.15.2", path = "rpc/core" } +kaspa-rpc-macros = { version = "0.15.2", path = "rpc/macros" } +kaspa-rpc-service = { version = "0.15.2", path = "rpc/service" } +kaspa-txscript = { version = "0.15.2", path = "crypto/txscript" } +kaspa-txscript-errors = { version = "0.15.2", path = "crypto/txscript/errors" } +kaspa-utils = { version = "0.15.2", path = "utils" } +kaspa-utils-tower = { version = "0.15.2", path = "utils/tower" } +kaspa-utxoindex = { version = "0.15.2", path = "indexes/utxoindex" } +kaspa-wallet = { version = "0.15.2", path = "wallet/native" } +kaspa-wallet-cli-wasm = { version = "0.15.2", path = "wallet/wasm" } +kaspa-wallet-keys = { version = "0.15.2", path = "wallet/keys" } +kaspa-wallet-pskt = { version = "0.15.2", path = "wallet/pskt" } +kaspa-wallet-core = { version = "0.15.2", path = "wallet/core" } +kaspa-wallet-macros = { version = "0.15.2", path = "wallet/macros" } +kaspa-wasm = { version = "0.15.2", path = "wasm" } +kaspa-wasm-core = { version = "0.15.2", path = "wasm/core" } +kaspa-wrpc-client = { version = "0.15.2", path = "rpc/wrpc/client" } +kaspa-wrpc-proxy = { version = "0.15.2", path = "rpc/wrpc/proxy" } +kaspa-wrpc-server = { version = "0.15.2", path = "rpc/wrpc/server" } +kaspa-wrpc-wasm = { version = "0.15.2", path = "rpc/wrpc/wasm" } +kaspa-wrpc-example-subscriber = { version = "0.15.2", path = "rpc/wrpc/examples/subscriber" } +kaspad = { version = "0.15.2", path = "kaspad" } +kaspa-alloc = { version = "0.15.2", path = "utils/alloc" } # external aes = "0.8.3" From 53710fa5001c6c77e2f92d8df6d0a6aef0ba4141 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:22:38 +0200 Subject: [PATCH 19/26] remove "optional" startHash --- rpc/grpc/core/src/convert/message.rs | 6 +++--- rpc/service/src/service.rs | 11 +---------- testing/integration/src/daemon_integration_tests.rs | 3 +-- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/rpc/grpc/core/src/convert/message.rs b/rpc/grpc/core/src/convert/message.rs index b188bc09a..c0e75cf03 100644 --- a/rpc/grpc/core/src/convert/message.rs +++ b/rpc/grpc/core/src/convert/message.rs @@ -19,7 +19,7 @@ //! The SubmitBlockResponse is a notable exception to this general rule. use crate::protowire::{self, submit_block_response_message::RejectReason}; -use kaspa_consensus_core::{blockhash::BlockHashExtensions, network::NetworkId}; +use kaspa_consensus_core::network::NetworkId; use kaspa_core::debug; use kaspa_notify::subscription::Command; use kaspa_rpc_core::{ @@ -266,7 +266,7 @@ from!(item: RpcResult<&kaspa_rpc_core::GetSubnetworkResponse>, protowire::GetSub // ~~~ from!(item: &kaspa_rpc_core::GetVirtualChainFromBlockRequest, protowire::GetVirtualChainFromBlockRequestMessage, { - Self { start_hash: if item.start_hash.is_none() { String::default() } else { item.start_hash.to_string() }, include_accepted_transaction_ids: item.include_accepted_transaction_ids } + Self { start_hash: item.start_hash.to_string(), include_accepted_transaction_ids: item.include_accepted_transaction_ids } }); from!(item: RpcResult<&kaspa_rpc_core::GetVirtualChainFromBlockResponse>, protowire::GetVirtualChainFromBlockResponseMessage, { Self { @@ -746,7 +746,7 @@ try_from!(item: &protowire::GetSubnetworkResponseMessage, RpcResult, { Self { diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 7d76e4883..ade227c3d 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -6,7 +6,6 @@ use crate::converter::{consensus::ConsensusConverter, index::IndexConverter, pro use crate::service::NetworkType::{Mainnet, Testnet}; use async_trait::async_trait; use kaspa_consensus_core::api::counters::ProcessingCounters; -use kaspa_consensus_core::blockhash::BlockHashExtensions; use kaspa_consensus_core::errors::block::RuleError; use kaspa_consensus_core::{ block::Block, @@ -611,20 +610,12 @@ NOTE: This error usually indicates an RPC conversion error between the node and ) -> RpcResult { let session = self.consensus_manager.consensus().session().await; - // If start_hash is empty - use source instead. - let start_hash = if request.start_hash.is_none() { - // we default to the pruning point if the start hash is not provided - session.async_pruning_point().await - } else { - request.start_hash - }; - // limit is set to 10 times the mergeset_size_limit. // this means limit is 2480 on 10 bps, and 1800 on mainnet. // this bounds by number of merged blocks, if include_accepted_transactions = true // else it returns the limit amount on pure chain blocks. let limit = (self.config.mergeset_size_limit * 10) as usize; - let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(start_hash, limit).await?; + let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, limit).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { let accepted_transaction_ids = self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; diff --git a/testing/integration/src/daemon_integration_tests.rs b/testing/integration/src/daemon_integration_tests.rs index d3c26513a..460cf049c 100644 --- a/testing/integration/src/daemon_integration_tests.rs +++ b/testing/integration/src/daemon_integration_tests.rs @@ -11,7 +11,6 @@ use kaspa_consensus_core::header::Header; use kaspa_consensusmanager::ConsensusManager; use kaspa_core::{task::runtime::AsyncRuntime, trace}; use kaspa_grpc_client::GrpcClient; -use kaspa_hashes::ZERO_HASH; use kaspa_notify::scope::{BlockAddedScope, UtxosChangedScope, VirtualDaaScoreChangedScope}; use kaspa_rpc_core::{api::rpc::RpcApi, Notification, RpcTransactionId}; use kaspa_txscript::pay_to_address_script; @@ -109,7 +108,7 @@ async fn daemon_mining_test() { // Check that acceptance data contains the expected coinbase tx ids let vc = rpc_client2 .get_virtual_chain_from_block( - ZERO_HASH, // `ZERO_HASH` defaults to genesis i.e. the node's pp hash. + kaspa_consensus::params::SIMNET_GENESIS.hash, // true, ) .await From b0451e71844a556aaff38b620d1fba981294a94b Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:33:10 +0200 Subject: [PATCH 20/26] add to cli rpc.rs --- cli/src/modules/rpc.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cli/src/modules/rpc.rs b/cli/src/modules/rpc.rs index f32523c4a..f96cb5b61 100644 --- a/cli/src/modules/rpc.rs +++ b/cli/src/modules/rpc.rs @@ -121,10 +121,20 @@ impl Rpc { // let result = rpc.get_subnetwork_call(GetSubnetworkRequest { }).await?; // self.println(&ctx, result); // } - // RpcApiOps::GetVirtualChainFromBlock => { - // let result = rpc.get_virtual_chain_from_block_call(GetVirtualChainFromBlockRequest { }).await?; - // self.println(&ctx, result); - // } + RpcApiOps::GetVirtualChainFromBlock => { + if argv.is_empty() { + return Err(Error::custom("Missing startHash argument")); + }; + let start_hash = RpcHash::from_hex(argv.remove(0).as_str())?; + let include_accepted_transaction_ids = argv.remove(0).parse::().unwrap_or_default(); + let result = rpc + .get_virtual_chain_from_block_call( + None, + GetVirtualChainFromBlockRequest { start_hash, include_accepted_transaction_ids }, + ) + .await?; + self.println(&ctx, result); + } // RpcApiOps::GetBlocks => { // let result = rpc.get_blocks_call(GetBlocksRequest { }).await?; // self.println(&ctx, result); From c2df43c89765b56420daddbff460beb9b36cb10e Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 18:40:18 +0200 Subject: [PATCH 21/26] remove comment. --- rpc/service/src/converter/consensus.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/service/src/converter/consensus.rs b/rpc/service/src/converter/consensus.rs index b1e5ce8a1..8099ca25e 100644 --- a/rpc/service/src/converter/consensus.rs +++ b/rpc/service/src/converter/consensus.rs @@ -162,7 +162,7 @@ impl ConsensusConverter { &self, consensus: &ConsensusProxy, chain_path: &ChainPath, - merged_blocks_limit: usize, // limit by number of transactions + merged_blocks_limit: usize, ) -> RpcResult> { let acceptance_data = consensus.async_get_blocks_acceptance_data(chain_path.added.clone(), merged_blocks_limit).await.unwrap(); Ok(chain_path From 2fe7d5d82c58bcc5f48b5d5b1caf1162e1cf1db0 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:29:27 +0200 Subject: [PATCH 22/26] edit comment in .proto referencing def. startHash behavior. --- rpc/grpc/core/proto/rpc.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rpc/grpc/core/proto/rpc.proto b/rpc/grpc/core/proto/rpc.proto index 988448bb1..18ce907a5 100644 --- a/rpc/grpc/core/proto/rpc.proto +++ b/rpc/grpc/core/proto/rpc.proto @@ -377,10 +377,9 @@ message GetSubnetworkResponseMessage{ /// GetVirtualChainFromBlockRequestMessage requests the virtual selected /// parent chain from some startHash to this kaspad's current virtual /// Note: -/// 1) this call batches the response to: +/// this call batches the response to: /// a. the network's `mergeset size limit * 10` amount of chain blocks, if `includeAcceptedTransactionIds = false` /// b. when the acceptance data queried exceeds the network's `mergeset size limit * 10` amount of merged blocks, if `includeAcceptedTransactionIds = true` -/// 2) if startHash is not supplied it will default to the node's source hash message GetVirtualChainFromBlockRequestMessage{ string startHash = 1; bool includeAcceptedTransactionIds = 2; From 32c75cd5b5ba5a36db27102edb915fa87a69b14d Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:00:47 +0200 Subject: [PATCH 23/26] only batch added chain blocks, not removed, add check if source is a chain ancestor of high. --- components/consensusmanager/src/session.rs | 4 ++-- consensus/core/src/api/mod.rs | 6 +++--- consensus/src/consensus/mod.rs | 14 +++++++++++--- consensus/src/processes/traversal_manager.rs | 9 ++++----- rpc/grpc/core/proto/rpc.proto | 5 +++-- rpc/service/src/service.rs | 17 ++++++++++------- 6 files changed, 33 insertions(+), 22 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index bc4864e8d..830c1c672 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -267,8 +267,8 @@ impl ConsensusSessionOwned { self.clone().spawn_blocking(|c| c.is_nearly_synced()).await } - pub async fn async_get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { - self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, limit)).await + pub async fn async_get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { + self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, chain_path_added_limit)).await } pub async fn async_get_virtual_utxos( diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index 08cfae76f..4daa7fe19 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -157,12 +157,12 @@ pub trait ConsensusApi: Send + Sync { unimplemented!() } - /// Gets the virtual chain paths from `low` to the `sink` hash, or until `limit`` is reached + /// Gets the virtual chain paths from `low` to the `sink` hash, or until `chain_path_added_limit` is reached /// /// Note: - /// 1) `limit` will populate removed and then the added chain path, up to the specified amount. + /// 1) `chain_path_added_limit` will populate removed fully, and then the added chain path, up to `chain_path_added_limit` amount of hashes. /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. - fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { + fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { unimplemented!() } diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 7f40c6483..6a4b4c56f 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -607,18 +607,26 @@ impl ConsensusApi for Consensus { self.config.is_nearly_synced(compact.timestamp, compact.daa_score) } - fn get_virtual_chain_from_block(&self, low: Hash, limit: usize) -> ConsensusResult { + fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { // Calculate chain changes between the given `low` and the current sink hash (up to `limit` amount of block hashes). // Note: // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. - // 2) supplying `usize::MAX` as `limit` will result in the full chain path, with optimized performance. + // 2) supplying `usize::MAX` as `chain_path_added_limit` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); + // Verify that the block exists self.validate_block_exists(low)?; - Ok(self.services.dag_traversal_manager.calculate_chain_path(low, self.get_sink(), limit)) + // Verify that source is on chain(block) self.services + self.services + .reachability_service + .is_chain_ancestor_of(self.get_source(), low) + .then_some(()) + .ok_or(ConsensusError::General("the queried hash does not have source on its chain"))?; + + Ok(self.services.dag_traversal_manager.calculate_chain_path(low, self.get_sink(), chain_path_added_limit)) } /// Returns a Vec of header samples since genesis diff --git a/consensus/src/processes/traversal_manager.rs b/consensus/src/processes/traversal_manager.rs index dc3373138..ff958242c 100644 --- a/consensus/src/processes/traversal_manager.rs +++ b/consensus/src/processes/traversal_manager.rs @@ -31,10 +31,10 @@ impl ChainPath { + pub fn calculate_chain_path(&self, from: Hash, to: Hash, chain_path_added_limit: usize) -> ChainPath { let mut removed = Vec::new(); let mut common_ancestor = from; - for current in self.reachability_service.default_backward_chain_iterator(from).take(max_traversal_allowed) { + for current in self.reachability_service.default_backward_chain_iterator(from) { if !self.reachability_service.is_chain_ancestor_of(current, to) { removed.push(current); } else { @@ -42,7 +42,7 @@ impl RpcResult { let session = self.consensus_manager.consensus().session().await; - // limit is set to 10 times the mergeset_size_limit. - // this means limit is 2480 on 10 bps, and 1800 on mainnet. + // batch_size is set to 10 times the mergeset_size_limit. + // this means batch_size is 2480 on 10 bps, and 1800 on mainnet. // this bounds by number of merged blocks, if include_accepted_transactions = true - // else it returns the limit amount on pure chain blocks. - let limit = (self.config.mergeset_size_limit * 10) as usize; - let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, limit).await?; + // else it returns the batch_size amount on pure chain blocks. + // Note: batch_size does not bound removed chain blocks, only added chain blocks. + let batch_size = (self.config.mergeset_size_limit * 10) as usize; + let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, batch_size).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { - let accepted_transaction_ids = - self.consensus_converter.get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, limit).await?; + let accepted_transaction_ids = self + .consensus_converter + .get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, batch_size) + .await?; // bound added to the length of the accepted transaction ids, which is bounded by merged blocks virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec(); accepted_transaction_ids From b74b17fb6c2b84a3ddacbda68fa059afc0657f04 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:06:19 +0200 Subject: [PATCH 24/26] remove dangling code in comment --- consensus/src/consensus/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 6a4b4c56f..72e34571c 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -619,7 +619,7 @@ impl ConsensusApi for Consensus { // Verify that the block exists self.validate_block_exists(low)?; - // Verify that source is on chain(block) self.services + // Verify that source is on chain(block) self.services .reachability_service .is_chain_ancestor_of(self.get_source(), low) From 65daaceb7439cb70f00c02381b0592c912cc2e85 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:08:18 +0200 Subject: [PATCH 25/26] remove error from some prev. commit. --- consensus/core/src/errors/consensus.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/consensus/core/src/errors/consensus.rs b/consensus/core/src/errors/consensus.rs index 57764282a..51d8b3f4d 100644 --- a/consensus/core/src/errors/consensus.rs +++ b/consensus/core/src/errors/consensus.rs @@ -17,9 +17,6 @@ pub enum ConsensusError { #[error("some data is missing for block {0}")] MissingData(Hash), - #[error("expected block: {0} to be an ancestor of block: {1}")] - ExpectedAncestor(Hash, Hash), - #[error("got unexpected pruning point")] UnexpectedPruningPoint, From 2eb647cd8397b95b36c1f946d728fc86b5ede034 Mon Sep 17 00:00:00 2001 From: D-Stacks <78099568+D-Stacks@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:31:13 +0200 Subject: [PATCH 26/26] Optionalize limts. --- components/consensusmanager/src/session.rs | 8 ++++++-- consensus/core/src/api/mod.rs | 10 +++++++--- consensus/src/consensus/mod.rs | 14 ++++++++++---- .../src/pipeline/virtual_processor/processor.rs | 2 +- consensus/src/processes/traversal_manager.rs | 6 +++--- rpc/service/src/converter/consensus.rs | 2 +- rpc/service/src/service.rs | 4 ++-- 7 files changed, 30 insertions(+), 16 deletions(-) diff --git a/components/consensusmanager/src/session.rs b/components/consensusmanager/src/session.rs index 830c1c672..2643739ee 100644 --- a/components/consensusmanager/src/session.rs +++ b/components/consensusmanager/src/session.rs @@ -267,7 +267,11 @@ impl ConsensusSessionOwned { self.clone().spawn_blocking(|c| c.is_nearly_synced()).await } - pub async fn async_get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { + pub async fn async_get_virtual_chain_from_block( + &self, + low: Hash, + chain_path_added_limit: Option, + ) -> ConsensusResult { self.clone().spawn_blocking(move |c| c.get_virtual_chain_from_block(low, chain_path_added_limit)).await } @@ -383,7 +387,7 @@ impl ConsensusSessionOwned { pub async fn async_get_blocks_acceptance_data( &self, hashes: Vec, - merged_blocks_limit: usize, + merged_blocks_limit: Option, ) -> ConsensusResult>> { self.clone().spawn_blocking(move |c| c.get_blocks_acceptance_data(&hashes, merged_blocks_limit)).await } diff --git a/consensus/core/src/api/mod.rs b/consensus/core/src/api/mod.rs index 4daa7fe19..91165b73d 100644 --- a/consensus/core/src/api/mod.rs +++ b/consensus/core/src/api/mod.rs @@ -161,8 +161,8 @@ pub trait ConsensusApi: Send + Sync { /// /// Note: /// 1) `chain_path_added_limit` will populate removed fully, and then the added chain path, up to `chain_path_added_limit` amount of hashes. - /// 1.1) use `usize::MAX` to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. - fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { + /// 1.1) use `None to impose no limit with optimized backward chain iteration, for better performance in cases where batching is not required. + fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: Option) -> ConsensusResult { unimplemented!() } @@ -302,7 +302,11 @@ pub trait ConsensusApi: Send + Sync { /// Returns acceptance data for a set of blocks belonging to the selected parent chain. /// /// See `self::get_virtual_chain` - fn get_blocks_acceptance_data(&self, hashes: &[Hash], merged_blocks_limit: usize) -> ConsensusResult>> { + fn get_blocks_acceptance_data( + &self, + hashes: &[Hash], + merged_blocks_limit: Option, + ) -> ConsensusResult>> { unimplemented!() } diff --git a/consensus/src/consensus/mod.rs b/consensus/src/consensus/mod.rs index 72e34571c..1731729a3 100644 --- a/consensus/src/consensus/mod.rs +++ b/consensus/src/consensus/mod.rs @@ -607,13 +607,13 @@ impl ConsensusApi for Consensus { self.config.is_nearly_synced(compact.timestamp, compact.daa_score) } - fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: usize) -> ConsensusResult { + fn get_virtual_chain_from_block(&self, low: Hash, chain_path_added_limit: Option) -> ConsensusResult { // Calculate chain changes between the given `low` and the current sink hash (up to `limit` amount of block hashes). // Note: // 1) that we explicitly don't // do the calculation against the virtual itself so that we // won't later need to remove it from the result. - // 2) supplying `usize::MAX` as `chain_path_added_limit` will result in the full chain path, with optimized performance. + // 2) supplying `None` as `chain_path_added_limit` will result in the full chain path, with optimized performance. let _guard = self.pruning_lock.blocking_read(); // Verify that the block exists @@ -926,17 +926,23 @@ impl ConsensusApi for Consensus { self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash)) } - fn get_blocks_acceptance_data(&self, hashes: &[Hash], merged_blocks_limit: usize) -> ConsensusResult>> { + fn get_blocks_acceptance_data( + &self, + hashes: &[Hash], + merged_blocks_limit: Option, + ) -> ConsensusResult>> { // Note: merged_blocks_limit will limit after the sum of merged blocks is breached along the supplied hash's acceptance data // and not limit the acceptance data within a queried hash. i.e. It has mergeset_size_limit granularity, this is to guarantee full acceptance data coverage. - if merged_blocks_limit == usize::MAX { + if merged_blocks_limit.is_none() { return hashes .iter() .copied() .map(|hash| self.acceptance_data_store.get(hash).unwrap_option().ok_or(ConsensusError::MissingData(hash))) .collect::>>(); } + let merged_blocks_limit = merged_blocks_limit.unwrap(); // we handle `is_none`, so may unwrap. let mut num_of_merged_blocks = 0usize; + hashes .iter() .copied() diff --git a/consensus/src/pipeline/virtual_processor/processor.rs b/consensus/src/pipeline/virtual_processor/processor.rs index d8cec5ff6..88fee97bf 100644 --- a/consensus/src/pipeline/virtual_processor/processor.rs +++ b/consensus/src/pipeline/virtual_processor/processor.rs @@ -290,7 +290,7 @@ impl VirtualStateProcessor { assert_eq!(virtual_ghostdag_data.selected_parent, new_sink); let sink_multiset = self.utxo_multisets_store.get(new_sink).unwrap(); - let chain_path = self.dag_traversal_manager.calculate_chain_path(prev_sink, new_sink, usize::MAX); + let chain_path = self.dag_traversal_manager.calculate_chain_path(prev_sink, new_sink, None); let new_virtual_state = self .calculate_and_commit_virtual_state( virtual_read, diff --git a/consensus/src/processes/traversal_manager.rs b/consensus/src/processes/traversal_manager.rs index ff958242c..23dc5c69f 100644 --- a/consensus/src/processes/traversal_manager.rs +++ b/consensus/src/processes/traversal_manager.rs @@ -31,7 +31,7 @@ impl ChainPath { + pub fn calculate_chain_path(&self, from: Hash, to: Hash, chain_path_added_limit: Option) -> ChainPath { let mut removed = Vec::new(); let mut common_ancestor = from; for current in self.reachability_service.default_backward_chain_iterator(from) { @@ -42,7 +42,7 @@ impl, ) -> RpcResult> { let acceptance_data = consensus.async_get_blocks_acceptance_data(chain_path.added.clone(), merged_blocks_limit).await.unwrap(); Ok(chain_path diff --git a/rpc/service/src/service.rs b/rpc/service/src/service.rs index 109e1496a..bdc2a9541 100644 --- a/rpc/service/src/service.rs +++ b/rpc/service/src/service.rs @@ -616,11 +616,11 @@ NOTE: This error usually indicates an RPC conversion error between the node and // else it returns the batch_size amount on pure chain blocks. // Note: batch_size does not bound removed chain blocks, only added chain blocks. let batch_size = (self.config.mergeset_size_limit * 10) as usize; - let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, batch_size).await?; + let mut virtual_chain_batch = session.async_get_virtual_chain_from_block(request.start_hash, Some(batch_size)).await?; let accepted_transaction_ids = if request.include_accepted_transaction_ids { let accepted_transaction_ids = self .consensus_converter - .get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, batch_size) + .get_virtual_chain_accepted_transaction_ids(&session, &virtual_chain_batch, Some(batch_size)) .await?; // bound added to the length of the accepted transaction ids, which is bounded by merged blocks virtual_chain_batch.added = virtual_chain_batch.added[..accepted_transaction_ids.len()].to_vec();