-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add RestartHeaviestFork to Gossip #34161
Add RestartHeaviestFork to Gossip #34161
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #34161 +/- ##
===========================================
+ Coverage 0 81.7% +81.7%
===========================================
Files 0 826 +826
Lines 0 223236 +223236
===========================================
+ Hits 0 182485 +182485
- Misses 0 40751 +40751 |
gossip/src/restart_crds_values.rs
Outdated
// Sum of received heaviest fork validator stake / total stake * u16::MAX. | ||
received_heaviest_fork_ratio: u16, |
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.
I would probably call this stake_ratio
or observed_stake_ratio
.
heaviest_fork
is already in the name of struct; it is redundant to repeat it here again.
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.
also why this u16
better than sending a f64
or the (stake, total_stake)
as a tuple?
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 original idea is we can save some bytes, but now you mention it, it's not really worth losing the precision by switching from 16 bytes to 2 bytes, I'm changing to (stake, total_stake) now.
gossip/src/restart_crds_values.rs
Outdated
ReceivedHeaviestForkStakeLargerThanTotalStake, | ||
#[error("Total stake of received heaviest fork cannot be zero")] | ||
ReceivedHeaviestForkStakeZero, |
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.
No need to repeat the enum name in the variants.
The variants are already qualified by the enum name, ie. RestartHeaviestForkError::...
.
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.
Changed.
@@ -122,6 +141,64 @@ impl RestartLastVotedForkSlots { | |||
} | |||
} | |||
|
|||
impl Sanitize for RestartHeaviestFork { | |||
fn sanitize(&self) -> Result<(), SanitizeError> { |
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.
can we sanitize the wallclock like the other crds values?
also probably that should be done for the previous restart crds value as well.
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.
Done.
gossip/src/restart_crds_values.rs
Outdated
if self.received_heaviest_fork_ratio == 0 { | ||
// this should at least include its own stake. | ||
return Err(SanitizeError::ValueOutOfBounds); | ||
} |
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.
what if node_stake / total_stake * u16::MAX < 1
?
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.
Removed.
gossip/src/restart_crds_values.rs
Outdated
pub wallclock: u64, | ||
pub last_slot: Slot, | ||
pub last_slot_hash: Hash, | ||
// Sum of received heaviest fork validator stake / total stake * u16::MAX. |
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.
What is "total stake"?
Is that the epoch stake or the stake observed in gossip?
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.
Changed.
gossip/src/restart_crds_values.rs
Outdated
pub last_slot: Slot, | ||
pub last_slot_hash: Hash, | ||
pub observed_stake: u64, | ||
pub total_epoch_stake: u64, |
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.
why do we need this?
Isn't the epoch_stakes
already known by all the nodes in the cluster?
https://github.com/solana-labs/solana/blob/1f00f8e29/runtime/src/bank.rs#L7744-L7746
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.
I thought it might be nice to distribute total_epoch_stake just in case some calculation is off. But you are right, if this stake is wrong we have bigger problems. Removed.
gossip/src/restart_crds_values.rs
Outdated
#[derive(Debug, Error, PartialEq)] | ||
pub enum RestartHeaviestForkError { | ||
#[error("Total stake of received heaviest fork cannot be zero")] | ||
ZeroObservedStake, | ||
} | ||
|
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 seems unnecessary and just adds verbosity.
Zero stake is practically not any different from stake of only 1 sol.
In addition a malicious node can just fake any number here.
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.
Removed.
gossip/src/restart_crds_values.rs
Outdated
if self.observed_stake == 0 { | ||
// this should at least include its own stake. | ||
return Err(SanitizeError::ValueOutOfBounds); | ||
} |
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.
Similarly here, regarding stake of 0.
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.
Removed.
gossip/src/restart_crds_values.rs
Outdated
if observed_stake == 0 { | ||
return Err(RestartHeaviestForkError::ZeroObservedStake); | ||
} |
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.
again, here regarding zero stake.
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.
Removed.
gossip/src/restart_crds_values.rs
Outdated
pub fn new( | ||
from: Pubkey, | ||
now: u64, | ||
last_slot: Slot, | ||
last_slot_hash: Hash, | ||
observed_stake: u64, | ||
shred_version: u16, | ||
) -> Self { | ||
Self { | ||
from, | ||
wallclock: now, | ||
last_slot, | ||
last_slot_hash, | ||
observed_stake, | ||
shred_version, | ||
} | ||
} |
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.
Why do we need this? all fields are public.
Either remove fields from public interface or remove this redundant method.
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.
Removed.
gossip/src/restart_crds_values.rs
Outdated
} | ||
} | ||
|
||
pub fn new_rand<R: Rng>(rng: &mut R, pubkey: Option<Pubkey>) -> Self { |
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.
Does this need to be pub
?
I feel like every review I have to ask not to pollute public interface.
Can you go over all pub
s in this code and remove those not needed?
or at least change them to pub(crate)
.
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 is used in tests, and I don't see any benchmarks needing it now. So I changed it to pub(crate).
Add RestartHeaviestFork to Gossip