From a404944b90db4ad118ecf340759619d732c602b2 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 20 Apr 2023 15:19:10 -0400 Subject: [PATCH] Add a SubstrateBlockAck message to the processor When a Substrate block occurs, the coordinator is expected to emit SubstrateBlock. This causes the processor to begin a variety of plans. The processor now emits SubstrateBlockAck, explicitly listing all plan IDs, before starting signing. This lets the coordinator provide a SubstrateBlock transaction, and with it, recognize all plan IDs as valid. Prior, we would've had to have a spotty algorithm based upon the upcoming Preprocess messages, or if we immediately provided the SubstrateBlock transaction, then wait for the processor to inform us of the contained plans. This creates an explicitly proper async flow not reliant on waiting for data availability. Alternatively, we could've replaced Preprocess with (Block, Vec). This would've been more efficient, yet also clunky due to the multiple usages of the Preprocess message. --- processor/messages/src/lib.rs | 2 ++ processor/src/main.rs | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/processor/messages/src/lib.rs b/processor/messages/src/lib.rs index b07f79a0..73b187c1 100644 --- a/processor/messages/src/lib.rs +++ b/processor/messages/src/lib.rs @@ -134,6 +134,7 @@ pub mod coordinator { #[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)] pub enum ProcessorMessage { + SubstrateBlockAck { block: u64, plans: Vec<[u8; 32]> }, BatchPreprocess { id: SignId, preprocess: Vec }, BatchShare { id: SignId, share: [u8; 32] }, } @@ -151,6 +152,7 @@ pub mod substrate { }, SubstrateBlock { context: SubstrateContext, + block: u64, key: Vec, burns: Vec, }, diff --git a/processor/src/main.rs b/processor/src/main.rs index 79362116..d39ea9cb 100644 --- a/processor/src/main.rs +++ b/processor/src/main.rs @@ -383,6 +383,7 @@ async fn handle_coordinator_msg( messages::substrate::CoordinatorMessage::SubstrateBlock { context, + block, key: key_vec, burns, } => { @@ -422,6 +423,15 @@ async fn handle_coordinator_msg( .expect("key we don't have a scheduler for acknowledged a block") .schedule(outputs, payments); + coordinator + .send(ProcessorMessage::Coordinator( + messages::coordinator::ProcessorMessage::SubstrateBlockAck { + block, + plans: plans.iter().map(|plan| plan.id()).collect(), + }, + )) + .await; + sign_plans( txn, coin,