Flesh out eventuality task

This commit is contained in:
Luke Parker
2024-08-24 23:43:31 -04:00
parent 945f31dfc7
commit 379780a3c9
11 changed files with 174 additions and 29 deletions

View File

@@ -3,7 +3,8 @@ use serai_db::{Db, DbTxn};
use serai_primitives::BlockHash;
use serai_in_instructions_primitives::{MAX_BATCH_SIZE, Batch};
use primitives::{Id, OutputType, Block};
use primitives::ReceivedOutput;
// TODO: Localize to ReportDb?
use crate::{db::ScannerDb, ScannerFeed, ContinuallyRan};
@@ -48,8 +49,20 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for ReportTask<D, S> {
// If this block is notable, create the Batch(s) for it
if ScannerDb::<S>::is_block_notable(&txn, b) {
let in_instructions = ScannerDb::<S>::in_instructions(&txn, b)
.expect("reporting block which didn't set its InInstructions");
let in_instructions = {
let mut in_instructions = ScannerDb::<S>::in_instructions(&txn, b)
.expect("reporting block which didn't set its InInstructions");
// Sort these before reporting them in case anything we did is non-deterministic/to have
// a well-defined order (not implicit to however we got this result, enabling different
// methods to be used in the future)
in_instructions.sort_by(|a, b| {
use core::cmp::{Ordering, Ord};
let res = a.output.id().as_ref().cmp(&b.output.id().as_ref());
assert!(res != Ordering::Equal);
res
});
in_instructions
};
let network = S::NETWORK;
let block_hash =