Skip to content

Commit

Permalink
pibd: save latest_block_height to request less data from db when chec…
Browse files Browse the repository at this point in the history
…king progress (#3756)
  • Loading branch information
ardocrat authored Jun 20, 2023
1 parent fd1410e commit 45ebc8a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
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

0 comments on commit 45ebc8a

Please sign in to comment.