mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
merge genesis complete block with genesis ended
Some checks failed
Lint / clippy (windows-latest) (push) Has been cancelled
Lint / deny (push) Has been cancelled
Lint / fmt (push) Has been cancelled
Lint / machete (push) Has been cancelled
Reproducible Runtime / build (push) Has been cancelled
Tests / test-infra (push) Has been cancelled
Full Stack Tests / build (push) Has been cancelled
Lint / clippy (macos-13) (push) Has been cancelled
Lint / clippy (macos-14) (push) Has been cancelled
Lint / clippy (ubuntu-latest) (push) Has been cancelled
Tests / test-substrate (push) Has been cancelled
Tests / test-serai-client (push) Has been cancelled
Some checks failed
Lint / clippy (windows-latest) (push) Has been cancelled
Lint / deny (push) Has been cancelled
Lint / fmt (push) Has been cancelled
Lint / machete (push) Has been cancelled
Reproducible Runtime / build (push) Has been cancelled
Tests / test-infra (push) Has been cancelled
Full Stack Tests / build (push) Has been cancelled
Lint / clippy (macos-13) (push) Has been cancelled
Lint / clippy (macos-14) (push) Has been cancelled
Lint / clippy (ubuntu-latest) (push) Has been cancelled
Tests / test-substrate (push) Has been cancelled
Tests / test-serai-client (push) Has been cancelled
This commit is contained in:
parent
efc45c391b
commit
a2df54dd6a
5 changed files with 22 additions and 32 deletions
|
@ -63,8 +63,7 @@ impl<'a> SeraiGenesisLiquidity<'a> {
|
||||||
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(LiquidityAmount::zero()))
|
Ok(self.0.storage(PALLET, "Supply", coin).await?.unwrap_or(LiquidityAmount::zero()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn genesis_complete(&self) -> Result<bool, SeraiError> {
|
pub async fn genesis_complete_block(&self) -> Result<Option<u64>, SeraiError> {
|
||||||
let result: Option<()> = self.0.storage(PALLET, "GenesisComplete", ()).await?;
|
self.0.storage(PALLET, "GenesisCompleteBlock", ()).await
|
||||||
Ok(result.is_some())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,18 +54,18 @@ async fn test_emissions(serai: Serai) {
|
||||||
let (_, mut batch_ids) = set_up_genesis(&serai, &coins, &values).await;
|
let (_, mut batch_ids) = set_up_genesis(&serai, &coins, &values).await;
|
||||||
|
|
||||||
// wait until genesis is complete
|
// wait until genesis is complete
|
||||||
while !serai
|
let mut genesis_complete_block = None;
|
||||||
|
while genesis_complete_block.is_none() {
|
||||||
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
|
genesis_complete_block = serai
|
||||||
.as_of_latest_finalized_block()
|
.as_of_latest_finalized_block()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.genesis_liquidity()
|
.genesis_liquidity()
|
||||||
.genesis_complete()
|
.genesis_complete_block()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap();
|
||||||
{
|
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
|
||||||
}
|
}
|
||||||
let genesis_complete_block = serai.latest_finalized_block().await.unwrap().number();
|
|
||||||
|
|
||||||
for _ in 0 .. 3 {
|
for _ in 0 .. 3 {
|
||||||
// get current stakes
|
// get current stakes
|
||||||
|
@ -99,7 +99,7 @@ async fn test_emissions(serai: Serai) {
|
||||||
|
|
||||||
// calculate how much reward in this session
|
// calculate how much reward in this session
|
||||||
let reward_this_epoch =
|
let reward_this_epoch =
|
||||||
if change_block_number < (genesis_complete_block + FAST_EPOCH_INITIAL_PERIOD) {
|
if change_block_number < (genesis_complete_block.unwrap() + FAST_EPOCH_INITIAL_PERIOD) {
|
||||||
block_count * INITIAL_REWARD_PER_BLOCK
|
block_count * INITIAL_REWARD_PER_BLOCK
|
||||||
} else {
|
} else {
|
||||||
let blocks_until = SECURE_BY - change_block_number;
|
let blocks_until = SECURE_BY - change_block_number;
|
||||||
|
|
|
@ -24,14 +24,15 @@ pub async fn test_genesis_liquidity(serai: Serai) {
|
||||||
let (accounts, _) = set_up_genesis(&serai, &coins, &values).await;
|
let (accounts, _) = set_up_genesis(&serai, &coins, &values).await;
|
||||||
|
|
||||||
// wait until genesis is complete
|
// wait until genesis is complete
|
||||||
while !serai
|
while serai
|
||||||
.as_of_latest_finalized_block()
|
.as_of_latest_finalized_block()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.genesis_liquidity()
|
.genesis_liquidity()
|
||||||
.genesis_complete()
|
.genesis_complete_block()
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
.is_none()
|
||||||
{
|
{
|
||||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,10 +82,6 @@ pub mod pallet {
|
||||||
pub(crate) type EconomicSecurityReached<T: Config> =
|
pub(crate) type EconomicSecurityReached<T: Config> =
|
||||||
StorageMap<_, Identity, NetworkId, bool, ValueQuery>;
|
StorageMap<_, Identity, NetworkId, bool, ValueQuery>;
|
||||||
|
|
||||||
// TODO: Find a better place for this
|
|
||||||
#[pallet::storage]
|
|
||||||
pub(crate) type GenesisCompleteBlock<T: Config> = StorageValue<_, u64, OptionQuery>;
|
|
||||||
|
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
pub(crate) type LastSwapVolume<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;
|
pub(crate) type LastSwapVolume<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;
|
||||||
|
|
||||||
|
@ -107,12 +103,6 @@ pub mod pallet {
|
||||||
#[pallet::hooks]
|
#[pallet::hooks]
|
||||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||||
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
|
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
|
||||||
if GenesisCompleteBlock::<T>::get().is_none() &&
|
|
||||||
GenesisLiquidity::<T>::genesis_complete().is_some()
|
|
||||||
{
|
|
||||||
GenesisCompleteBlock::<T>::set(Some(n.saturated_into::<u64>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// we wait 1 extra block after genesis ended to see the changes. We only need this extra
|
// we wait 1 extra block after genesis ended to see the changes. We only need this extra
|
||||||
// block in dev&test networks where we start the chain with accounts that already has some
|
// block in dev&test networks where we start the chain with accounts that already has some
|
||||||
// staked SRI. So when we check for ec-security pre-genesis we look like we are economically
|
// staked SRI. So when we check for ec-security pre-genesis we look like we are economically
|
||||||
|
@ -121,7 +111,7 @@ pub mod pallet {
|
||||||
// enough) is because ValidatorSets pallet runs before the genesis pallet in runtime.
|
// enough) is because ValidatorSets pallet runs before the genesis pallet in runtime.
|
||||||
// So ValidatorSets pallet sees the old state until next block.
|
// So ValidatorSets pallet sees the old state until next block.
|
||||||
// TODO: revisit this when mainnet genesis validator stake code is done.
|
// TODO: revisit this when mainnet genesis validator stake code is done.
|
||||||
let gcb = GenesisCompleteBlock::<T>::get();
|
let gcb = GenesisLiquidity::<T>::genesis_complete_block();
|
||||||
let genesis_ended = gcb.is_some() && (n.saturated_into::<u64>() > gcb.unwrap());
|
let genesis_ended = gcb.is_some() && (n.saturated_into::<u64>() > gcb.unwrap());
|
||||||
|
|
||||||
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
||||||
|
@ -339,7 +329,7 @@ pub mod pallet {
|
||||||
#[cfg(not(feature = "fast-epoch"))]
|
#[cfg(not(feature = "fast-epoch"))]
|
||||||
let initial_period_duration = 2 * MONTHS;
|
let initial_period_duration = 2 * MONTHS;
|
||||||
|
|
||||||
let genesis_complete_block = GenesisCompleteBlock::<T>::get();
|
let genesis_complete_block = GenesisLiquidity::<T>::genesis_complete_block();
|
||||||
genesis_complete_block.is_some() &&
|
genesis_complete_block.is_some() &&
|
||||||
(n.saturated_into::<u64>() < (genesis_complete_block.unwrap() + initial_period_duration))
|
(n.saturated_into::<u64>() < (genesis_complete_block.unwrap() + initial_period_duration))
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,8 +72,8 @@ pub mod pallet {
|
||||||
pub(crate) type Oracle<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;
|
pub(crate) type Oracle<T: Config> = StorageMap<_, Identity, Coin, u64, OptionQuery>;
|
||||||
|
|
||||||
#[pallet::storage]
|
#[pallet::storage]
|
||||||
#[pallet::getter(fn genesis_complete)]
|
#[pallet::getter(fn genesis_complete_block)]
|
||||||
pub(crate) type GenesisComplete<T: Config> = StorageValue<_, (), OptionQuery>;
|
pub(crate) type GenesisCompleteBlock<T: Config> = StorageValue<_, u64, OptionQuery>;
|
||||||
|
|
||||||
#[pallet::hooks]
|
#[pallet::hooks]
|
||||||
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
|
||||||
|
@ -87,7 +87,7 @@ pub mod pallet {
|
||||||
// Distribute the genesis sri to pools after a month
|
// Distribute the genesis sri to pools after a month
|
||||||
if (n.saturated_into::<u64>() >= final_block) &&
|
if (n.saturated_into::<u64>() >= final_block) &&
|
||||||
Self::oraclization_is_done() &&
|
Self::oraclization_is_done() &&
|
||||||
GenesisComplete::<T>::get().is_none()
|
GenesisCompleteBlock::<T>::get().is_none()
|
||||||
{
|
{
|
||||||
// mint the SRI
|
// mint the SRI
|
||||||
Coins::<T>::mint(
|
Coins::<T>::mint(
|
||||||
|
@ -167,7 +167,7 @@ pub mod pallet {
|
||||||
assert_eq!(Coins::<T>::balance(GENESIS_LIQUIDITY_ACCOUNT.into(), coin), Amount(0));
|
assert_eq!(Coins::<T>::balance(GENESIS_LIQUIDITY_ACCOUNT.into(), coin), Amount(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
GenesisComplete::<T>::set(Some(()));
|
GenesisCompleteBlock::<T>::set(Some(n.saturated_into::<u64>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
// we accept we reached economic security once we can mint smallest amount of a network's coin
|
||||||
|
|
Loading…
Reference in a new issue