-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from datachainlab/generic-fork-parameters
Make fork parameters generic Signed-off-by: Jun Kimura <[email protected]>
- Loading branch information
Showing
11 changed files
with
181 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
use crate::{beacon::Version, fork::ForkParameters, preset, types::U64}; | ||
|
||
use super::Config; | ||
|
||
pub const CONFIG: Config = Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters { | ||
genesis_fork_version: Version([0, 0, 16, 32]), | ||
genesis_slot: U64(0), | ||
|
||
altair_fork_version: Version([1, 0, 16, 32]), | ||
altair_fork_epoch: U64(36660), | ||
|
||
bellatrix_fork_version: Version([2, 0, 16, 32]), | ||
bellatrix_fork_epoch: U64(112260), | ||
|
||
capella_fork_version: Version([3, 0, 16, 32]), | ||
capella_fork_epoch: U64(162304), | ||
|
||
// NOTE: dummy data | ||
eip4844_fork_version: Version([4, 0, 0, 0]), | ||
eip4844_fork_epoch: U64(u64::MAX), | ||
}, | ||
min_genesis_time: U64(1614588812), | ||
use crate::{ | ||
beacon::Version, | ||
fork::{ForkParameter, ForkParameters}, | ||
internal_prelude::*, | ||
preset, | ||
types::U64, | ||
}; | ||
|
||
pub fn get_config() -> Config { | ||
Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters::new( | ||
Version([0, 0, 16, 32]), | ||
vec![ | ||
ForkParameter::new(Version([4, 0, 16, 32]), U64(u64::MAX)), | ||
ForkParameter::new(Version([3, 0, 16, 32]), U64(162304)), | ||
ForkParameter::new(Version([2, 0, 16, 32]), U64(112260)), | ||
ForkParameter::new(Version([1, 0, 16, 32]), U64(36660)), | ||
], | ||
), | ||
min_genesis_time: U64(1614588812), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,25 +1,24 @@ | ||
use crate::{beacon::Version, fork::ForkParameters, preset, types::U64}; | ||
|
||
use super::Config; | ||
|
||
pub const CONFIG: Config = Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters { | ||
genesis_fork_version: Version([0, 0, 0, 0]), | ||
genesis_slot: U64(0), | ||
|
||
altair_fork_version: Version([1, 0, 0, 0]), | ||
altair_fork_epoch: U64(74240), | ||
|
||
bellatrix_fork_version: Version([2, 0, 0, 0]), | ||
bellatrix_fork_epoch: U64(144896), | ||
|
||
capella_fork_version: Version([3, 0, 0, 0]), | ||
capella_fork_epoch: U64(194048), | ||
|
||
// NOTE: dummy data | ||
eip4844_fork_version: Version([4, 0, 0, 0]), | ||
eip4844_fork_epoch: U64(u64::MAX), | ||
}, | ||
min_genesis_time: U64(1606824000), | ||
use crate::{ | ||
beacon::Version, | ||
fork::{ForkParameter, ForkParameters}, | ||
internal_prelude::*, | ||
preset, | ||
types::U64, | ||
}; | ||
|
||
pub fn get_config() -> Config { | ||
Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters::new( | ||
Version([0, 0, 0, 0]), | ||
vec![ | ||
ForkParameter::new(Version([4, 0, 0, 0]), U64(u64::MAX)), | ||
ForkParameter::new(Version([3, 0, 0, 0]), U64(194048)), | ||
ForkParameter::new(Version([2, 0, 0, 0]), U64(144896)), | ||
ForkParameter::new(Version([1, 0, 0, 0]), U64(74240)), | ||
], | ||
), | ||
min_genesis_time: U64(1606824000), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,25 +1,24 @@ | ||
use crate::{beacon::Version, fork::ForkParameters, preset, types::U64}; | ||
|
||
use super::Config; | ||
|
||
pub const CONFIG: Config = Config { | ||
preset: preset::minimal::PRESET, | ||
fork_parameters: ForkParameters { | ||
genesis_fork_version: Version([0, 0, 0, 1]), | ||
genesis_slot: U64(0), | ||
|
||
altair_fork_version: Version([1, 0, 0, 1]), | ||
altair_fork_epoch: U64(0), | ||
|
||
bellatrix_fork_version: Version([2, 0, 0, 1]), | ||
bellatrix_fork_epoch: U64(0), | ||
|
||
capella_fork_version: Version([3, 0, 0, 1]), | ||
capella_fork_epoch: U64(0), | ||
|
||
// NOTE: dummy data | ||
eip4844_fork_version: Version([4, 0, 0, 1]), | ||
eip4844_fork_epoch: U64(u64::MAX), | ||
}, | ||
min_genesis_time: U64(1578009600), | ||
use crate::{ | ||
beacon::Version, | ||
fork::{ForkParameter, ForkParameters}, | ||
internal_prelude::*, | ||
preset, | ||
types::U64, | ||
}; | ||
|
||
pub fn get_config() -> Config { | ||
Config { | ||
preset: preset::minimal::PRESET, | ||
fork_parameters: ForkParameters::new( | ||
Version([0, 0, 0, 1]), | ||
vec![ | ||
ForkParameter::new(Version([4, 0, 0, 1]), U64(u64::MAX)), | ||
ForkParameter::new(Version([3, 0, 0, 1]), U64(0)), | ||
ForkParameter::new(Version([2, 0, 0, 1]), U64(0)), | ||
ForkParameter::new(Version([1, 0, 0, 1]), U64(0)), | ||
], | ||
), | ||
min_genesis_time: U64(1578009600), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,25 +1,24 @@ | ||
use crate::{beacon::Version, fork::ForkParameters, preset, types::U64}; | ||
|
||
use super::Config; | ||
|
||
pub const CONFIG: Config = Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters { | ||
genesis_fork_version: Version([144, 0, 0, 105]), | ||
genesis_slot: U64(0), | ||
|
||
altair_fork_version: Version([144, 0, 0, 112]), | ||
altair_fork_epoch: U64(50), | ||
|
||
bellatrix_fork_version: Version([144, 0, 0, 113]), | ||
bellatrix_fork_epoch: U64(100), | ||
|
||
capella_fork_version: Version([144, 0, 0, 114]), | ||
capella_fork_epoch: U64(56832), | ||
|
||
// NOTE: dummy data | ||
eip4844_fork_version: Version([4, 0, 0, 0]), | ||
eip4844_fork_epoch: U64(u64::MAX), | ||
}, | ||
min_genesis_time: U64(1655647200), | ||
use crate::{ | ||
beacon::Version, | ||
fork::{ForkParameter, ForkParameters}, | ||
internal_prelude::*, | ||
preset, | ||
types::U64, | ||
}; | ||
|
||
pub fn get_config() -> Config { | ||
Config { | ||
preset: preset::mainnet::PRESET, | ||
fork_parameters: ForkParameters::new( | ||
Version([144, 0, 0, 105]), | ||
vec![ | ||
ForkParameter::new(Version([144, 0, 0, 0]), U64(u64::MAX)), | ||
ForkParameter::new(Version([144, 0, 0, 114]), U64(56832)), | ||
ForkParameter::new(Version([144, 0, 0, 113]), U64(100)), | ||
ForkParameter::new(Version([144, 0, 0, 112]), U64(50)), | ||
], | ||
), | ||
min_genesis_time: U64(1655647200), | ||
} | ||
} |
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 |
---|---|---|
@@ -1,19 +1,52 @@ | ||
use crate::beacon::{Epoch, Slot, Version}; | ||
use crate::errors::Error; | ||
use crate::internal_prelude::*; | ||
use crate::types::U64; | ||
|
||
#[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
pub struct ForkParameters { | ||
pub genesis_fork_version: Version, | ||
pub genesis_slot: Slot, | ||
pub genesis_version: Version, | ||
pub forks: Vec<ForkParameter>, | ||
} | ||
|
||
impl ForkParameters { | ||
pub const fn new(genesis_version: Version, forks: Vec<ForkParameter>) -> Self { | ||
Self { | ||
genesis_version, | ||
forks, | ||
} | ||
} | ||
|
||
pub fn validate(&self) -> Result<(), Error> { | ||
if self.forks.windows(2).all(|f| f[0].epoch >= f[1].epoch) { | ||
Ok(()) | ||
} else { | ||
Err(Error::InvalidForkParamersOrder(self.clone())) | ||
} | ||
} | ||
|
||
pub altair_fork_version: Version, | ||
pub altair_fork_epoch: Epoch, | ||
pub fn genesis_slot(&self) -> Slot { | ||
U64(0) | ||
} | ||
|
||
pub bellatrix_fork_version: Version, | ||
pub bellatrix_fork_epoch: Epoch, | ||
pub fn compute_fork_version(&self, epoch: Epoch) -> Result<&Version, Error> { | ||
for fork in self.forks.iter() { | ||
if epoch >= fork.epoch { | ||
return Ok(&fork.version); | ||
} | ||
} | ||
Ok(&self.genesis_version) | ||
} | ||
} | ||
|
||
pub capella_fork_version: Version, | ||
pub capella_fork_epoch: Epoch, | ||
#[derive(Debug, Default, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] | ||
pub struct ForkParameter { | ||
pub version: Version, | ||
pub epoch: Epoch, | ||
} | ||
|
||
pub eip4844_fork_version: Version, | ||
pub eip4844_fork_epoch: Epoch, | ||
impl ForkParameter { | ||
pub const fn new(version: Version, epoch: Epoch) -> Self { | ||
Self { version, epoch } | ||
} | ||
} |
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.