Skip to content

Commit

Permalink
feat(remove-ops): get by id when mined
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfourzerofour committed Nov 10, 2023
1 parent b6a0726 commit 95c0646
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
28 changes: 14 additions & 14 deletions crates/pool/src/mempool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use super::{
size::SizeTracker,
PoolConfig, PoolOperation,
};
use crate::chain::MinedOp;

#[derive(Debug, Clone)]
pub(crate) struct PoolInnerConfig {
Expand Down Expand Up @@ -152,9 +153,20 @@ impl PoolInner {

pub(crate) fn mine_operation(
&mut self,
hash: H256,
mined_op: &MinedOp,
block_number: u64,
) -> Option<Arc<PoolOperation>> {
let id = UserOperationId {
sender: mined_op.sender,
nonce: mined_op.nonce,
};

let tx_in_pool = self.by_id.get(&id)?;

let hash = tx_in_pool
.uo()
.op_hash(mined_op.entry_point, self.config.chain_id);

let ret = self.remove_operation_internal(hash, Some(block_number));
self.update_metrics();
ret
Expand Down Expand Up @@ -309,19 +321,7 @@ impl PoolInner {
self.decrement_address_count(e.address);
}

let mut removed_op_size = op.mem_size();

self.by_hash.retain(|_, existing_op| {
let remove_condition = existing_op.po.uo.id().eq(&op.po.uo.id());

if remove_condition {
removed_op_size += existing_op.mem_size();
self.best.remove(existing_op);
}
!remove_condition
});

self.pool_size -= removed_op_size;
self.pool_size -= op.mem_size();
Some(op.po)
}

Expand Down
6 changes: 2 additions & 4 deletions crates/pool/src/mempool/uo_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,8 @@ where

// Remove throttled ops that were included in the block
state.throttled_ops.remove(&op.hash);
if let Some(op) = state
.pool
.mine_operation(op.hash, update.latest_block_number)
{

if let Some(op) = state.pool.mine_operation(op, update.latest_block_number) {
// Only account for a staked entity once
for entity_addr in op.staked_entities().map(|e| e.address).unique() {
self.reputation.add_included(entity_addr);
Expand Down
6 changes: 4 additions & 2 deletions crates/types/src/user_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ const PACKED_USER_OPERATION_FIXED_LEN: usize = 480;
/// Unique identifier for a user operation from a given sender
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct UserOperationId {
sender: Address,
nonce: U256,
/// sender of user operation
pub sender: Address,
/// nonce of user operation
pub nonce: U256,
}

impl UserOperation {
Expand Down

0 comments on commit 95c0646

Please sign in to comment.