Skip to content

Commit 0ae9635

Browse files
committed
spike
1 parent 857899b commit 0ae9635

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

crates/bundle-pool/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tracing::error;
88

99
pub use pool::{BundleStore, InMemoryBundlePool};
1010
pub use source::KafkaBundleSource;
11-
pub use tips_core::{Bundle, BundleHash, BundleWithMetadata, CancelBundle};
11+
pub use tips_core::{Bundle, BundleWithMetadata, CancelBundle};
1212

1313
pub fn connect_sources_to_pool<S, P>(
1414
sources: Vec<S>,

crates/core/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ pub mod types;
66
pub mod test_utils;
77

88
pub use types::{
9-
BLOCK_TIME, Bundle, BundleHash, BundleWithMetadata, CancelBundle, MeterBundleResponse,
9+
BLOCK_TIME, Bundle, BundleHash, BundleProperties, BundleWithMetadata, CancelBundle,
10+
MeterBundleResponse,
1011
};

crates/core/src/types.rs

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ use uuid::Uuid;
1010
/// Block time in microseconds
1111
pub const BLOCK_TIME: u128 = 2_000_000;
1212

13+
pub trait BundleProperties {
14+
fn bundle_hash(&self) -> B256;
15+
}
16+
1317
#[derive(Default, Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
1418
#[serde(rename_all = "camelCase")]
1519
pub struct Bundle {
@@ -56,6 +60,26 @@ pub struct Bundle {
5660
pub dropping_tx_hashes: Vec<TxHash>,
5761
}
5862

63+
impl BundleProperties for Bundle {
64+
fn bundle_hash(&self) -> B256 {
65+
let transactions: Vec<OpTxEnvelope> = self
66+
.txs
67+
.iter()
68+
.map(|b| {
69+
OpTxEnvelope::decode_2718_exact(b)
70+
.map_err(|e| format!("failed to decode transaction: {e}"))
71+
})
72+
.collect::<Result<Vec<_>, _>>()
73+
.expect("failed to decode transactions");
74+
75+
let mut concatenated = Vec::new();
76+
for tx in transactions {
77+
concatenated.extend_from_slice(tx.tx_hash().as_slice());
78+
}
79+
keccak256(&concatenated)
80+
}
81+
}
82+
5983
#[derive(Debug, Clone, Serialize, Deserialize)]
6084
#[serde(rename_all = "camelCase")]
6185
pub struct BundleHash {
@@ -115,14 +139,6 @@ impl BundleWithMetadata {
115139
&self.uuid
116140
}
117141

118-
pub fn bundle_hash(&self) -> B256 {
119-
let mut concatenated = Vec::new();
120-
for tx in self.transactions() {
121-
concatenated.extend_from_slice(tx.tx_hash().as_slice());
122-
}
123-
keccak256(&concatenated)
124-
}
125-
126142
pub fn txn_hashes(&self) -> Vec<TxHash> {
127143
self.transactions().iter().map(|t| t.tx_hash()).collect()
128144
}
@@ -150,6 +166,12 @@ impl BundleWithMetadata {
150166
}
151167
}
152168

169+
impl BundleProperties for BundleWithMetadata {
170+
fn bundle_hash(&self) -> B256 {
171+
self.bundle.bundle_hash()
172+
}
173+
}
174+
153175
#[derive(Debug, Clone, Serialize, Deserialize)]
154176
#[serde(rename_all = "camelCase")]
155177
pub struct TransactionResult {

crates/ingress-rpc/src/queue.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ impl QueuePublisher for KafkaQueuePublisher {
7575
mod tests {
7676
use super::*;
7777
use rdkafka::config::ClientConfig;
78-
use tips_core::{Bundle, BundleWithMetadata, test_utils::create_test_meter_bundle_response};
78+
use tips_core::{
79+
Bundle, BundleProperties, BundleWithMetadata, test_utils::create_test_meter_bundle_response,
80+
};
7981
use tokio::time::{Duration, Instant};
8082

8183
fn create_test_bundle() -> Bundle {

crates/ingress-rpc/src/service.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use reth_rpc_eth_types::EthApiError;
1212
use std::time::{SystemTime, UNIX_EPOCH};
1313
use tips_audit::{BundleEvent, BundleEventPublisher};
1414
use tips_core::{
15-
BLOCK_TIME, Bundle, BundleHash, BundleWithMetadata, CancelBundle, MeterBundleResponse,
15+
BLOCK_TIME, Bundle, BundleHash, BundleProperties, BundleWithMetadata, CancelBundle,
16+
MeterBundleResponse,
1617
};
1718
use tracing::{info, warn};
1819

0 commit comments

Comments
 (0)