This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
client/finality-grandpa/src/until_imported: Refactor BlockGlobalMessage #5390
Merged
bkchr
merged 4 commits into
paritytech:master
from
mxinden:refactor-blocked-global-message
Mar 25, 2020
Merged
client/finality-grandpa/src/until_imported: Refactor BlockGlobalMessage #5390
bkchr
merged 4 commits into
paritytech:master
from
mxinden:refactor-blocked-global-message
Mar 25, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
`BlockGlobalMessage` owns an `inner` which contains (1) a count for the amount of outstanding blocks to be waited on and (2) the message itself. Given that both is already wrapped in an `Arc` there is no need to keep track of the outstanding blocks, given that it simply corresponds to the amount of strong reference counts on the `Arc` itself. This commit removes the atomic counter within `inner` and piggy backs on the `Arc` reference counter instead.
mxinden
added
A0-please_review
Pull request needs code review.
B0-silent
Changes should not be mentioned in any release notes
labels
Mar 24, 2020
mxinden
commented
Mar 24, 2020
return None; | ||
} | ||
|
||
let mut last_count = self.inner.0.load(Ordering::Acquire); | ||
|
||
// CAS loop to ensure that we always have a last reader. |
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.
In case we decide against this, we should at least replace this CAS loop with a single fetch_sub
call.
bkchr
reviewed
Mar 24, 2020
} | ||
match Arc::try_unwrap(self.inner) { | ||
// This is the last reference, thus this was the last outstanding block to be awaited. | ||
Ok(inner) => match Mutex::into_inner(inner) { |
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.
This match doesn't makes any sense?
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.
Yes. At first I thought this would make it more explicit. Removed it and improved comment above it instead.
Thanks for the review @bkchr. Would you mind taking another look? |
andresilva
approved these changes
Mar 25, 2020
andresilva
reviewed
Mar 25, 2020
Co-Authored-By: André Silva <andre.beat@gmail.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
A0-please_review
Pull request needs code review.
B0-silent
Changes should not be mentioned in any release notes
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BlockGlobalMessage
owns aninner
which contains (1) a count for theamount of outstanding blocks to be waited on and (2) the message itself.
Given that both is already wrapped in an
Arc
there is no need to keeptrack of the outstanding blocks, given that it simply corresponds to the
amount of strong reference counts on the
Arc
itself.This commit removes the atomic counter within
inner
and piggy backs onthe
Arc
reference counter instead.On the one hand this reduces the amount of complexity given that there is no need to update the blocks-to-be-awaited counter anymore, on the other hand it makes the blocks-to-be-awaited counting implicit instead of explicit. Let me know what you think.