From 1482178dadf89651ea7384ab06f68490ef8624c8 Mon Sep 17 00:00:00 2001 From: brianp Date: Fri, 6 Oct 2023 13:16:13 +0200 Subject: [PATCH] Remove proto bytes for std bytes --- .../chain_metadata_service/service.rs | 4 +- .../src/base_node/proto/chain_metadata.proto | 2 +- .../src/base_node/proto/chain_metadata.rs | 7 ++- .../core/src/base_node/proto/wallet_rpc.proto | 8 ++-- .../core/src/base_node/proto/wallet_rpc.rs | 35 ++++++++------ base_layer/core/src/base_node/rpc/service.rs | 13 +++--- .../tasks/txo_validation_task.rs | 2 +- .../transaction_validation_protocol.rs | 7 ++- base_layer/wallet/tests/support/comms_rpc.rs | 10 ++-- .../transaction_service_tests/service.rs | 32 ++++++------- .../transaction_protocols.rs | 46 +++++++++---------- base_layer/wallet/tests/utxo_scanner/mod.rs | 30 ++++++------ 12 files changed, 102 insertions(+), 94 deletions(-) diff --git a/base_layer/core/src/base_node/chain_metadata_service/service.rs b/base_layer/core/src/base_node/chain_metadata_service/service.rs index dc33240737..6c46e26312 100644 --- a/base_layer/core/src/base_node/chain_metadata_service/service.rs +++ b/base_layer/core/src/base_node/chain_metadata_service/service.rs @@ -245,10 +245,10 @@ mod test { let diff: u128 = 1; proto::ChainMetadata { height_of_longest_chain: Some(1), - best_block: Some(vec![ + best_block: vec![ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - ]), + ], pruned_height: 0, accumulated_difficulty: diff.to_be_bytes().to_vec(), timestamp: Some(0), diff --git a/base_layer/core/src/base_node/proto/chain_metadata.proto b/base_layer/core/src/base_node/proto/chain_metadata.proto index 6acde5f455..10f9b5a82f 100644 --- a/base_layer/core/src/base_node/proto/chain_metadata.proto +++ b/base_layer/core/src/base_node/proto/chain_metadata.proto @@ -11,7 +11,7 @@ message ChainMetadata { // The current chain height, or the block number of the longest valid chain, or `None` if there is no chain google.protobuf.UInt64Value height_of_longest_chain = 1; // The block hash of the current tip of the longest valid chain, or `None` for an empty chain - google.protobuf.BytesValue best_block = 2; + bytes best_block = 2; // The current geometric mean of the pow of the chain tip, or `None` if there is no chain bytes accumulated_difficulty = 5; // The effective height of the pruning horizon. This indicates from what height diff --git a/base_layer/core/src/base_node/proto/chain_metadata.rs b/base_layer/core/src/base_node/proto/chain_metadata.rs index 7a84a66c75..3e56b4de16 100644 --- a/base_layer/core/src/base_node/proto/chain_metadata.rs +++ b/base_layer/core/src/base_node/proto/chain_metadata.rs @@ -53,9 +53,12 @@ impl TryFrom for ChainMetadata { } else { height_of_longest_chain.saturating_sub(metadata.pruned_height) }; + + if metadata.best_block.is_empty() { + return Err("Best block is missing".to_string()); + } let hash: FixedHash = metadata .best_block - .ok_or_else(|| "Best block is missing".to_string())? .try_into() .map_err(|e| format!("Malformed best block: {}", e))?; Ok(ChainMetadata::new( @@ -74,7 +77,7 @@ impl From for proto::ChainMetadata { let accumulated_difficulty = metadata.accumulated_difficulty().to_be_bytes().to_vec(); Self { height_of_longest_chain: Some(metadata.height_of_longest_chain()), - best_block: Some(metadata.best_block().to_vec()), + best_block: metadata.best_block().to_vec(), pruned_height: metadata.pruned_height(), accumulated_difficulty, timestamp: Some(metadata.timestamp()), diff --git a/base_layer/core/src/base_node/proto/wallet_rpc.proto b/base_layer/core/src/base_node/proto/wallet_rpc.proto index 2578f34b65..e0792847fa 100644 --- a/base_layer/core/src/base_node/proto/wallet_rpc.proto +++ b/base_layer/core/src/base_node/proto/wallet_rpc.proto @@ -35,7 +35,7 @@ enum TxLocation { message TxQueryResponse { TxLocation location = 1; - google.protobuf.BytesValue block_hash = 2; + bytes block_hash = 2; uint64 confirmations = 3; bool is_synced = 4; uint64 height_of_longest_chain = 5; @@ -45,7 +45,7 @@ message TxQueryResponse { message TxQueryBatchResponse { tari.types.Signature signature = 1; TxLocation location = 2; - google.protobuf.BytesValue block_hash = 3; + bytes block_hash = 3; uint64 confirmations = 4; uint64 block_height = 5; google.protobuf.UInt64Value mined_timestamp = 6; @@ -54,7 +54,7 @@ message TxQueryBatchResponse { message TxQueryBatchResponses { repeated TxQueryBatchResponse responses = 1; bool is_synced = 2; - google.protobuf.BytesValue tip_hash = 3; + bytes tip_hash = 3; uint64 height_of_longest_chain = 4; google.protobuf.UInt64Value tip_mined_timestamp = 5; } @@ -70,7 +70,7 @@ message FetchUtxosResponse { message QueryDeletedRequest { repeated uint64 mmr_positions = 1; - google.protobuf.BytesValue chain_must_include_header = 2; + bytes chain_must_include_header = 2; bool include_deleted_block_data = 3; } diff --git a/base_layer/core/src/base_node/proto/wallet_rpc.rs b/base_layer/core/src/base_node/proto/wallet_rpc.rs index be9729e401..5af9ac4848 100644 --- a/base_layer/core/src/base_node/proto/wallet_rpc.rs +++ b/base_layer/core/src/base_node/proto/wallet_rpc.rs @@ -21,12 +21,13 @@ // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. use std::{ - convert::{TryFrom, TryInto}, + convert::TryFrom, fmt::{Display, Error, Formatter}, }; use serde::{Deserialize, Serialize}; use tari_common_types::types::{BlockHash, Signature}; +use tari_utilities::ByteArray; use crate::proto::{base_node as proto, types}; @@ -191,12 +192,15 @@ impl TryFrom for TxQueryResponse { type Error = String; fn try_from(proto_response: proto::TxQueryResponse) -> Result { - let hash = match proto_response.block_hash { - Some(v) => match v.try_into() { - Ok(v) => Some(v), - Err(e) => return Err(format!("Malformed block hash: {}", e)), - }, - None => None, + let hash = if proto_response.block_hash.is_empty() { + None + } else { + Some(match BlockHash::try_from(proto_response.block_hash.clone()) { + Ok(h) => h, + Err(e) => { + return Err(format!("Malformed block hash: {}", e)); + }, + }) }; Ok(Self { location: TxLocation::try_from( @@ -216,7 +220,7 @@ impl From for proto::TxQueryResponse { fn from(response: TxQueryResponse) -> Self { Self { location: proto::TxLocation::from(response.location) as i32, - block_hash: response.block_hash.map(|v| v.to_vec()), + block_hash: response.block_hash.map(|v| v.to_vec()).unwrap_or(vec![]), confirmations: response.confirmations, is_synced: response.is_synced, height_of_longest_chain: response.height_of_longest_chain, @@ -229,12 +233,15 @@ impl TryFrom for TxQueryBatchResponse { type Error = String; fn try_from(proto_response: proto::TxQueryBatchResponse) -> Result { - let hash = match proto_response.block_hash { - Some(v) => match v.try_into() { - Ok(v) => Some(v), - Err(e) => return Err(format!("Malformed block hash: {}", e)), - }, - None => None, + let hash = if proto_response.block_hash.is_empty() { + None + } else { + Some(match BlockHash::try_from(proto_response.block_hash.clone()) { + Ok(h) => h, + Err(e) => { + return Err(format!("Malformed block hash: {}", e)); + }, + }) }; Ok(Self { signature: Signature::try_from( diff --git a/base_layer/core/src/base_node/rpc/service.rs b/base_layer/core/src/base_node/rpc/service.rs index 8624c1da4d..3172e21e5b 100644 --- a/base_layer/core/src/base_node/rpc/service.rs +++ b/base_layer/core/src/base_node/rpc/service.rs @@ -125,7 +125,7 @@ impl BaseNodeWalletRpcService { let confirmations = chain_metadata.height_of_longest_chain().saturating_sub(header.height); let response = TxQueryResponse { location: TxLocation::Mined as i32, - block_hash: Some(block_hash.to_vec()), + block_hash: block_hash.to_vec(), confirmations, is_synced, height_of_longest_chain: chain_metadata.height_of_longest_chain(), @@ -146,7 +146,7 @@ impl BaseNodeWalletRpcService { { TxStorageResponse::UnconfirmedPool => TxQueryResponse { location: TxLocation::InMempool as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, is_synced, height_of_longest_chain: chain_metadata.height_of_longest_chain(), @@ -161,7 +161,7 @@ impl BaseNodeWalletRpcService { TxStorageResponse::NotStoredFeeTooLow | TxStorageResponse::NotStoredAlreadyMined => TxQueryResponse { location: TxLocation::NotStored as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, is_synced, height_of_longest_chain: chain_metadata.height_of_longest_chain(), @@ -318,7 +318,7 @@ impl BaseNodeWalletService for BaseNodeWalletRpc Ok(Response::new(TxQueryBatchResponses { responses, is_synced, - tip_hash: Some(metadata.best_block().to_vec()), + tip_hash: metadata.best_block().to_vec(), height_of_longest_chain: metadata.height_of_longest_chain(), tip_mined_timestamp: Some(metadata.timestamp()), })) @@ -458,8 +458,9 @@ impl BaseNodeWalletService for BaseNodeWalletRpc ) -> Result, RpcStatus> { let message = request.into_message(); - if let Some(chain_must_include_header) = message.chain_must_include_header { - let hash = chain_must_include_header + if !message.chain_must_include_header.is_empty() { + let hash = message + .chain_must_include_header .try_into() .map_err(|_| RpcStatus::bad_request(&"Malformed block hash received".to_string()))?; if self diff --git a/base_layer/wallet/src/output_manager_service/tasks/txo_validation_task.rs b/base_layer/wallet/src/output_manager_service/tasks/txo_validation_task.rs index c58e016dd7..1291cb6641 100644 --- a/base_layer/wallet/src/output_manager_service/tasks/txo_validation_task.rs +++ b/base_layer/wallet/src/output_manager_service/tasks/txo_validation_task.rs @@ -206,7 +206,7 @@ where // This assumes that the base node has not reorged since the last time we asked. let deleted_bitmap_response = wallet_client .query_deleted(QueryDeletedRequest { - chain_must_include_header: last_mined_header_hash.map(|v| v.to_vec()), + chain_must_include_header: last_mined_header_hash.map(|v| v.to_vec()).unwrap_or_default(), mmr_positions: batch.iter().filter_map(|ub| ub.mined_mmr_position).collect(), include_deleted_block_data: true, }) diff --git a/base_layer/wallet/src/transaction_service/protocols/transaction_validation_protocol.rs b/base_layer/wallet/src/transaction_service/protocols/transaction_validation_protocol.rs index 235f778e90..ace948adb5 100644 --- a/base_layer/wallet/src/transaction_service/protocols/transaction_validation_protocol.rs +++ b/base_layer/wallet/src/transaction_service/protocols/transaction_validation_protocol.rs @@ -341,10 +341,9 @@ where } } } - let tip = batch_response - .tip_hash - .ok_or_else(|| TransactionServiceError::ProtobufConversionError("Missing `tip_hash` field".to_string()))? - .try_into()?; + + let tip = batch_response.tip_hash.try_into()?; + Ok(( mined, unmined, diff --git a/base_layer/wallet/tests/support/comms_rpc.rs b/base_layer/wallet/tests/support/comms_rpc.rs index 4a06a1e491..82ea00410c 100644 --- a/base_layer/wallet/tests/support/comms_rpc.rs +++ b/base_layer/wallet/tests/support/comms_rpc.rs @@ -31,7 +31,7 @@ use std::{ time::{Duration, Instant}, }; -use tari_common_types::types::{HashOutput, Signature}; +use tari_common_types::types::{FixedHash, HashOutput, Signature}; use tari_comms::{ protocol::rpc::{NamedProtocolService, Request, Response, RpcClient, RpcStatus, Streaming}, PeerConnection, @@ -141,7 +141,7 @@ impl BaseNodeWalletRpcMockState { })), transaction_query_batch_response: Arc::new(Mutex::new(TxQueryBatchResponsesProto { responses: vec![], - tip_hash: Some(vec![]), + tip_hash: FixedHash::zero().to_vec(), is_synced: true, height_of_longest_chain: 0, tip_mined_timestamp: Some(0), @@ -149,7 +149,7 @@ impl BaseNodeWalletRpcMockState { tip_info_response: Arc::new(Mutex::new(TipInfoResponse { metadata: Some(ChainMetadataProto { height_of_longest_chain: Some(std::i64::MAX as u64), - best_block: Some(Vec::new()), + best_block: FixedHash::zero().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -932,8 +932,8 @@ mod test { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(444), - best_block: Some(Vec::new()), - accumulated_difficulty: Vec::new(), + best_block: vec![], + accumulated_difficulty: vec![], pruned_height: 0, timestamp: Some(0), }; diff --git a/base_layer/wallet/tests/transaction_service_tests/service.rs b/base_layer/wallet/tests/transaction_service_tests/service.rs index a057900ced..b2af430060 100644 --- a/base_layer/wallet/tests/transaction_service_tests/service.rs +++ b/base_layer/wallet/tests/transaction_service_tests/service.rs @@ -3777,7 +3777,7 @@ async fn test_coinbase_generation_and_monitoring() { tx1.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -3787,7 +3787,7 @@ async fn test_coinbase_generation_and_monitoring() { tx2b.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&1).unwrap().hash().to_vec()), + block_hash: block_headers.get(&1).unwrap().hash().to_vec(), confirmations: 0, block_height: 1, mined_timestamp: Some(0), @@ -3796,7 +3796,7 @@ async fn test_coinbase_generation_and_monitoring() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some(block_headers.get(&1).unwrap().hash().to_vec()), + tip_hash: block_headers.get(&1).unwrap().hash().to_vec(), height_of_longest_chain: 1, tip_mined_timestamp: Some(0), }; @@ -3838,7 +3838,7 @@ async fn test_coinbase_generation_and_monitoring() { tx2b.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&4).unwrap().hash().to_vec()), + block_hash: block_headers.get(&4).unwrap().hash().to_vec(), confirmations: 3, block_height: 4, mined_timestamp: Some(0), @@ -3847,7 +3847,7 @@ async fn test_coinbase_generation_and_monitoring() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses, is_synced: true, - tip_hash: Some(block_headers.get(&4).unwrap().hash().to_vec()), + tip_hash: block_headers.get(&4).unwrap().hash().to_vec(), height_of_longest_chain: 4, tip_mined_timestamp: Some(0), }; @@ -3921,7 +3921,7 @@ async fn test_coinbase_abandoned() { let transaction_query_batch_responses = vec![TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx1.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::InMempool) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -3930,7 +3930,7 @@ async fn test_coinbase_abandoned() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses, is_synced: true, - tip_hash: Some([5u8; 32].to_vec()), + tip_hash: [5u8; 32].to_vec(), height_of_longest_chain: block_height_a + TransactionServiceConfig::default().num_confirmations_required + 1, tip_mined_timestamp: Some(0), }; @@ -4046,7 +4046,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx1.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -4054,7 +4054,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx2.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some([11u8; 32].to_vec()), + block_hash: [11u8; 32].to_vec(), confirmations: 2, block_height: block_height_b, mined_timestamp: Some(0), @@ -4064,7 +4064,7 @@ async fn test_coinbase_abandoned() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses, is_synced: true, - tip_hash: Some([13u8; 32].to_vec()), + tip_hash: [13u8; 32].to_vec(), height_of_longest_chain: block_height_b + 2, tip_mined_timestamp: Some(0), }; @@ -4132,7 +4132,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx1.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -4140,7 +4140,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx2.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -4150,7 +4150,7 @@ async fn test_coinbase_abandoned() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses, is_synced: true, - tip_hash: Some([12u8; 32].to_vec()), + tip_hash: [12u8; 32].to_vec(), height_of_longest_chain: block_height_b + TransactionServiceConfig::default().num_confirmations_required + 1, tip_mined_timestamp: Some(0), }; @@ -4249,7 +4249,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx1.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -4257,7 +4257,7 @@ async fn test_coinbase_abandoned() { TxQueryBatchResponseProto { signature: Some(SignatureProto::from(tx2.first_kernel_excess_sig().unwrap().clone())), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&10).unwrap().hash().to_vec()), + block_hash: block_headers.get(&10).unwrap().hash().to_vec(), confirmations: 5, block_height: 10, mined_timestamp: Some(0), @@ -4267,7 +4267,7 @@ async fn test_coinbase_abandoned() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses, is_synced: true, - tip_hash: Some([20u8; 32].to_vec()), + tip_hash: [20u8; 32].to_vec(), height_of_longest_chain: 20, tip_mined_timestamp: Some(0), }; diff --git a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs index dbd0bb3d8d..db32643f06 100644 --- a/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs +++ b/base_layer/wallet/tests/transaction_service_tests/transaction_protocols.rs @@ -785,7 +785,7 @@ async fn tx_validation_protocol_tx_becomes_mined_unconfirmed_then_confirmed() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some([1u8; 32].to_vec()), + block_hash: [1u8; 32].to_vec(), confirmations: 0, block_height: 1, mined_timestamp: Some(0), @@ -794,7 +794,7 @@ async fn tx_validation_protocol_tx_becomes_mined_unconfirmed_then_confirmed() { let mut batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some([1u8; 32].to_vec()), + tip_hash: [1u8; 32].to_vec(), height_of_longest_chain: 1, tip_mined_timestamp: Some(0), }; @@ -859,7 +859,7 @@ async fn tx_validation_protocol_tx_becomes_mined_unconfirmed_then_confirmed() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some([5u8; 32].to_vec()), + block_hash: [5u8; 32].to_vec(), confirmations: 4, block_height: 5, mined_timestamp: Some(0), @@ -868,7 +868,7 @@ async fn tx_validation_protocol_tx_becomes_mined_unconfirmed_then_confirmed() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some([5u8; 32].to_vec()), + tip_hash: [5u8; 32].to_vec(), height_of_longest_chain: 5, tip_mined_timestamp: Some(0), }; @@ -942,7 +942,7 @@ async fn tx_revalidation() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some([5u8; 32].to_vec()), + block_hash: [5u8; 32].to_vec(), confirmations: 4, block_height: 5, mined_timestamp: Some(0), @@ -951,7 +951,7 @@ async fn tx_revalidation() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some([5u8; 32].to_vec()), + tip_hash: [5u8; 32].to_vec(), height_of_longest_chain: 5, tip_mined_timestamp: Some(0), }; @@ -984,7 +984,7 @@ async fn tx_revalidation() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some([5u8; 32].to_vec()), + block_hash: [5u8; 32].to_vec(), confirmations: 8, block_height: 10, mined_timestamp: Some(0), @@ -993,7 +993,7 @@ async fn tx_revalidation() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some([5u8; 32].to_vec()), + tip_hash: [5u8; 32].to_vec(), height_of_longest_chain: 10, tip_mined_timestamp: Some(0), }; @@ -1104,7 +1104,7 @@ async fn tx_validation_protocol_reorg() { tx1.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&5).unwrap().hash().to_vec()), + block_hash: block_headers.get(&5).unwrap().hash().to_vec(), confirmations: 5, block_height: 5, mined_timestamp: Some(0), @@ -1114,7 +1114,7 @@ async fn tx_validation_protocol_reorg() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&6).unwrap().hash().to_vec()), + block_hash: block_headers.get(&6).unwrap().hash().to_vec(), confirmations: 4, block_height: 6, mined_timestamp: Some(0), @@ -1124,7 +1124,7 @@ async fn tx_validation_protocol_reorg() { tx3.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&7).unwrap().hash().to_vec()), + block_hash: block_headers.get(&7).unwrap().hash().to_vec(), confirmations: 3, block_height: 7, mined_timestamp: Some(0), @@ -1134,7 +1134,7 @@ async fn tx_validation_protocol_reorg() { tx4.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&8).unwrap().hash().to_vec()), + block_hash: block_headers.get(&8).unwrap().hash().to_vec(), confirmations: 2, block_height: 8, mined_timestamp: Some(0), @@ -1144,7 +1144,7 @@ async fn tx_validation_protocol_reorg() { coinbase_tx1.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&8).unwrap().hash().to_vec()), + block_hash: block_headers.get(&8).unwrap().hash().to_vec(), confirmations: 2, block_height: 8, mined_timestamp: Some(0), @@ -1154,7 +1154,7 @@ async fn tx_validation_protocol_reorg() { tx5.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&9).unwrap().hash().to_vec()), + block_hash: block_headers.get(&9).unwrap().hash().to_vec(), confirmations: 1, block_height: 9, mined_timestamp: Some(0), @@ -1164,7 +1164,7 @@ async fn tx_validation_protocol_reorg() { coinbase_tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&9).unwrap().hash().to_vec()), + block_hash: block_headers.get(&9).unwrap().hash().to_vec(), confirmations: 1, block_height: 9, mined_timestamp: Some(0), @@ -1174,7 +1174,7 @@ async fn tx_validation_protocol_reorg() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some(block_headers.get(&10).unwrap().hash().to_vec()), + tip_hash: block_headers.get(&10).unwrap().hash().to_vec(), height_of_longest_chain: 10, tip_mined_timestamp: Some(0), }; @@ -1225,7 +1225,7 @@ async fn tx_validation_protocol_reorg() { tx1.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&5).unwrap().hash().to_vec()), + block_hash: block_headers.get(&5).unwrap().hash().to_vec(), confirmations: 4, block_height: 5, mined_timestamp: Some(0), @@ -1235,7 +1235,7 @@ async fn tx_validation_protocol_reorg() { tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&6).unwrap().hash().to_vec()), + block_hash: block_headers.get(&6).unwrap().hash().to_vec(), confirmations: 3, block_height: 6, mined_timestamp: Some(0), @@ -1245,7 +1245,7 @@ async fn tx_validation_protocol_reorg() { tx3.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&7).unwrap().hash().to_vec()), + block_hash: block_headers.get(&7).unwrap().hash().to_vec(), confirmations: 2, block_height: 7, mined_timestamp: Some(0), @@ -1255,7 +1255,7 @@ async fn tx_validation_protocol_reorg() { coinbase_tx1.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -1265,7 +1265,7 @@ async fn tx_validation_protocol_reorg() { tx5.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::Mined) as i32, - block_hash: Some(block_headers.get(&8).unwrap().hash().to_vec()), + block_hash: block_headers.get(&8).unwrap().hash().to_vec(), confirmations: 1, block_height: 8, mined_timestamp: Some(0), @@ -1275,7 +1275,7 @@ async fn tx_validation_protocol_reorg() { coinbase_tx2.transaction.first_kernel_excess_sig().unwrap().clone(), )), location: TxLocationProto::from(TxLocation::NotStored) as i32, - block_hash: None, + block_hash: vec![], confirmations: 0, block_height: 0, mined_timestamp: None, @@ -1285,7 +1285,7 @@ async fn tx_validation_protocol_reorg() { let batch_query_response = TxQueryBatchResponsesProto { responses: transaction_query_batch_responses.clone(), is_synced: true, - tip_hash: Some(block_headers.get(&8).unwrap().hash().to_vec()), + tip_hash: block_headers.get(&8).unwrap().hash().to_vec(), height_of_longest_chain: 8, tip_mined_timestamp: Some(0), }; diff --git a/base_layer/wallet/tests/utxo_scanner/mod.rs b/base_layer/wallet/tests/utxo_scanner/mod.rs index e4b3f289a2..09f2929bac 100644 --- a/base_layer/wallet/tests/utxo_scanner/mod.rs +++ b/base_layer/wallet/tests/utxo_scanner/mod.rs @@ -314,7 +314,7 @@ async fn test_utxo_scanner_recovery() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS - 1), - best_block: Some(block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -413,7 +413,7 @@ async fn test_utxo_scanner_recovery_with_restart() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS - 1), - best_block: Some(block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -579,7 +579,7 @@ async fn test_utxo_scanner_recovery_with_restart_and_reorg() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS - 1), - best_block: Some(block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -652,7 +652,7 @@ async fn test_utxo_scanner_recovery_with_restart_and_reorg() { test_interface2.rpc_service_state.set_blocks(block_headers.clone()); let chain_metadata = ChainMetadata { height_of_longest_chain: Some(9), - best_block: Some(block_headers.get(&9).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&9).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -777,14 +777,12 @@ async fn test_utxo_scanner_scanned_block_cache_clearing() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(800 + NUM_BLOCKS - 1), - best_block: Some( - block_headers - .get(&(800 + NUM_BLOCKS - 1)) - .unwrap() - .clone() - .hash() - .to_vec(), - ), + best_block: block_headers + .get(&(800 + NUM_BLOCKS - 1)) + .unwrap() + .clone() + .hash() + .to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -881,7 +879,7 @@ async fn test_utxo_scanner_one_sided_payments() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS - 1), - best_block: Some(block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -1001,7 +999,7 @@ async fn test_utxo_scanner_one_sided_payments() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS), - best_block: Some(block_headers.get(&(NUM_BLOCKS)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0), @@ -1016,7 +1014,7 @@ async fn test_utxo_scanner_one_sided_payments() { test_interface .base_node_service_event_publisher .send(Arc::new(BaseNodeEvent::NewBlockDetected( - chain_metadata.best_block.as_ref().cloned().unwrap().try_into().unwrap(), + chain_metadata.best_block.try_into().unwrap(), 11, ))) .unwrap(); @@ -1088,7 +1086,7 @@ async fn test_birthday_timestamp_over_chain() { let chain_metadata = ChainMetadata { height_of_longest_chain: Some(NUM_BLOCKS - 1), - best_block: Some(block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec()), + best_block: block_headers.get(&(NUM_BLOCKS - 1)).unwrap().clone().hash().to_vec(), accumulated_difficulty: Vec::new(), pruned_height: 0, timestamp: Some(0),