Have the scanner's report task ensure handovers only occur if Batchs are valid

This is incomplete at this time. The logic is fine, but needs to be moved to a
distinct location to handle singular blocks which produce multiple Batches.
This commit is contained in:
Luke Parker
2024-12-30 06:11:47 -05:00
parent 5b74fc8ac1
commit 445c49f030
4 changed files with 95 additions and 2 deletions

View File

@@ -40,6 +40,12 @@ pub(crate) enum Action<S: ScannerFeed> {
QueueBurns(Vec<OutInstructionWithBalance>),
}
create_db!(
ScannerSubstrate {
LastAcknowledgedBatch: () -> u32,
}
);
db_channel!(
ScannerSubstrate {
Actions: () -> ActionEncodable,
@@ -48,6 +54,14 @@ db_channel!(
pub(crate) struct SubstrateDb<S: ScannerFeed>(PhantomData<S>);
impl<S: ScannerFeed> SubstrateDb<S> {
pub(crate) fn last_acknowledged_batch(getter: &impl Get) -> Option<u32> {
LastAcknowledgedBatch::get(getter)
}
pub(crate) fn set_last_acknowledged_batch(txn: &mut impl DbTxn, id: u32) {
LastAcknowledgedBatch::set(txn, &id)
}
pub(crate) fn queue_acknowledge_batch(
txn: &mut impl DbTxn,
batch_id: u32,

View File

@@ -1,6 +1,6 @@
use core::{marker::PhantomData, future::Future};
use serai_db::{DbTxn, Db};
use serai_db::{Get, DbTxn, Db};
use serai_coins_primitives::{OutInstruction, OutInstructionWithBalance};
use serai_validator_sets_primitives::Session;
@@ -14,6 +14,9 @@ use crate::{
mod db;
use db::*;
pub(crate) fn last_acknowledged_batch<S: ScannerFeed>(getter: &impl Get) -> Option<u32> {
SubstrateDb::<S>::last_acknowledged_batch(getter)
}
pub(crate) fn queue_acknowledge_batch<S: ScannerFeed>(
txn: &mut impl DbTxn,
batch_id: u32,
@@ -99,6 +102,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SubstrateTask<D, S> {
"batch acknowledged on-chain was distinct"
);
SubstrateDb::<S>::set_last_acknowledged_batch(&mut txn, batch_id);
AcknowledgedBatches::send(
&mut txn,
&external_key_for_session_to_sign_batch.0,