-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
Make StakeDelegations clone-on-write #21542
Conversation
/// current stake delegations for this bank | ||
pub fn cloned_stake_delegations(&self) -> HashMap<Pubkey, Delegation> { | ||
self.stakes.read().unwrap().stake_delegations().clone() | ||
} | ||
|
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 function was only called by the bank tests, so I've moved it into the test module. Originally I only needed to change the return type (to StakeDelegations
), but saw I could also move the fn.
runtime/src/stake_delegations.rs
Outdated
/// A map of pubkey-to-stake-delegation with clone-on-write semantics | ||
#[derive(Default, Clone, PartialEq, Debug, Deserialize, Serialize)] | ||
pub struct StakeDelegations(Arc<StakeDelegationsInner>); |
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.
The inner map needs to be wrapped in an Arc
due to it being passed between threads. Found this out from the compiler while building an earlier version with Rc
.
@jstarry Using Rc
(or Arc
) answers the questions we were having yesterday about Rust and lifetimes, vs just using Cow
.
@@ -27,7 +30,7 @@ pub struct Stakes { | |||
vote_accounts: VoteAccounts, | |||
|
|||
/// stake_delegations | |||
stake_delegations: HashMap<Pubkey, Delegation>, | |||
stake_delegations: StakeDelegations, |
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.
Pretty nice! Basically no other changes needed.
Codecov Report
@@ Coverage Diff @@
## master #21542 +/- ##
=======================================
Coverage 81.5% 81.5%
=======================================
Files 506 507 +1
Lines 142216 142251 +35
=======================================
+ Hits 116024 116071 +47
+ Misses 26192 26180 -12 |
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.
Look great!
Problem
Stake delegations are cloned into every bank, regardless if they are changed or not.
Summary of Changes
Implement clone-on-write semantics for stake delegations.