Update Update and substrate_signers to [u8; 32] from Vec<u8>

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.
This commit is contained in:
Luke Parker 2023-08-24 13:24:52 -04:00
parent 506ded205a
commit 61418b4e9f
No known key found for this signature in database
3 changed files with 8 additions and 9 deletions

View file

@ -176,7 +176,7 @@ pub mod substrate {
#[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Zeroize, Serialize, Deserialize)]
pub enum ProcessorMessage { pub enum ProcessorMessage {
Update { key: Vec<u8>, batch: SignedBatch }, Update { key: [u8; 32], batch: SignedBatch },
} }
} }

View file

@ -158,7 +158,7 @@ struct TributaryMutable<N: Network, D: Db> {
// The safety of this follows as written above. // The safety of this follows as written above.
// TODO: There should only be one SubstrateSigner at a time (see #277) // TODO: There should only be one SubstrateSigner at a time (see #277)
substrate_signers: HashMap<Vec<u8>, SubstrateSigner<D>>, substrate_signers: HashMap<[u8; 32], SubstrateSigner<D>>,
} }
// Items which are mutably borrowed by Substrate. // Items which are mutably borrowed by Substrate.
@ -373,10 +373,9 @@ async fn handle_coordinator_msg<D: Db, N: Network, Co: Coordinator>(
// See TributaryMutable's struct definition for why this block is safe // See TributaryMutable's struct definition for why this block is safe
let KeyConfirmed { substrate_keys, network_keys } = let KeyConfirmed { substrate_keys, network_keys } =
tributary_mutable.key_gen.confirm(txn, set, key_pair).await; tributary_mutable.key_gen.confirm(txn, set, key_pair).await;
tributary_mutable.substrate_signers.insert( tributary_mutable
substrate_keys.group_key().to_bytes().to_vec(), .substrate_signers
SubstrateSigner::new(substrate_keys), .insert(substrate_keys.group_key().to_bytes(), SubstrateSigner::new(substrate_keys));
);
let key = network_keys.group_key(); let key = network_keys.group_key();
@ -520,7 +519,7 @@ async fn boot<N: Network, D: Db>(
let substrate_signer = SubstrateSigner::new(substrate_keys); 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 // We don't have to load any state for this since the Scanner will re-fire any events
// necessary // 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); let mut signer = Signer::new(network.clone(), network_keys);
@ -612,7 +611,7 @@ async fn run<N: Network, D: Db, Co: Coordinator>(mut raw_db: D, network: N, mut
SubstrateSignerEvent::SignedBatch(batch) => { SubstrateSignerEvent::SignedBatch(batch) => {
coordinator coordinator
.send(ProcessorMessage::Substrate(messages::substrate::ProcessorMessage::Update { .send(ProcessorMessage::Substrate(messages::substrate::ProcessorMessage::Update {
key: key.clone(), key: *key,
batch, batch,
})) }))
.await; .await;

View file

@ -125,7 +125,7 @@ pub(crate) async fn sign_batch(
key, key,
batch: this_batch, batch: this_batch,
}) => { }) => {
assert_eq!(&key, &id.key); assert_eq!(key.as_slice(), &id.key);
if batch.is_none() { if batch.is_none() {
assert!(PublicKey::from_raw(id.key.clone().try_into().unwrap()) assert!(PublicKey::from_raw(id.key.clone().try_into().unwrap())