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

fix: resolve empty filter related message bug #4270

Merged
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
10 changes: 5 additions & 5 deletions sync/src/filter/get_block_filter_check_points_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

let mut block_filter_hashes = Vec::new();

if tip_number >= start_number {
if latest >= start_number {
for block_number in (start_number..start_number + BATCH_SIZE * CHECK_POINT_INTERVAL)
.step_by(CHECK_POINT_INTERVAL as usize)
{
Expand All @@ -59,9 +59,9 @@ impl<'a> GetBlockFilterCheckPointsProcess<'a> {
let message = packed::BlockFilterMessage::new_builder()
.set(content)
.build();
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message));
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message))
} else {
Status::ignored()
}

Status::ok()
}
}
4 changes: 2 additions & 2 deletions sync/src/filter/get_block_filter_hashes_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ impl<'a> GetBlockFilterHashesProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

let mut block_filter_hashes = Vec::new();

if tip_number >= start_number {
if latest >= start_number {
let parent_block_filter_hash = if start_number > 0 {
match active_chain
.get_block_hash(start_number - 1)
Expand Down
11 changes: 6 additions & 5 deletions sync/src/filter/get_block_filters_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ impl<'a> GetBlockFiltersProcess<'a> {
pub fn execute(self) -> Status {
let active_chain = self.filter.shared.active_chain();
let start_number: BlockNumber = self.message.to_entity().start_number().unpack();
let tip_number: BlockNumber = active_chain.tip_number();
if tip_number >= start_number {
let latest: BlockNumber = active_chain.get_latest_built_filter_block_number();

if latest >= start_number {
let mut block_hashes = Vec::new();
let mut filters = Vec::new();
for block_number in start_number..start_number + BATCH_SIZE {
Expand All @@ -58,9 +59,9 @@ impl<'a> GetBlockFiltersProcess<'a> {
let message = packed::BlockFilterMessage::new_builder()
.set(content)
.build();
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message));
attempt!(send_message_to(self.nc.as_ref(), self.peer, &message))
} else {
Status::ignored()
}

Status::ok()
}
}
7 changes: 7 additions & 0 deletions sync/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,13 @@ impl ActiveChain {
self.store().get_block_filter_hash(hash)
}

pub fn get_latest_built_filter_block_number(&self) -> BlockNumber {
self.snapshot
.get_latest_built_filter_data_block_hash()
.and_then(|hash| self.snapshot.get_block_number(&hash))
.unwrap_or_default()
}

pub fn shared(&self) -> &SyncShared {
&self.shared
}
Expand Down
Loading