Skip to content

Commit

Permalink
Pre-genesis flag when requesting txns by address
Browse files Browse the repository at this point in the history
Use the appropiate services flag when transactions from the PoW chain are required
from a specific address
  • Loading branch information
viquezclaudio authored and jsdanielh committed Nov 22, 2024
1 parent 5323ed8 commit 107b362
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
13 changes: 9 additions & 4 deletions consensus/src/consensus/consensus_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,19 @@ impl<N: Network> ConsensusProxy<N> {
min_peers: usize,
max: Option<u16>,
start_at: Option<Blake2bHash>,
include_pre_genesis: bool,
) -> Result<Vec<(Blake2bHash, u32)>, 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",
Expand Down
8 changes: 7 additions & 1 deletion consensus/tests/consensus_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion web-client/src/client/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ impl Client {
min_peers.unwrap_or(1),
limit,
start_at,
true,
)
.await?;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 107b362

Please sign in to comment.