From 107b362ddd8c2d731f46e3ed79c25f93132f1aed Mon Sep 17 00:00:00 2001 From: viquezclaudio Date: Fri, 22 Nov 2024 12:22:51 -0600 Subject: [PATCH] Pre-genesis flag when requesting txns by address Use the appropiate services flag when transactions from the PoW chain are required from a specific address --- consensus/src/consensus/consensus_proxy.rs | 13 +++++++++---- consensus/tests/consensus_proxy.rs | 8 +++++++- web-client/src/client/lib.rs | 11 ++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/consensus/src/consensus/consensus_proxy.rs b/consensus/src/consensus/consensus_proxy.rs index 605677c2ad..d9ca86de4a 100644 --- a/consensus/src/consensus/consensus_proxy.rs +++ b/consensus/src/consensus/consensus_proxy.rs @@ -105,14 +105,19 @@ impl ConsensusProxy { min_peers: usize, max: Option, start_at: Option, + include_pre_genesis: bool, ) -> Result, RequestError> { let mut obtained_receipts = HashSet::new(); + // If we need to include pre-genesis data, we set the appropiate services flag + let services = if include_pre_genesis { + Services::PRE_GENESIS_TRANSACTIONS | Services::TRANSACTION_INDEX + } else { + Services::TRANSACTION_INDEX + }; + // We obtain a list of connected peers that could satisfy our request and perform the request to each one: - for peer_id in self - .get_peers_for_service(Services::TRANSACTION_INDEX, min_peers) - .await? - { + for peer_id in self.get_peers_for_service(services, min_peers).await? { log::debug!( peer_id = %peer_id, "Performing txn receipts by address request to peer", diff --git a/consensus/tests/consensus_proxy.rs b/consensus/tests/consensus_proxy.rs index bbf7549791..dd4d6886cd 100644 --- a/consensus/tests/consensus_proxy.rs +++ b/consensus/tests/consensus_proxy.rs @@ -92,7 +92,13 @@ async fn test_request_transactions_by_address() { let key_pair = KeyPair::from(PrivateKey::from_str(REWARD_KEY).unwrap()); let receipts = consensus_proxy - .request_transaction_receipts_by_address(Address::from(&key_pair.public), 1, None, None) + .request_transaction_receipts_by_address( + Address::from(&key_pair.public), + 1, + None, + None, + false, + ) .await; assert!(receipts.is_ok()); let res = consensus_proxy diff --git a/web-client/src/client/lib.rs b/web-client/src/client/lib.rs index cd5807227e..dda4910005 100644 --- a/web-client/src/client/lib.rs +++ b/web-client/src/client/lib.rs @@ -700,6 +700,7 @@ impl Client { min_peers.unwrap_or(1), limit, start_at, + true, ) .await?; @@ -772,11 +773,19 @@ impl Client { } } + let include_pre_genesis = since_block_height < Policy::genesis_block_number(); + // Fetch transaction receipts. let receipts: HashMap<_, _> = self .inner .consensus_proxy() - .request_transaction_receipts_by_address(address, min_peers, limit, start_at) + .request_transaction_receipts_by_address( + address, + min_peers, + limit, + start_at, + include_pre_genesis, + ) .await? .into_iter() .collect();