Skip to content

Commit

Permalink
Txqueue track transferdomain nonce (#2421)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jouzo authored Sep 6, 2023
1 parent d7697ce commit 7224b45
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/ain-evm/src/txqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use rand::Rng;
use crate::{
core::XHash,
receipt::Receipt,
transaction::{system::SystemTx, SignedTx},
transaction::{
system::{SystemTx, TransferDomainData},
SignedTx,
},
};

type Result<T> = std::result::Result<T, QueueError>;
Expand Down Expand Up @@ -269,15 +272,21 @@ impl TransactionQueue {

pub fn queue_tx(&self, tx: QueueTx, tx_hash: XHash, gas_used: U256) -> Result<()> {
let mut data = self.data.lock().unwrap();
if let QueueTx::SignedTx(signed_tx) = &tx {
if let Some(nonce) = data.account_nonces.get(&signed_tx.sender) {
if signed_tx.nonce() != nonce + 1 {
return Err(QueueError::InvalidNonce((signed_tx.clone(), *nonce)));
match &tx {
QueueTx::SignedTx(signed_tx)
| QueueTx::SystemTx(SystemTx::TransferDomain(TransferDomainData {
signed_tx, ..
})) => {
if let Some(nonce) = data.account_nonces.get(&signed_tx.sender) {
if signed_tx.nonce() != nonce + 1 {
return Err(QueueError::InvalidNonce((signed_tx.clone(), *nonce)));
}
}
data.account_nonces
.insert(signed_tx.sender, signed_tx.nonce());
data.total_gas_used += gas_used;
}
data.account_nonces
.insert(signed_tx.sender, signed_tx.nonce());
data.total_gas_used += gas_used;
_ => (),
}
data.transactions.push(QueueTxItem {
tx,
Expand Down

0 comments on commit 7224b45

Please sign in to comment.