Skip to content

Commit

Permalink
chore: small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shunsukew committed Nov 5, 2024
1 parent d4c23aa commit 8356075
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
33 changes: 19 additions & 14 deletions crates/builder/src/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,13 +1380,7 @@ impl<UO: UserOperation> ProposalContext<UO> {
let is_sender_staked = entity_infos.sender.is_staked;
if is_factory_staked || is_sender_staked {
if let Some(paymaster) = entity_infos.paymaster {
self.entity_updates.insert(
paymaster.address(),
EntityUpdate {
entity: paymaster.entity,
update_type: EntityUpdateType::PaymasterAmendment,
},
);
self.add_erep_015_paymaster_amendment(paymaster.entity)
}
}

Expand Down Expand Up @@ -1489,13 +1483,7 @@ impl<UO: UserOperation> ProposalContext<UO> {

if paymaster_ammendment_required {
if let Some(paymaster) = entity_infos.paymaster {
self.entity_updates.insert(
paymaster.address(),
EntityUpdate {
entity: paymaster.entity,
update_type: EntityUpdateType::PaymasterAmendment,
},
);
self.add_erep_015_paymaster_amendment(paymaster.entity)
};
}
}
Expand Down Expand Up @@ -1559,6 +1547,23 @@ impl<UO: UserOperation> ProposalContext<UO> {
}
}
}

fn add_erep_015_paymaster_amendment(&mut self, entity: Entity) {
if !entity.is_paymaster() {
warn!(
"Attempted to add EREP-015 paymaster amendment for non-paymaster entity: {:?}",
entity
);
return;
}
self.entity_updates.insert(
entity.address,
EntityUpdate {
entity,
update_type: EntityUpdateType::PaymasterAmendment,
},
);
}
}

#[cfg(test)]
Expand Down
11 changes: 9 additions & 2 deletions crates/pool/src/mempool/uo_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rundler_types::{
use rundler_utils::emit::WithEntryPoint;
use tokio::sync::broadcast;
use tonic::async_trait;
use tracing::info;
use tracing::{info, warn};

use super::{
paymaster::PaymasterTracker, pool::PoolInner, reputation::AddressReputation, Mempool,
Expand Down Expand Up @@ -733,7 +733,14 @@ where
self.reputation.handle_srep_050_penalty(entity.address);
}
EntityUpdateType::PaymasterAmendment => {
self.reputation.remove_seen(entity.address);
if entity.is_paymaster() {
self.reputation.remove_seen(entity.address);
} else {
warn!(
"Received paymaster amendment for non-paymaster entity: {:?}",
entity
);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions crates/types/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl Entity {
Self::new(EntityType::Paymaster, address)
}

/// Check if the entity is a paymaster
pub fn is_paymaster(&self) -> bool {
self.kind == EntityType::Paymaster
}

/// Create a new aggregator entity at address
pub fn aggregator(address: Address) -> Self {
Self::new(EntityType::Aggregator, address)
Expand Down

0 comments on commit 8356075

Please sign in to comment.