From 240126637454539164f7110e6e53658ffadd7b9f Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Wed, 11 Oct 2023 02:10:35 -0400 Subject: [PATCH] Replace mutate with get + set I'm legitimately unsure why mutate doesn't work. Reading the impls, it should... --- substrate/in-instructions/pallet/src/lib.rs | 23 ++++++++++++--------- substrate/validator-sets/pallet/src/lib.rs | 9 ++++---- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/substrate/in-instructions/pallet/src/lib.rs b/substrate/in-instructions/pallet/src/lib.rs index 22e95467e..4c1adb2b4 100644 --- a/substrate/in-instructions/pallet/src/lib.rs +++ b/substrate/in-instructions/pallet/src/lib.rs @@ -80,7 +80,9 @@ pub mod pallet { } } - fn key_for_network(network: NetworkId) -> Result<(Session, Option, Option), InvalidTransaction> { + fn keys_for_network( + network: NetworkId, + ) -> Result<(Session, Option, Option), InvalidTransaction> { let session = ValidatorSets::::session(network); let mut set = ValidatorSet { session, network }; let latest = ValidatorSets::::keys(set).map(|keys| keys.0); @@ -146,9 +148,6 @@ pub mod pallet { Call::__Ignore(_, _) => unreachable!(), }; - let network = batch.batch.network; - let (current_session, prior, current) = key_for_network::(network)?; - // verify the batch size // TODO: Merge this encode with the one done by batch_message if batch.batch.encode().len() > MAX_BATCH_SIZE { @@ -156,15 +155,19 @@ pub mod pallet { } // verify the signature + let network = batch.batch.network; + let (current_session, prior, current) = keys_for_network::(network)?; let batch_message = batch_message(&batch.batch); // Check the prior key first since only a single `Batch` (the last one) will be when prior is // Some yet prior wasn't the signing key - let valid_by_prior = if let Some(key) = prior { - key.verify(&batch_message, &batch.signature) - } else { false }; - let valid = valid_by_prior || (if let Some(key) = current { - key.verify(&batch_message, &batch.signature) - } else { false }); + let valid_by_prior = + if let Some(key) = prior { key.verify(&batch_message, &batch.signature) } else { false }; + let valid = valid_by_prior || + (if let Some(key) = current { + key.verify(&batch_message, &batch.signature) + } else { + false + }); if !valid { Err(InvalidTransaction::BadProof)?; } diff --git a/substrate/validator-sets/pallet/src/lib.rs b/substrate/validator-sets/pallet/src/lib.rs index d71859c14..da319974b 100644 --- a/substrate/validator-sets/pallet/src/lib.rs +++ b/substrate/validator-sets/pallet/src/lib.rs @@ -169,10 +169,11 @@ pub mod pallet { fn new_set(network: NetworkId) { // Update CurrentSession let session = if network != NetworkId::Serai { - CurrentSession::::mutate(network, |session| { - Some(session.map(|session| Session(session.0 + 1)).unwrap_or(Session(0))) - }) - .unwrap() + let new_session = CurrentSession::::get(network) + .map(|session| Session(session.0 + 1)) + .unwrap_or(Session(0)); + CurrentSession::::set(network, Some(new_session)); + new_session } else { Self::session(network) };