mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 12:49:23 +00:00
Replace acknowledge_block with acknowledge_batch
This commit is contained in:
@@ -17,6 +17,9 @@ create_db!(
|
||||
// The next Batch ID to use
|
||||
NextBatchId: () -> u32,
|
||||
|
||||
// The block number which caused a batch
|
||||
BlockNumberForBatch: (batch: u32) -> u64,
|
||||
|
||||
// The return addresses for the InInstructions within a Batch
|
||||
SerializedReturnAddresses: (batch: u32) -> Vec<u8>,
|
||||
}
|
||||
@@ -39,12 +42,19 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
NextToPotentiallyReportBlock::get(getter)
|
||||
}
|
||||
|
||||
pub(crate) fn acquire_batch_id(txn: &mut impl DbTxn) -> u32 {
|
||||
pub(crate) fn acquire_batch_id(txn: &mut impl DbTxn, block_number: u64) -> u32 {
|
||||
let id = NextBatchId::get(txn).unwrap_or(0);
|
||||
NextBatchId::set(txn, &(id + 1));
|
||||
BlockNumberForBatch::set(txn, id, &block_number);
|
||||
id
|
||||
}
|
||||
|
||||
pub(crate) fn take_block_number_for_batch(txn: &mut impl DbTxn, id: u32) -> Option<u64> {
|
||||
let block_number = BlockNumberForBatch::get(txn, id)?;
|
||||
BlockNumberForBatch::del(txn, id);
|
||||
Some(block_number)
|
||||
}
|
||||
|
||||
pub(crate) fn save_return_information(
|
||||
txn: &mut impl DbTxn,
|
||||
id: u32,
|
||||
@@ -67,6 +77,7 @@ impl<S: ScannerFeed> ReportDb<S> {
|
||||
id: u32,
|
||||
) -> Option<Vec<Option<ReturnInformation<S>>>> {
|
||||
let buf = SerializedReturnAddresses::get(txn, id)?;
|
||||
SerializedReturnAddresses::del(txn, id);
|
||||
let mut buf = buf.as_slice();
|
||||
|
||||
let mut res = Vec::with_capacity(buf.len() / (32 + 1 + 8));
|
||||
|
||||
@@ -25,6 +25,13 @@ pub(crate) fn take_return_information<S: ScannerFeed>(
|
||||
ReportDb::<S>::take_return_information(txn, id)
|
||||
}
|
||||
|
||||
pub(crate) fn take_block_number_for_batch<S: ScannerFeed>(
|
||||
txn: &mut impl DbTxn,
|
||||
id: u32,
|
||||
) -> Option<u64> {
|
||||
ReportDb::<S>::take_block_number_for_batch(txn, id)
|
||||
}
|
||||
|
||||
/*
|
||||
This task produces Batches for notable blocks, with all InInstructions, in an ordered fashion.
|
||||
|
||||
@@ -89,7 +96,7 @@ impl<D: Db, S: ScannerFeed, B: BatchPublisher> ContinuallyRan for ReportTask<D,
|
||||
if notable {
|
||||
let network = S::NETWORK;
|
||||
let block_hash = index::block_id(&txn, b);
|
||||
let mut batch_id = ReportDb::<S>::acquire_batch_id(&mut txn);
|
||||
let mut batch_id = ReportDb::<S>::acquire_batch_id(&mut txn, b);
|
||||
|
||||
// start with empty batch
|
||||
let mut batches =
|
||||
@@ -110,7 +117,7 @@ impl<D: Db, S: ScannerFeed, B: BatchPublisher> ContinuallyRan for ReportTask<D,
|
||||
let in_instruction = batch.instructions.pop().unwrap();
|
||||
|
||||
// bump the id for the new batch
|
||||
batch_id = ReportDb::<S>::acquire_batch_id(&mut txn);
|
||||
batch_id = ReportDb::<S>::acquire_batch_id(&mut txn, b);
|
||||
|
||||
// make a new batch with this instruction included
|
||||
batches.push(Batch {
|
||||
|
||||
Reference in New Issue
Block a user