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<Preprocess>).
This would've been more efficient, yet also clunky due to the multiple usages
of the Preprocess message.
This commit is contained in:
Luke Parker 2023-04-20 15:19:10 -04:00
parent 70d866af6a
commit a404944b90
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View file

@ -134,6 +134,7 @@ pub mod coordinator {
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)]
pub enum ProcessorMessage { pub enum ProcessorMessage {
SubstrateBlockAck { block: u64, plans: Vec<[u8; 32]> },
BatchPreprocess { id: SignId, preprocess: Vec<u8> }, BatchPreprocess { id: SignId, preprocess: Vec<u8> },
BatchShare { id: SignId, share: [u8; 32] }, BatchShare { id: SignId, share: [u8; 32] },
} }
@ -151,6 +152,7 @@ pub mod substrate {
}, },
SubstrateBlock { SubstrateBlock {
context: SubstrateContext, context: SubstrateContext,
block: u64,
key: Vec<u8>, key: Vec<u8>,
burns: Vec<OutInstructionWithBalance>, burns: Vec<OutInstructionWithBalance>,
}, },

View file

@ -383,6 +383,7 @@ async fn handle_coordinator_msg<D: Db, C: Coin, Co: Coordinator>(
messages::substrate::CoordinatorMessage::SubstrateBlock { messages::substrate::CoordinatorMessage::SubstrateBlock {
context, context,
block,
key: key_vec, key: key_vec,
burns, burns,
} => { } => {
@ -422,6 +423,15 @@ async fn handle_coordinator_msg<D: Db, C: Coin, Co: Coordinator>(
.expect("key we don't have a scheduler for acknowledged a block") .expect("key we don't have a scheduler for acknowledged a block")
.schedule(outputs, payments); .schedule(outputs, payments);
coordinator
.send(ProcessorMessage::Coordinator(
messages::coordinator::ProcessorMessage::SubstrateBlockAck {
block,
plans: plans.iter().map(|plan| plan.id()).collect(),
},
))
.await;
sign_plans( sign_plans(
txn, txn,
coin, coin,