Skip to content

Commit

Permalink
fix(oppool): use efficient pack length
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-miao committed Sep 15, 2023
1 parent da5400d commit 771977b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crates/rundler/src/op_pool/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use mockall::automock;
pub use reputation::{
HourlyMovingAverageReputation, Reputation, ReputationParams, ReputationStatus,
};
use rundler_types::{Entity, EntityType, UserOperation};
use rundler_types::{Entity, EntityType, UserOperation, USER_OPERATION_PACKED_LEN};
use strum::IntoEnumIterator;
use tonic::async_trait;

Expand Down Expand Up @@ -164,7 +164,7 @@ impl PoolOperation {
}

pub fn size(&self) -> usize {
self.uo.pack().len()
USER_OPERATION_PACKED_LEN
}

fn entity_address(&self, entity: EntityType) -> Option<Address> {
Expand Down
2 changes: 1 addition & 1 deletion crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! Rundler common types

mod user_operation;
pub use user_operation::UserOperationId;
pub use user_operation::{UserOperationId, USER_OPERATION_PACKED_LEN};

/// Generated contracts module
#[allow(non_snake_case)]
Expand Down
9 changes: 9 additions & 0 deletions crates/types/src/user_operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::{
UserOperation,
};

/// size of a packed user operation in bytes
pub const USER_OPERATION_PACKED_LEN: usize = 320;

/// Unique identifier for a user operation from a given sender
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct UserOperationId {
Expand Down Expand Up @@ -229,4 +232,10 @@ mod tests {
.unwrap()
);
}

#[test]
fn test_pack_len() {
let user_operation = UserOperation::default();
assert_eq!(user_operation.pack().len(), USER_OPERATION_PACKED_LEN);
}
}

0 comments on commit 771977b

Please sign in to comment.