Skip to content

Commit

Permalink
fix edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Apr 11, 2023
1 parent 67db4b2 commit fa0746c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
15 changes: 14 additions & 1 deletion base_layer/core/src/base_node/rpc/sync_utxos_by_block_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ where B: BlockchainBackend + 'static
.fetch_utxos_in_block(current_header.hash(), Some(bitmap.clone()))
.await
.rpc_status_internal_error(LOG_TARGET)?;

let utxos = utxos
.into_iter()
.enumerate()
Expand All @@ -158,6 +157,7 @@ where B: BlockchainBackend + 'static
current_header.height,
current_header_hash.to_hex(),
);

for utxo_chunk in utxos.chunks(2000) {
let utxo_block_response = SyncUtxosByBlockResponse {
outputs: utxo_chunk.to_vec(),
Expand All @@ -170,6 +170,19 @@ where B: BlockchainBackend + 'static
break;
}
}
if utxos.is_empty() {
// if its empty, we need to send an empty vec of outputs.
let utxo_block_response = SyncUtxosByBlockResponse {
outputs: utxos,
height: current_header.height,
header_hash: current_header_hash.to_vec(),
mined_timestamp: current_header.timestamp.as_u64(),
};
// Ensure task stops if the peer prematurely stops their RPC session
if tx.send(Ok(utxo_block_response)).await.is_err() {
break;
}
}

debug!(
target: LOG_TARGET,
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/tests/base_node_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ async fn test_sync_utxos_by_block() {
let mut streaming = service.sync_utxos_by_block(req).await.unwrap().into_inner();

let responses = convert_mpsc_to_stream(&mut streaming).collect::<Vec<_>>().await;

// dbg!(&block0);
assert_eq!(
vec![
(0, block0.header().hash().to_vec(), 0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,14 @@ where
timestamp: Utc::now().naive_utc(),
});
}
// We need to update the last one
if let Some(scanned_block) = prev_scanned_block {
self.resources.db.clear_scanned_blocks_before_height(
scanned_block.height.saturating_sub(SCANNED_BLOCK_CACHE_SIZE),
true,
)?;
self.resources.db.save_scanned_block(scanned_block)?;
}
trace!(
target: LOG_TARGET,
"bulletproof rewind profile - streamed {} outputs in {} ms",
Expand Down

0 comments on commit fa0746c

Please sign in to comment.