Merge pull request #190 from blockworks-foundation/use_counting_semaphore_to_poll_blocks

Use counting semaphore to poll blocks
This commit is contained in:
galactus 2023-09-08 13:58:54 +02:00 committed by GitHub
commit 88cef0edf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -179,6 +179,11 @@ pub fn poll_block(
.await
.context("Slot notification channel close")?;
let last_processed_slot = current_slot.load(std::sync::atomic::Ordering::Relaxed);
let last_processed_slot = if last_processed_slot == 0 {
last_processed_slot.saturating_sub(1)
} else {
last_processed_slot
};
if processed_slot > last_processed_slot {
current_slot.store(processed_slot, std::sync::atomic::Ordering::Relaxed);

View File

@ -84,13 +84,14 @@ pub fn poll_slots(
// this is because it may be a slot block
if estimated_slot < current_slot + 32 {
estimated_slot += 1;
sender
.send(SlotNotification {
processed_slot: current_slot,
estimated_processed_slot: estimated_slot,
})
.context("Connot send slot notification")?;
}
sender
.send(SlotNotification {
processed_slot: current_slot,
estimated_processed_slot: estimated_slot,
})
.context("Connot send slot notification")?;
}
}
}