Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
refactor: Remove sequence in pallet-cosmos
Browse files Browse the repository at this point in the history
  • Loading branch information
code0xff committed Sep 12, 2024
1 parent 4c9d0ec commit c540129
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 4 additions & 6 deletions frame/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ impl<T: Config> Pallet<T> {
let mut builder =
ValidTransactionBuilder::default().and_provides((origin, transaction_nonce));

let who = T::AddressMapping::into_account_id(origin);
let sequence = frame_system::Pallet::<T>::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))
}
Expand Down Expand Up @@ -497,9 +500,4 @@ impl<T: Config> Pallet<T> {
pays_fee: Pays::Yes,
})
}

pub fn sequence(address: &H160) -> u64 {
let account_id = T::AddressMapping::into_account_id(*address);
frame_system::Pallet::<T>::account_nonce(&account_id).saturated_into()
}
}
12 changes: 8 additions & 4 deletions frame/cosmos/x/auth/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(PhantomData<T>);
Expand Down Expand Up @@ -79,8 +82,9 @@ where
return Err(TransactionValidityError::Invalid(InvalidTransaction::BadSigner));
}

let sequence =
pallet_cosmos::Pallet::<T>::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::<T>::account_nonce(&who).saturated_into();

if signer_info.sequence > sequence {
return Err(TransactionValidityError::Invalid(InvalidTransaction::Future));
} else if signer_info.sequence < sequence {
Expand Down

0 comments on commit c540129

Please sign in to comment.