-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Lock-free latest_l2_height
in gas price service
#2546
base: chore/add-tests-for-v1-gas-service
Are you sure you want to change the base?
Lock-free latest_l2_height
in gas price service
#2546
Conversation
.latest_l2_height | ||
.lock() | ||
.map_err(|err| anyhow::anyhow!("lock error: {:?}", err))?; | ||
let latest_l2_height = self.latest_l2_height.load(Ordering::SeqCst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let latest_l2_height = self.latest_l2_height.load(Ordering::SeqCst); | |
let latest_l2_height = self.latest_l2_height.load(Ordering::Acquire); |
SeqCst is not needed unless you have at least two atomic variables. The purpose of SeqCst is to make sure that different threads do not see updates to different variables in different order. See https://stackoverflow.com/questions/14861822/acquire-release-versus-sequentially-consistent-memory-order for an example.
(Just mentioning this, overall I think we can keep SeqCst)
@@ -103,7 +107,7 @@ where | |||
.filter_costs_that_have_values_greater_than_l2_block_height(da_block_costs)?; | |||
tracing::debug!( | |||
"the latest l2 height is: {:?}", | |||
*self.latest_l2_height.lock().unwrap() | |||
self.latest_l2_height.load(Ordering::SeqCst) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.latest_l2_height.load(Ordering::SeqCst) | |
self.latest_l2_height.load(Ordering::Acquire) |
.lock() | ||
.map_err(|err| anyhow!("Error locking latest L2 block: {:?}", err))?; | ||
*latest_l2_block = BlockHeight::from(height); | ||
self.latest_l2_block.store(height, Ordering::SeqCst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.latest_l2_block.store(height, Ordering::SeqCst); | |
self.latest_l2_block.store(height, Ordering::Release); |
(see the corresponding comment on the load
operation)
small comments because I am picky about memory ordering :) , but overall LGTM |
Description
This PR removes the
Mutex
around thelatest_l2_height
in the gas price service.Before requesting review