2020-07-06 20:05:55 -07:00
|
|
|
#[derive(Serialize, Deserialize, Default, Clone, Copy, Debug, PartialEq)]
|
2019-11-06 13:15:00 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct CommitmentConfig {
|
|
|
|
pub commitment: CommitmentLevel,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CommitmentConfig {
|
|
|
|
pub fn recent() -> Self {
|
|
|
|
Self {
|
|
|
|
commitment: CommitmentLevel::Recent,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 10:38:54 -08:00
|
|
|
pub fn max() -> Self {
|
|
|
|
Self {
|
|
|
|
commitment: CommitmentLevel::Max,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 21:55:33 -07:00
|
|
|
pub fn root() -> Self {
|
|
|
|
Self {
|
|
|
|
commitment: CommitmentLevel::Root,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-18 11:49:01 -07:00
|
|
|
pub fn single() -> Self {
|
|
|
|
Self {
|
|
|
|
commitment: CommitmentLevel::Single,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-22 12:55:17 -07:00
|
|
|
pub fn single_gossip() -> Self {
|
|
|
|
Self {
|
|
|
|
commitment: CommitmentLevel::SingleGossip,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 16:53:30 -08:00
|
|
|
pub fn ok(self) -> Option<Self> {
|
|
|
|
if self == Self::default() {
|
2019-11-06 13:15:00 -08:00
|
|
|
None
|
|
|
|
} else {
|
2020-03-03 16:53:30 -08:00
|
|
|
Some(self)
|
2019-11-06 13:15:00 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-22 12:55:17 -07:00
|
|
|
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
2019-11-06 13:15:00 -08:00
|
|
|
#[serde(rename_all = "camelCase")]
|
2020-08-07 07:45:17 -07:00
|
|
|
/// An attribute of a slot. It describes how finalized a block is at some point in time. For example, a slot
|
|
|
|
/// is said to be at the max level immediately after the cluster recognizes the block at that slot as
|
|
|
|
/// finalized. When querying the ledger state, use lower levels of commitment to report progress and higher
|
|
|
|
/// levels to ensure state changes will not be rolled back.
|
2019-11-06 13:15:00 -08:00
|
|
|
pub enum CommitmentLevel {
|
2020-08-07 07:45:17 -07:00
|
|
|
/// The highest slot having reached max vote lockout, as recognized by a supermajority of the cluster.
|
2019-11-06 13:15:00 -08:00
|
|
|
Max,
|
2020-08-07 07:45:17 -07:00
|
|
|
|
|
|
|
/// The highest slot of the heaviest fork. Ledger state at this slot is not derived from a finalized
|
|
|
|
/// block, but if multiple forks are present, is from the fork the validator believes is most likely
|
|
|
|
/// to finalize.
|
2019-11-06 13:15:00 -08:00
|
|
|
Recent,
|
2020-08-07 07:45:17 -07:00
|
|
|
|
|
|
|
/// The highest slot having reached max vote lockout.
|
2020-04-29 21:55:33 -07:00
|
|
|
Root,
|
2020-08-07 07:45:17 -07:00
|
|
|
|
|
|
|
/// The highest slot having reached 1 confirmation.
|
2020-05-18 11:49:01 -07:00
|
|
|
Single,
|
2020-08-07 07:45:17 -07:00
|
|
|
|
|
|
|
/// The highest slot having reached 1 confirmation via gossip votes; may occur before or after Single,
|
|
|
|
/// depending on gossip traffic.
|
2020-05-22 12:55:17 -07:00
|
|
|
SingleGossip,
|
2019-11-06 13:15:00 -08:00
|
|
|
}
|
2020-07-06 20:05:55 -07:00
|
|
|
|
|
|
|
impl Default for CommitmentLevel {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::Max
|
|
|
|
}
|
|
|
|
}
|