Skip to content

Commit

Permalink
Handle legacy virtual hash in EstimateNetworkHashesPerSecond RPC me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
tiram88 committed Oct 27, 2023
1 parent e15b070 commit 6fb728c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rpc/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kaspa-math.workspace = true
kaspa-utxoindex.workspace = true
kaspa-wrpc-core.workspace = true
kaspa-perf-monitor.workspace = true
kaspa-hashes.workspace = true

log.workspace = true
async-trait.workspace = true
Expand Down
13 changes: 12 additions & 1 deletion rpc/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,12 +556,23 @@ impl RpcApi for RpcCoreService {
if request.window_size as u64 > self.config.pruning_depth {
return Err(RpcError::WindowSizeExceedingPruningDepth(request.window_size, self.config.pruning_depth));
}

// In the previous golang implementation the convention for virtual was the following const.
// In the current implementation, consensus behaves the same when it gets a None instead.
const LEGACY_VIRTUAL: kaspa_hashes::Hash = kaspa_hashes::Hash::from_bytes([0xff; kaspa_hashes::HASH_SIZE]);
let mut start_hash = request.start_hash;
if let Some(start) = start_hash {
if start == LEGACY_VIRTUAL {
start_hash = None;
}
}

Ok(EstimateNetworkHashesPerSecondResponse::new(
self.consensus_manager
.consensus()
.session()
.await
.async_estimate_network_hashes_per_second(request.start_hash, request.window_size as usize)
.async_estimate_network_hashes_per_second(start_hash, request.window_size as usize)
.await?,
))
}
Expand Down

0 comments on commit 6fb728c

Please sign in to comment.