diff --git a/frame/cosmos/src/lib.rs b/frame/cosmos/src/lib.rs index 08bbaa2..8131819 100644 --- a/frame/cosmos/src/lib.rs +++ b/frame/cosmos/src/lib.rs @@ -422,9 +422,12 @@ impl Pallet { let mut builder = ValidTransactionBuilder::default().and_provides((origin, transaction_nonce)); + let who = T::AddressMapping::into_account_id(origin); + let sequence = frame_system::Pallet::::account_nonce(&who).saturated_into(); + // In the context of the pool, a transaction with // too high a nonce is still considered valid - if transaction_nonce > Self::sequence(&origin) { + if transaction_nonce > sequence { if let Some(prev_nonce) = transaction_nonce.checked_sub(1) { builder = builder.and_requires((origin, prev_nonce)) } @@ -497,9 +500,4 @@ impl Pallet { pays_fee: Pays::Yes, }) } - - pub fn sequence(address: &H160) -> u64 { - let account_id = T::AddressMapping::into_account_id(*address); - frame_system::Pallet::::account_nonce(&account_id).saturated_into() - } } diff --git a/frame/cosmos/x/auth/src/sigverify.rs b/frame/cosmos/x/auth/src/sigverify.rs index fea03ef..9ed181a 100644 --- a/frame/cosmos/x/auth/src/sigverify.rs +++ b/frame/cosmos/x/auth/src/sigverify.rs @@ -35,8 +35,11 @@ use pallet_cosmos_x_auth_signing::{ }; use ripemd::Digest; use sp_core::{sha2_256, Get, H160}; -use sp_runtime::transaction_validity::{ - InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, +use sp_runtime::{ + transaction_validity::{ + InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction, + }, + SaturatedConversion, }; pub struct SigVerificationDecorator(PhantomData); @@ -79,8 +82,9 @@ where return Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner)); } - let sequence = - pallet_cosmos::Pallet::::sequence(&H160::from_slice(&signer_addr_raw)); + let who = T::AddressMapping::into_account_id(H160::from_slice(&signer_addr_raw)); + let sequence = frame_system::Pallet::::account_nonce(&who).saturated_into(); + if signer_info.sequence > sequence { return Err(TransactionValidityError::Invalid(InvalidTransaction::Future)); } else if signer_info.sequence < sequence {