Add Batch messages from processor, verify Batchs published on-chain

Renames Update to SignedBatch.

Checks Batch equality via a hash of the InInstructions. That prevents needing
to keep the Batch in node state or TX introspect.
This commit is contained in:
Luke Parker
2023-09-29 03:51:01 -04:00
parent 0be567ff69
commit 0eff3d9453
18 changed files with 281 additions and 80 deletions

View File

@@ -8,7 +8,7 @@ use serde::{Serialize, Deserialize};
use dkg::{Participant, ThresholdParams};
use serai_primitives::{BlockHash, NetworkId};
use in_instructions_primitives::SignedBatch;
use in_instructions_primitives::{Batch, SignedBatch};
use tokens_primitives::OutInstructionWithBalance;
use validator_sets_primitives::{ValidatorSet, KeyPair};
@@ -178,7 +178,8 @@ pub mod substrate {
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, Encode, Decode, Serialize, Deserialize)]
pub enum ProcessorMessage {
Update { batch: SignedBatch },
Batch { batch: Batch },
SignedBatch { batch: SignedBatch },
}
}
@@ -364,8 +365,9 @@ impl ProcessorMessage {
ProcessorMessage::Substrate(msg) => {
let (sub, id) = match msg {
// Unique since network and ID binding
substrate::ProcessorMessage::Update { batch, .. } => {
(0, (batch.batch.network, batch.batch.id).encode())
substrate::ProcessorMessage::Batch { batch } => (0, (batch.network, batch.id).encode()),
substrate::ProcessorMessage::SignedBatch { batch, .. } => {
(1, (batch.batch.network, batch.batch.id).encode())
}
};

View File

@@ -530,6 +530,12 @@ async fn run<N: Network, D: Db, Co: Coordinator>(mut raw_db: D, network: N, mut
for batch in batches {
info!("created batch {} ({} instructions)", batch.id, batch.instructions.len());
coordinator.send(
messages::ProcessorMessage::Substrate(
messages::substrate::ProcessorMessage::Batch { batch: batch.clone() }
)
).await;
if let Some(substrate_signer) = tributary_mutable.substrate_signer.as_mut() {
substrate_signer.sign(txn, batch).await;
}
@@ -588,9 +594,9 @@ async fn run<N: Network, D: Db, Co: Coordinator>(mut raw_db: D, network: N, mut
}
SubstrateSignerEvent::SignedBatch(batch) => {
coordinator
.send(ProcessorMessage::Substrate(messages::substrate::ProcessorMessage::Update {
batch,
}))
.send(ProcessorMessage::Substrate(
messages::substrate::ProcessorMessage::SignedBatch { batch },
))
.await;
}
}

View File

@@ -694,6 +694,7 @@ impl<N: Network, D: Db> Scanner<N, D> {
return;
}
// Since we're creating a Batch, mark it as needing ack
scanner.need_ack.push_back(block_being_scanned);
true
} else {
@@ -706,7 +707,7 @@ impl<N: Network, D: Db> Scanner<N, D> {
scanner.eventualities.remove(retired.to_bytes().as_ref());
}
// Update ram_scanned/need_ack
// Update ram_scanned
scanner.ram_scanned = Some(block_being_scanned);
drop(scanner_lock);