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: fix atomic ordering in multi-thread #4623

Merged
merged 1 commit into from
Aug 30, 2024
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 shared/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ impl Shared {
/// Return whether chain is in initial block download
pub fn is_initial_block_download(&self) -> bool {
// Once this function has returned false, it must remain false.
if self.ibd_finished.load(Ordering::Relaxed) {
if self.ibd_finished.load(Ordering::Acquire) {
false
} else if unix_time_as_millis().saturating_sub(self.snapshot().tip_header().timestamp())
> MAX_TIP_AGE
{
true
} else {
self.ibd_finished.store(true, Ordering::Relaxed);
self.ibd_finished.store(true, Ordering::Release);
false
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/src/types/header_map/kernel_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
self.stats().tick_primary_delete();
}
// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory.remove(hash, allow_shrink_to_fit);
if self.backend.is_empty() {
return;
Expand All @@ -175,7 +175,7 @@ where
});

// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory
.remove_batch(values.iter().map(|value| value.hash()), allow_shrink_to_fit);
}
Expand Down
6 changes: 3 additions & 3 deletions tx-pool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ macro_rules! send_notify {
impl TxPoolController {
/// Return whether tx-pool service is started
pub fn service_started(&self) -> bool {
self.started.load(Ordering::Relaxed)
self.started.load(Ordering::Acquire)
}

/// Set tx-pool service started, should only used for test
#[cfg(feature = "internal")]
pub fn set_service_started(&self, v: bool) {
self.started.store(v, Ordering::Relaxed);
self.started.store(v, Ordering::Release);
}

/// Return reference of tokio runtime handle
Expand Down Expand Up @@ -658,7 +658,7 @@ impl TxPoolServiceBuilder {
}
}
});
self.started.store(true, Ordering::Relaxed);
self.started.store(true, Ordering::Release);
if let Err(err) = self.tx_pool_controller.load_persisted_data(txs) {
error!("Failed to import persistent txs, cause: {}", err);
}
Expand Down
Loading