Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: only fetch blocks for filter matched #154

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/protocols/light_client/components/send_blocks_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> SendBlocksProofProcess<'a> {
let status = self.execute_internally();
self.protocol
.peers()
.update_blocks_proof_request(self.peer_index, None);
.update_blocks_proof_request(self.peer_index, None, false);
status
}

Expand Down Expand Up @@ -118,7 +118,7 @@ impl<'a> SendBlocksProofProcess<'a> {
));

// Get blocks
{
if original_request.should_get_blocks() {
let block_hashes: Vec<packed::Byte32> =
headers.iter().map(|header| header.hash()).collect();
{
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/light_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ impl LightClientProtocol {
.as_bytes();

self.peers
.update_blocks_proof_request(*peer_index, Some(content));
.update_blocks_proof_request(*peer_index, Some(content), false);
if let Err(err) = nc.send_message(
SupportProtocols::LightClient.protocol_id(),
*peer_index,
Expand Down
23 changes: 19 additions & 4 deletions src/protocols/light_client/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub(crate) struct ProveState {
pub(crate) struct BlocksProofRequest {
content: packed::GetBlocksProof,
when_sent: u64,
should_get_blocks: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -394,8 +395,16 @@ impl ProveState {
}

impl BlocksProofRequest {
pub(crate) fn new(content: packed::GetBlocksProof, when_sent: u64) -> Self {
Self { content, when_sent }
pub(crate) fn new(
content: packed::GetBlocksProof,
when_sent: u64,
should_get_blocks: bool,
) -> Self {
Self {
content,
when_sent,
should_get_blocks,
}
}

pub(crate) fn last_hash(&self) -> Byte32 {
Expand Down Expand Up @@ -430,6 +439,10 @@ impl BlocksProofRequest {
false
}
}

pub(crate) fn should_get_blocks(&self) -> bool {
self.should_get_blocks
}
}

impl BlocksRequest {
Expand Down Expand Up @@ -1480,10 +1493,12 @@ impl Peers {
&self,
index: PeerIndex,
request: Option<packed::GetBlocksProof>,
should_get_blocks: bool,
) {
if let Some(mut peer) = self.inner.get_mut(&index) {
peer.blocks_proof_request =
request.map(|content| BlocksProofRequest::new(content, unix_time_as_millis()));
peer.blocks_proof_request = request.map(|content| {
BlocksProofRequest::new(content, unix_time_as_millis(), should_get_blocks)
});
}
}
pub(crate) fn update_blocks_request(&self, index: PeerIndex, hashes: Option<Vec<Byte32>>) {
Expand Down
8 changes: 4 additions & 4 deletions src/tests/protocols/light_client/send_blocks_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async fn last_state_is_changed() {
.unwrap();
protocol
.peers()
.update_blocks_proof_request(peer_index, Some(content));
.update_blocks_proof_request(peer_index, Some(content), true);
}

num += 1;
Expand Down Expand Up @@ -218,7 +218,7 @@ async fn unexpected_response() {
.unwrap();
protocol
.peers()
.update_blocks_proof_request(peer_index, Some(content));
.update_blocks_proof_request(peer_index, Some(content), true);
}

// Run the test.
Expand Down Expand Up @@ -325,7 +325,7 @@ async fn get_blocks_with_chunks() {
.unwrap();
protocol
.peers()
.update_blocks_proof_request(peer_index, Some(content));
.update_blocks_proof_request(peer_index, Some(content), true);
}

// Run the test.
Expand Down Expand Up @@ -675,7 +675,7 @@ async fn test_send_blocks_proof(param: TestParameter) {
.unwrap();
protocol
.peers()
.update_blocks_proof_request(peer_index, Some(content));
.update_blocks_proof_request(peer_index, Some(content), true);
}

// Run the test.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) fn prove_or_download_matched_blocks(
.set(content.clone())
.build()
.as_bytes();
peers.update_blocks_proof_request(*peer_index, Some(content));
peers.update_blocks_proof_request(*peer_index, Some(content), true);
if let Err(err) = nc.send_message(
SupportProtocols::LightClient.protocol_id(),
*peer_index,
Expand Down
Loading