From 61418b4e9f6f92203e971a3928b0fe0385a6d8a3 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Thu, 24 Aug 2023 13:24:52 -0400 Subject: [PATCH] Update `Update` and substrate_signers to [u8; 32] from Vec A commit made while testing moved them from network-key-indexed to Substrate-key-indexed. Since Substrate keys have a fixed-length, fitting within the Copy boundary, there's no reason for it to not use an array. --- processor/messages/src/lib.rs | 2 +- processor/src/main.rs | 13 ++++++------- tests/processor/src/tests/batch.rs | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/processor/messages/src/lib.rs b/processor/messages/src/lib.rs index 17927ffb..c23bfe3d 100644 --- a/processor/messages/src/lib.rs +++ b/processor/messages/src/lib.rs @@ -176,7 +176,7 @@ pub mod substrate { #[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)] pub enum ProcessorMessage { - Update { key: Vec, batch: SignedBatch }, + Update { key: [u8; 32], batch: SignedBatch }, } } diff --git a/processor/src/main.rs b/processor/src/main.rs index 50385d86..d6dd00cb 100644 --- a/processor/src/main.rs +++ b/processor/src/main.rs @@ -158,7 +158,7 @@ struct TributaryMutable { // The safety of this follows as written above. // TODO: There should only be one SubstrateSigner at a time (see #277) - substrate_signers: HashMap, SubstrateSigner>, + substrate_signers: HashMap<[u8; 32], SubstrateSigner>, } // Items which are mutably borrowed by Substrate. @@ -373,10 +373,9 @@ async fn handle_coordinator_msg( // See TributaryMutable's struct definition for why this block is safe let KeyConfirmed { substrate_keys, network_keys } = tributary_mutable.key_gen.confirm(txn, set, key_pair).await; - tributary_mutable.substrate_signers.insert( - substrate_keys.group_key().to_bytes().to_vec(), - SubstrateSigner::new(substrate_keys), - ); + tributary_mutable + .substrate_signers + .insert(substrate_keys.group_key().to_bytes(), SubstrateSigner::new(substrate_keys)); let key = network_keys.group_key(); @@ -520,7 +519,7 @@ async fn boot( let substrate_signer = SubstrateSigner::new(substrate_keys); // We don't have to load any state for this since the Scanner will re-fire any events // necessary - substrate_signers.insert(substrate_key.to_bytes().to_vec(), substrate_signer); + substrate_signers.insert(substrate_key.to_bytes(), substrate_signer); let mut signer = Signer::new(network.clone(), network_keys); @@ -612,7 +611,7 @@ async fn run(mut raw_db: D, network: N, mut SubstrateSignerEvent::SignedBatch(batch) => { coordinator .send(ProcessorMessage::Substrate(messages::substrate::ProcessorMessage::Update { - key: key.clone(), + key: *key, batch, })) .await; diff --git a/tests/processor/src/tests/batch.rs b/tests/processor/src/tests/batch.rs index 25391524..41e0adf3 100644 --- a/tests/processor/src/tests/batch.rs +++ b/tests/processor/src/tests/batch.rs @@ -125,7 +125,7 @@ pub(crate) async fn sign_batch( key, batch: this_batch, }) => { - assert_eq!(&key, &id.key); + assert_eq!(key.as_slice(), &id.key); if batch.is_none() { assert!(PublicKey::from_raw(id.key.clone().try_into().unwrap())