mirror of
https://github.com/serai-dex/serai.git
synced 2025-01-03 17:40:34 +00:00
Have the Coordinator scan the Substrate genesis block
Also adds a workflow for running tests/coordinator.
This commit is contained in:
parent
d5c787fea2
commit
aab8a417db
6 changed files with 56 additions and 11 deletions
44
.github/workflows/coordinator-tests.yml
vendored
Normal file
44
.github/workflows/coordinator-tests.yml
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
name: Coordinator Tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- develop
|
||||||
|
paths:
|
||||||
|
- "common/**"
|
||||||
|
- "crypto/**"
|
||||||
|
- "coins/**"
|
||||||
|
- "message-queue/**"
|
||||||
|
- "orchestration/message-queue/**"
|
||||||
|
- "coordinator/**"
|
||||||
|
- "orchestration/coordinator/**"
|
||||||
|
- "tests/docker/**"
|
||||||
|
- "tests/coordinator/**"
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- "common/**"
|
||||||
|
- "crypto/**"
|
||||||
|
- "coins/**"
|
||||||
|
- "message-queue/**"
|
||||||
|
- "orchestration/message-queue/**"
|
||||||
|
- "coordinator/**"
|
||||||
|
- "orchestration/coordinator/**"
|
||||||
|
- "tests/docker/**"
|
||||||
|
- "tests/coordinator/**"
|
||||||
|
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install Build Dependencies
|
||||||
|
uses: ./.github/actions/build-dependencies
|
||||||
|
with:
|
||||||
|
github-token: ${{ inputs.github-token }}
|
||||||
|
|
||||||
|
- name: Run coordinator Docker tests
|
||||||
|
run: cd tests/coordinator && GITHUB_CI=true cargo test
|
|
@ -107,7 +107,7 @@ pub async fn scan_substrate<D: Db, Pro: Processors>(
|
||||||
log::info!("scanning substrate");
|
log::info!("scanning substrate");
|
||||||
|
|
||||||
let mut db = substrate::SubstrateDb::new(db);
|
let mut db = substrate::SubstrateDb::new(db);
|
||||||
let mut last_substrate_block = db.last_block();
|
let mut next_substrate_block = db.next_block();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match substrate::handle_new_blocks(
|
match substrate::handle_new_blocks(
|
||||||
|
@ -126,7 +126,7 @@ pub async fn scan_substrate<D: Db, Pro: Processors>(
|
||||||
},
|
},
|
||||||
&processors,
|
&processors,
|
||||||
&serai,
|
&serai,
|
||||||
&mut last_substrate_block,
|
&mut next_substrate_block,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,12 +14,12 @@ impl<D: Db> SubstrateDb<D> {
|
||||||
fn block_key() -> Vec<u8> {
|
fn block_key() -> Vec<u8> {
|
||||||
Self::substrate_key(b"block", [])
|
Self::substrate_key(b"block", [])
|
||||||
}
|
}
|
||||||
pub fn set_last_block(&mut self, block: u64) {
|
pub fn set_next_block(&mut self, block: u64) {
|
||||||
let mut txn = self.0.txn();
|
let mut txn = self.0.txn();
|
||||||
txn.put(Self::block_key(), block.to_le_bytes());
|
txn.put(Self::block_key(), block.to_le_bytes());
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
pub fn last_block(&self) -> u64 {
|
pub fn next_block(&self) -> u64 {
|
||||||
u64::from_le_bytes(self.0.get(Self::block_key()).unwrap_or(vec![0; 8]).try_into().unwrap())
|
u64::from_le_bytes(self.0.get(Self::block_key()).unwrap_or(vec![0; 8]).try_into().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -302,17 +302,17 @@ pub async fn handle_new_blocks<
|
||||||
create_new_tributary: CNT,
|
create_new_tributary: CNT,
|
||||||
processors: &Pro,
|
processors: &Pro,
|
||||||
serai: &Serai,
|
serai: &Serai,
|
||||||
last_block: &mut u64,
|
next_block: &mut u64,
|
||||||
) -> Result<(), SeraiError> {
|
) -> Result<(), SeraiError> {
|
||||||
// Check if there's been a new Substrate block
|
// Check if there's been a new Substrate block
|
||||||
let latest = serai.get_latest_block().await?;
|
let latest = serai.get_latest_block().await?;
|
||||||
let latest_number = latest.number();
|
let latest_number = latest.number();
|
||||||
if latest_number == *last_block {
|
if latest_number < *next_block {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mut latest = Some(latest);
|
let mut latest = Some(latest);
|
||||||
|
|
||||||
for b in (*last_block + 1) ..= latest_number {
|
for b in *next_block ..= latest_number {
|
||||||
log::info!("found substrate block {b}");
|
log::info!("found substrate block {b}");
|
||||||
handle_block(
|
handle_block(
|
||||||
db,
|
db,
|
||||||
|
@ -330,8 +330,8 @@ pub async fn handle_new_blocks<
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
*last_block += 1;
|
*next_block += 1;
|
||||||
db.set_last_block(*last_block);
|
db.set_next_block(*next_block);
|
||||||
log::info!("handled substrate block {b}");
|
log::info!("handled substrate block {b}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,9 @@ use ciphersuite::{group::ff::PrimeField, Ciphersuite, Ristretto};
|
||||||
|
|
||||||
use serai_client::primitives::NetworkId;
|
use serai_client::primitives::NetworkId;
|
||||||
|
|
||||||
use dockertest::{PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition};
|
use dockertest::{
|
||||||
|
PullPolicy, Image, LogAction, LogPolicy, LogSource, LogOptions, StartPolicy, Composition,
|
||||||
|
};
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
|
@ -30,7 +30,6 @@ fn new_test() -> (Vec<(Handles, <Ristretto as Ciphersuite>::F)>, DockerTest) {
|
||||||
(coordinators, test)
|
(coordinators, test)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stack_test() {
|
fn stack_test() {
|
||||||
let (_coordinators, test) = new_test();
|
let (_coordinators, test) = new_test();
|
||||||
|
|
Loading…
Reference in a new issue