mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Merge BlockWithAcknowledgedBatch and BatchWithoutAcknowledgeBatch
Offers a simpler API to the coordinator.
This commit is contained in:
@@ -31,6 +31,8 @@ tokio = { version = "1", default-features = false, features = ["rt-multi-thread"
|
||||
|
||||
serai-db = { path = "../../common/db" }
|
||||
|
||||
messages = { package = "serai-processor-messages", path = "../messages" }
|
||||
|
||||
serai-primitives = { path = "../../substrate/primitives", default-features = false, features = ["std"] }
|
||||
serai-in-instructions-primitives = { path = "../../substrate/in-instructions/primitives", default-features = false, features = ["std", "borsh"] }
|
||||
serai-coins-primitives = { path = "../../substrate/coins/primitives", default-features = false, features = ["std", "borsh"] }
|
||||
|
||||
@@ -429,9 +429,6 @@ impl<S: ScannerFeed> Scanner<S> {
|
||||
/// This means the specified Batch was ordered on Serai in relation to Burn events, and all
|
||||
/// validators have achieved synchrony on it.
|
||||
///
|
||||
/// `in_instruction_succeededs` is the result of executing each InInstruction within this batch,
|
||||
/// true if it succeeded and false if it did not (and did not cause any state changes on Serai).
|
||||
///
|
||||
/// `burns` is a list of Burns to queue with the acknowledgement of this Batch for efficiency's
|
||||
/// sake. Any Burns passed here MUST NOT be passed into any other call of `acknowledge_batch` nor
|
||||
/// `queue_burns`. Doing so will cause them to be executed multiple times.
|
||||
@@ -441,7 +438,7 @@ impl<S: ScannerFeed> Scanner<S> {
|
||||
&mut self,
|
||||
mut txn: impl DbTxn,
|
||||
batch_id: u32,
|
||||
in_instruction_succeededs: Vec<bool>,
|
||||
in_instruction_results: Vec<messages::substrate::InInstructionResult>,
|
||||
burns: Vec<OutInstructionWithBalance>,
|
||||
key_to_activate: Option<KeyFor<S>>,
|
||||
) {
|
||||
@@ -451,7 +448,7 @@ impl<S: ScannerFeed> Scanner<S> {
|
||||
substrate::queue_acknowledge_batch::<S>(
|
||||
&mut txn,
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
burns,
|
||||
key_to_activate,
|
||||
);
|
||||
|
||||
@@ -12,7 +12,7 @@ use crate::{ScannerFeed, KeyFor};
|
||||
#[derive(BorshSerialize, BorshDeserialize)]
|
||||
struct AcknowledgeBatchEncodable {
|
||||
batch_id: u32,
|
||||
in_instruction_succeededs: Vec<bool>,
|
||||
in_instruction_results: Vec<messages::substrate::InInstructionResult>,
|
||||
burns: Vec<OutInstructionWithBalance>,
|
||||
key_to_activate: Option<Vec<u8>>,
|
||||
}
|
||||
@@ -25,7 +25,7 @@ enum ActionEncodable {
|
||||
|
||||
pub(crate) struct AcknowledgeBatch<S: ScannerFeed> {
|
||||
pub(crate) batch_id: u32,
|
||||
pub(crate) in_instruction_succeededs: Vec<bool>,
|
||||
pub(crate) in_instruction_results: Vec<messages::substrate::InInstructionResult>,
|
||||
pub(crate) burns: Vec<OutInstructionWithBalance>,
|
||||
pub(crate) key_to_activate: Option<KeyFor<S>>,
|
||||
}
|
||||
@@ -46,7 +46,7 @@ impl<S: ScannerFeed> SubstrateDb<S> {
|
||||
pub(crate) fn queue_acknowledge_batch(
|
||||
txn: &mut impl DbTxn,
|
||||
batch_id: u32,
|
||||
in_instruction_succeededs: Vec<bool>,
|
||||
in_instruction_results: Vec<messages::substrate::InInstructionResult>,
|
||||
burns: Vec<OutInstructionWithBalance>,
|
||||
key_to_activate: Option<KeyFor<S>>,
|
||||
) {
|
||||
@@ -54,7 +54,7 @@ impl<S: ScannerFeed> SubstrateDb<S> {
|
||||
txn,
|
||||
&ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
burns,
|
||||
key_to_activate: key_to_activate.map(|key| key.to_bytes().as_ref().to_vec()),
|
||||
}),
|
||||
@@ -69,12 +69,12 @@ impl<S: ScannerFeed> SubstrateDb<S> {
|
||||
Some(match action_encodable {
|
||||
ActionEncodable::AcknowledgeBatch(AcknowledgeBatchEncodable {
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
burns,
|
||||
key_to_activate,
|
||||
}) => Action::AcknowledgeBatch(AcknowledgeBatch {
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
burns,
|
||||
key_to_activate: key_to_activate.map(|key| {
|
||||
let mut repr = <KeyFor<S> as GroupEncoding>::Repr::default();
|
||||
|
||||
@@ -16,14 +16,14 @@ use db::*;
|
||||
pub(crate) fn queue_acknowledge_batch<S: ScannerFeed>(
|
||||
txn: &mut impl DbTxn,
|
||||
batch_id: u32,
|
||||
in_instruction_succeededs: Vec<bool>,
|
||||
in_instruction_results: Vec<messages::substrate::InInstructionResult>,
|
||||
burns: Vec<OutInstructionWithBalance>,
|
||||
key_to_activate: Option<KeyFor<S>>,
|
||||
) {
|
||||
SubstrateDb::<S>::queue_acknowledge_batch(
|
||||
txn,
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
burns,
|
||||
key_to_activate,
|
||||
)
|
||||
@@ -67,7 +67,7 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SubstrateTask<D, S> {
|
||||
match action {
|
||||
Action::AcknowledgeBatch(AcknowledgeBatch {
|
||||
batch_id,
|
||||
in_instruction_succeededs,
|
||||
in_instruction_results,
|
||||
mut burns,
|
||||
key_to_activate,
|
||||
}) => {
|
||||
@@ -127,16 +127,16 @@ impl<D: Db, S: ScannerFeed> ContinuallyRan for SubstrateTask<D, S> {
|
||||
let return_information = report::take_return_information::<S>(&mut txn, batch_id)
|
||||
.expect("didn't save the return information for Batch we published");
|
||||
assert_eq!(
|
||||
in_instruction_succeededs.len(),
|
||||
in_instruction_results.len(),
|
||||
return_information.len(),
|
||||
"amount of InInstruction succeededs differed from amount of return information saved"
|
||||
);
|
||||
|
||||
// We map these into standard Burns
|
||||
for (succeeded, return_information) in
|
||||
in_instruction_succeededs.into_iter().zip(return_information)
|
||||
for (result, return_information) in
|
||||
in_instruction_results.into_iter().zip(return_information)
|
||||
{
|
||||
if succeeded {
|
||||
if result == messages::substrate::InInstructionResult::Succeeded {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user