-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cardano-blockchain-types): Fork type
Signed-off-by: bkioshn <[email protected]>
- Loading branch information
Showing
3 changed files
with
70 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! Fork count is a counter that is incremented every time there is a roll-back in | ||
//! live-chain It is used to help followers determine how far to roll-back to | ||
//! resynchronize without storing full block history. The fork count starts at 1 for live | ||
//! blocks and increments if the live chain tip is purged due to a detected fork, but it | ||
//! does not track the exact number of forks reported by peers. | ||
//! | ||
//! Note: This fork terminology is different from fork in blockchain. | ||
use crate::conversion::from_saturating; | ||
|
||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
/// Counter that is incremented every time there is a roll-back in live-chain | ||
pub struct Fork(u64); | ||
|
||
impl Fork { | ||
/// Convert an `<T>` to Fork. (saturate if out of range.) | ||
pub fn from_saturating< | ||
T: Copy | ||
+ TryInto<u64> | ||
+ std::ops::Sub<Output = T> | ||
+ std::cmp::PartialOrd<T> | ||
+ num_traits::identities::Zero, | ||
>( | ||
value: T, | ||
) -> Self { | ||
let value: u64 = from_saturating(value); | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<u64> for Fork { | ||
fn from(value: u64) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl From<Fork> for u64 { | ||
fn from(val: Fork) -> Self { | ||
val.0 | ||
} | ||
} |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
mod auxdata; | ||
pub mod conversion; | ||
mod fork; | ||
pub mod hashes; | ||
mod multi_era_block_data; | ||
mod network; | ||
|
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