Implement block emissions (#551)

* add genesis liquidity implementation

* add missing deposit event

* fix CI issues

* minor fixes

* make math safer

* fix fmt

* implement block emissions

* make remove liquidity an authorized call

* implement setting initial values for coins

* add genesis liquidity test & misc fixes

* updato develop latest

* fix rotation test

* fix licencing

* add fast-epoch feature

* only create the pool when adding liquidity first time

* add initial reward era test

* test whole pre ec security emissions

* fix clippy

* add swap-to-staked-sri feature

* rebase changes

* fix tests

* Remove accidentally commited ETH ABI files

* fix some pr comments

* Finish up fixing pr comments

* exclude SRI from is_allowed check

* Misc changes

---------

Co-authored-by: akildemir <aeg_asd@hotmail.com>
Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
akildemir
2024-08-15 06:12:04 +03:00
committed by GitHub
parent bf1c493d9a
commit cccc1fc7e6
36 changed files with 1279 additions and 302 deletions

View File

@@ -6,7 +6,9 @@ use sp_core::{
};
use serai_client::{
primitives::{NETWORKS, NetworkId, BlockHash, insecure_pair_from_name},
primitives::{
NETWORKS, NetworkId, BlockHash, insecure_pair_from_name, FAST_EPOCH_DURATION, TARGET_BLOCK_TIME,
},
validator_sets::{
primitives::{Session, ValidatorSet, KeyPair},
ValidatorSetsEvent,
@@ -326,22 +328,25 @@ async fn verify_session_and_active_validators(
session: u32,
participants: &[Public],
) {
// wait until the active session. This wait should be max 30 secs since the epoch time.
let block = tokio::time::timeout(core::time::Duration::from_secs(2 * 60), async move {
loop {
let mut block = serai.latest_finalized_block_hash().await.unwrap();
if session_for_block(serai, block, network).await < session {
// Sleep a block
tokio::time::sleep(core::time::Duration::from_secs(6)).await;
continue;
// wait until the active session.
let block = tokio::time::timeout(
core::time::Duration::from_secs(FAST_EPOCH_DURATION * TARGET_BLOCK_TIME * 2),
async move {
loop {
let mut block = serai.latest_finalized_block_hash().await.unwrap();
if session_for_block(serai, block, network).await < session {
// Sleep a block
tokio::time::sleep(core::time::Duration::from_secs(TARGET_BLOCK_TIME)).await;
continue;
}
while session_for_block(serai, block, network).await > session {
block = serai.block(block).await.unwrap().unwrap().header.parent_hash.0;
}
assert_eq!(session_for_block(serai, block, network).await, session);
break block;
}
while session_for_block(serai, block, network).await > session {
block = serai.block(block).await.unwrap().unwrap().header.parent_hash.0;
}
assert_eq!(session_for_block(serai, block, network).await, session);
break block;
}
})
},
)
.await
.unwrap();
let serai_for_block = serai.as_of(block);
@@ -358,10 +363,10 @@ async fn verify_session_and_active_validators(
// make sure finalization continues as usual after the changes
let current_finalized_block = serai.latest_finalized_block().await.unwrap().header.number;
tokio::time::timeout(core::time::Duration::from_secs(60), async move {
tokio::time::timeout(core::time::Duration::from_secs(TARGET_BLOCK_TIME * 10), async move {
let mut finalized_block = serai.latest_finalized_block().await.unwrap().header.number;
while finalized_block <= current_finalized_block + 2 {
tokio::time::sleep(core::time::Duration::from_secs(6)).await;
tokio::time::sleep(core::time::Duration::from_secs(TARGET_BLOCK_TIME)).await;
finalized_block = serai.latest_finalized_block().await.unwrap().header.number;
}
})