-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for --include-partial-seats (#12)
* feat: add support for --include-partial-seats * Represent absence of partial seats by emtpy vec Instead of representing it by `None`. This simplifies code as it allows to remove an `Option` in several places.
- Loading branch information
Showing
11 changed files
with
601 additions
and
24 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use serde::Serialize; | ||
|
||
use crate::validator::Validator; | ||
|
||
/// Represents a partial seat filled by a particular validator. | ||
/// | ||
/// A partial seat may not outlive the validator it is referrencing. | ||
#[derive(Serialize, PartialEq, Debug, Clone)] | ||
pub struct PartialSeat<'validator> { | ||
/// Reference to the validator holding this particular partial seat. | ||
validator: &'validator Validator, | ||
/// The stake attributed to the partial seat. Note that `0 < weight < stake_per_seat`. | ||
/// | ||
/// For example, let validator `V` have a stake of 12 and let `stake_per_seat = 5`. Then `V` | ||
/// holds 2 full seats and a partial seat with `weight = 2`. | ||
weight: u128, | ||
} | ||
|
||
impl<'validator> PartialSeat<'validator> { | ||
/// Constructs the partial seat filled by `validator`. | ||
pub fn new(validator: &'validator Validator, weight: u128) -> Self { | ||
Self { validator, weight } | ||
} | ||
|
||
pub fn get_is_malicious(&self) -> bool { | ||
self.validator.get_is_malicious() | ||
} | ||
|
||
pub fn get_weight(&self) -> u128 { | ||
self.weight | ||
} | ||
} | ||
|
||
pub struct ShuffledPartialSeats<'seats> { | ||
partial_seats: &'seats [PartialSeat<'seats>], | ||
} | ||
|
||
impl<'seats> ShuffledPartialSeats<'seats> { | ||
/// Shuffles the input `partial_seats`. | ||
// TODO(rand) do all shuffling operations in one generic fn | ||
pub fn new(partial_seats: &'seats mut [PartialSeat<'seats>]) -> Self { | ||
fastrand::shuffle(partial_seats); | ||
Self { partial_seats } | ||
} | ||
|
||
pub fn get_partial_seats(&self) -> &[PartialSeat] { | ||
self.partial_seats | ||
} | ||
} |
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
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
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
Oops, something went wrong.