From f439d24aa43435c46d14bc4407752a2f2dacd08d Mon Sep 17 00:00:00 2001 From: jorgeantonio21 Date: Mon, 14 Nov 2022 19:26:44 +0000 Subject: [PATCH] uncomplete work --- base_layer/core/src/base_node/rpc/service.rs | 27 +++++++++++++++++++ .../utxo_scanner_service/utxo_scanner_task.rs | 9 +++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/base_layer/core/src/base_node/rpc/service.rs b/base_layer/core/src/base_node/rpc/service.rs index 042f291d7b8..bab863d142b 100644 --- a/base_layer/core/src/base_node/rpc/service.rs +++ b/base_layer/core/src/base_node/rpc/service.rs @@ -545,6 +545,32 @@ impl BaseNodeWalletService for BaseNodeWalletRpc async fn get_height_at_time(&self, request: Request) -> Result, RpcStatus> { let requested_epoch_time: u64 = request.into_message(); + dbg!("FLAG0: the requested epoch time = {}", requested_epoch_time); + + let zero_header = self + .db() + .fetch_header(0u64) + .await + .rpc_status_internal_error(LOG_TARGET)? + .ok_or_else(|| RpcStatus::not_found(&format!("Header not found during search at height {}", 0u64)))?; + + dbg!( + "FLAG1: the zero height block timestamp is: {}", + zero_header.timestamp.as_u64() + ); + + let one_header = self + .db() + .fetch_header(1u64) + .await + .rpc_status_internal_error(LOG_TARGET)? + .ok_or_else(|| RpcStatus::not_found(&format!("Header not found during search at height {}", 1u64)))?; + + dbg!( + "FLAG2: the one height block timestamp is: {}", + one_header.timestamp.as_u64() + ); + let tip_header = self .db() .fetch_tip_header() @@ -554,6 +580,7 @@ impl BaseNodeWalletService for BaseNodeWalletRpc let mut right_height = tip_header.height(); while left_height <= right_height { + dbg!("FLAG1: the right_height is: {}", right_height); let mut mid_height = (left_height + right_height) / 2; if mid_height == 0 { diff --git a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs index a1c9d193628..689aad1b01e 100644 --- a/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs +++ b/base_layer/wallet/src/utxo_scanner_service/utxo_scanner_task.rs @@ -66,6 +66,7 @@ use crate::{ }, }; +pub const BIRTHDAY_GENESIS_FROM_UNIX_EPOCH: u64 = 1640995200; // seconds since 2022-01-01 00:00:00 UTC pub const LOG_TARGET: &str = "wallet::utxo_scanning"; pub struct UtxoScannerTask { @@ -325,11 +326,7 @@ where client: &mut BaseNodeWalletRpcClient, ) -> Result { let tip_info = client.get_tip_info().await?; - let wallet_birthday_height = self.get_birthday_header_height_hash(client).await?.height; - let chain_height = tip_info - .metadata - .map(|m| m.height_of_longest_chain()) - .unwrap_or(wallet_birthday_height); + let chain_height = tip_info.metadata.map(|m| m.height_of_longest_chain()).unwrap_or(0); let end_header = client.get_header_by_height(chain_height).await?; let end_header = BlockHeader::try_from(end_header).map_err(UtxoScannerError::ConversionError)?; @@ -706,6 +703,8 @@ where // Calculate the unix epoch time of two days before the wallet birthday. This is to avoid any weird time zone // issues let epoch_time = u64::from(birthday.saturating_sub(2)) * 60 * 60 * 24; + // add the elapsed seconds from Unix epoch, to be consistent with block timestamps + let epoch_time = epoch_time + BIRTHDAY_GENESIS_FROM_UNIX_EPOCH; let block_height = match client.get_height_at_time(epoch_time).await { Ok(b) => b, Err(e) => {