mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-09 04:39:24 +00:00
Embed the mempool into the Blockchain
This commit is contained in:
@@ -24,13 +24,21 @@ impl<T: Transaction> Mempool<T> {
|
||||
) -> bool {
|
||||
match tx.kind() {
|
||||
TransactionKind::Signed(Signed { signer, nonce, .. }) => {
|
||||
// If the mempool doesn't have a nonce tracked, grab it from the blockchain
|
||||
if !self.next_nonces.contains_key(signer) {
|
||||
let Some(blockchain_next_nonces) = blockchain_next_nonces.get(signer).cloned() else {
|
||||
// Not a participant
|
||||
return false;
|
||||
};
|
||||
self.next_nonces.insert(*signer, blockchain_next_nonces);
|
||||
// Get the nonce from the blockchain
|
||||
let Some(blockchain_next_nonce) = blockchain_next_nonces.get(signer).cloned() else {
|
||||
// Not a participant
|
||||
return false;
|
||||
};
|
||||
|
||||
// If the blockchain's nonce is greater than the mempool's, use it
|
||||
// Default to true so if the mempool hasn't tracked this nonce yet, it'll be inserted
|
||||
let mut blockchain_is_greater = true;
|
||||
if let Some(mempool_next_nonce) = self.next_nonces.get(signer) {
|
||||
blockchain_is_greater = blockchain_next_nonce > *mempool_next_nonce;
|
||||
}
|
||||
|
||||
if blockchain_is_greater {
|
||||
self.next_nonces.insert(*signer, blockchain_next_nonce);
|
||||
}
|
||||
|
||||
if verify_transaction(&tx, self.genesis, &mut HashSet::new(), &mut self.next_nonces)
|
||||
|
||||
Reference in New Issue
Block a user