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

Optimize desegmenter check progress #3756

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
15 changes: 9 additions & 6 deletions chain/src/txhashset/desegmenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub struct Desegmenter {

/// Flag indicating there are no more segments to request
all_segments_complete: bool,

latest_block_height: u64,
}

impl Desegmenter {
Expand Down Expand Up @@ -104,6 +106,8 @@ impl Desegmenter {
bitmap_cache: None,

all_segments_complete: false,

latest_block_height: 0,
};
retval.calc_bitmap_mmr_sizes();
retval
Expand All @@ -120,6 +124,7 @@ impl Desegmenter {
self.bitmap_mmr_size = 0;
self.bitmap_cache = None;
self.bitmap_accumulator = BitmapAccumulator::new();
self.latest_block_height = 0;
self.calc_bitmap_mmr_sizes();
}

Expand All @@ -140,9 +145,7 @@ impl Desegmenter {

/// Check progress, update status if needed, returns true if all required
/// segments are in place
pub fn check_progress(&self, status: Arc<SyncState>) -> Result<bool, Error> {
let mut latest_block_height = 0;

pub fn check_progress(&mut self, status: Arc<SyncState>) -> Result<bool, Error> {
let local_output_mmr_size;
let local_kernel_mmr_size;
let local_rangeproof_mmr_size;
Expand Down Expand Up @@ -174,13 +177,13 @@ impl Desegmenter {
header_pmmr.get_first_header_with(
latest_output_size,
local_kernel_mmr_size,
latest_block_height,
self.latest_block_height,
self.store.clone(),
)
};

if let Some(h) = res {
latest_block_height = h.height;
self.latest_block_height = h.height;

// TODO: Unwraps
let tip = Tip::from_header(&h);
Expand All @@ -192,7 +195,7 @@ impl Desegmenter {
false,
false,
completed_leaves,
latest_block_height,
self.latest_block_height,
&self.archive_header,
);
if local_kernel_mmr_size == self.archive_header.kernel_mmr_size
Expand Down
2 changes: 1 addition & 1 deletion servers/src/grin/sync/state_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl StateSync {
if self.continue_pibd() {
let desegmenter = self.chain.desegmenter(&archive_header).unwrap();
// All segments in, validate
if let Some(d) = desegmenter.read().as_ref() {
if let Some(d) = desegmenter.write().as_mut() {
if let Ok(true) = d.check_progress(self.sync_state.clone()) {
if let Err(e) = d.check_update_leaf_set_state() {
error!("error updating PIBD leaf set: {}", e);
Expand Down