Skip to content
This repository was archived by the owner on Jul 15, 2026. It is now read-only.

Commit e31f12b

Browse files
authored
feat: publish to audit kafka async (#63)
* wip * works * make status text black * use helper * move init chan in main * reduce diffs
1 parent b113b31 commit e31f12b

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

crates/ingress-rpc/src/bin/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use op_alloy_network::Optimism;
55
use rdkafka::ClientConfig;
66
use rdkafka::producer::FutureProducer;
77
use std::net::{IpAddr, SocketAddr};
8-
use tips_audit::KafkaBundleEventPublisher;
8+
use tips_audit::{BundleEvent, KafkaBundleEventPublisher, connect_audit_to_publisher};
99
use tips_core::kafka::load_kafka_config_from_file;
1010
use tips_core::logger::init_logger;
1111
use tips_ingress_rpc::metrics::init_prometheus_exporter;
1212
use tips_ingress_rpc::queue::KafkaQueuePublisher;
1313
use tips_ingress_rpc::service::{IngressApiServer, IngressService};
14+
use tokio::sync::mpsc;
1415
use tracing::info;
1516
use url::Url;
1617

@@ -132,13 +133,15 @@ async fn main() -> anyhow::Result<()> {
132133
let audit_producer: FutureProducer = audit_client_config.create()?;
133134

134135
let audit_publisher = KafkaBundleEventPublisher::new(audit_producer, config.audit_topic);
136+
let (audit_tx, audit_rx) = mpsc::unbounded_channel::<BundleEvent>();
137+
connect_audit_to_publisher(audit_rx, audit_publisher);
135138

136139
let service = IngressService::new(
137140
provider,
138141
simulation_provider,
139142
config.dual_write_mempool,
140143
queue,
141-
audit_publisher,
144+
audit_tx,
142145
config.send_transaction_default_lifetime_seconds,
143146
config.block_time_milliseconds,
144147
);

crates/ingress-rpc/src/service.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ use op_alloy_consensus::OpTxEnvelope;
1010
use op_alloy_network::Optimism;
1111
use reth_rpc_eth_types::EthApiError;
1212
use std::time::{SystemTime, UNIX_EPOCH};
13-
use tips_audit::{BundleEvent, BundleEventPublisher};
13+
use tips_audit::BundleEvent;
1414
use tips_core::types::ParsedBundle;
1515
use tips_core::{
1616
AcceptedBundle, Bundle, BundleExtensions, BundleHash, CancelBundle, MeterBundleResponse,
1717
};
18+
use tokio::sync::mpsc;
1819
use tokio::time::Instant;
1920
use tracing::{info, warn};
2021

@@ -37,24 +38,24 @@ pub trait IngressApi {
3738
async fn send_raw_transaction(&self, tx: Bytes) -> RpcResult<B256>;
3839
}
3940

40-
pub struct IngressService<Queue, Audit> {
41+
pub struct IngressService<Queue> {
4142
provider: RootProvider<Optimism>,
4243
simulation_provider: RootProvider<Optimism>,
4344
dual_write_mempool: bool,
4445
bundle_queue: Queue,
45-
audit_publisher: Audit,
46+
audit_channel: mpsc::UnboundedSender<BundleEvent>,
4647
send_transaction_default_lifetime_seconds: u64,
4748
metrics: Metrics,
4849
block_time_milliseconds: u64,
4950
}
5051

51-
impl<Queue, Audit> IngressService<Queue, Audit> {
52+
impl<Queue> IngressService<Queue> {
5253
pub fn new(
5354
provider: RootProvider<Optimism>,
5455
simulation_provider: RootProvider<Optimism>,
5556
dual_write_mempool: bool,
5657
queue: Queue,
57-
audit_publisher: Audit,
58+
audit_channel: mpsc::UnboundedSender<BundleEvent>,
5859
send_transaction_default_lifetime_seconds: u64,
5960
block_time_milliseconds: u64,
6061
) -> Self {
@@ -63,7 +64,7 @@ impl<Queue, Audit> IngressService<Queue, Audit> {
6364
simulation_provider,
6465
dual_write_mempool,
6566
bundle_queue: queue,
66-
audit_publisher,
67+
audit_channel,
6768
send_transaction_default_lifetime_seconds,
6869
metrics: Metrics::default(),
6970
block_time_milliseconds,
@@ -72,10 +73,9 @@ impl<Queue, Audit> IngressService<Queue, Audit> {
7273
}
7374

7475
#[async_trait]
75-
impl<Queue, Audit> IngressApiServer for IngressService<Queue, Audit>
76+
impl<Queue> IngressApiServer for IngressService<Queue>
7677
where
7778
Queue: QueuePublisher + Sync + Send + 'static,
78-
Audit: BundleEventPublisher + Sync + Send + 'static,
7979
{
8080
async fn send_bundle(&self, bundle: Bundle) -> RpcResult<BundleHash> {
8181
self.validate_bundle(&bundle).await?;
@@ -104,8 +104,11 @@ where
104104
bundle_id: *accepted_bundle.uuid(),
105105
bundle: Box::new(accepted_bundle.clone()),
106106
};
107-
if let Err(e) = self.audit_publisher.publish(audit_event).await {
108-
warn!(message = "Failed to publish audit event", bundle_id = %accepted_bundle.uuid(), error = %e);
107+
if let Err(e) = self.audit_channel.send(audit_event) {
108+
warn!(message = "Failed to send audit event", error = %e);
109+
return Err(
110+
EthApiError::InvalidParams("Failed to send audit event".into()).into_rpc_err(),
111+
);
109112
}
110113

111114
Ok(BundleHash {
@@ -178,8 +181,11 @@ where
178181
bundle_id: *accepted_bundle.uuid(),
179182
bundle: accepted_bundle.clone().into(),
180183
};
181-
if let Err(e) = self.audit_publisher.publish(audit_event).await {
182-
warn!(message = "Failed to publish audit event", bundle_id = %accepted_bundle.uuid(), error = %e);
184+
if let Err(e) = self.audit_channel.send(audit_event) {
185+
warn!(message = "Failed to send audit event", error = %e);
186+
return Err(
187+
EthApiError::InvalidParams("Failed to send audit event".into()).into_rpc_err(),
188+
);
183189
}
184190

185191
self.metrics
@@ -189,10 +195,9 @@ where
189195
}
190196
}
191197

192-
impl<Queue, Audit> IngressService<Queue, Audit>
198+
impl<Queue> IngressService<Queue>
193199
where
194200
Queue: QueuePublisher + Sync + Send + 'static,
195-
Audit: BundleEventPublisher + Sync + Send + 'static,
196201
{
197202
async fn validate_tx(&self, data: &Bytes) -> RpcResult<Recovered<OpTxEnvelope>> {
198203
let start = Instant::now();

ui/src/app/bundles/[uuid]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default function BundlePage({ params }: PageProps) {
111111
<div className="flex items-start justify-between mb-2">
112112
<div className="flex flex-col gap-1">
113113
<span
114-
className={`px-2 py-1 rounded text-sm font-medium bg-gray-200`}
114+
className={`px-2 py-1 rounded text-sm font-medium bg-gray-200 text-black`}
115115
>
116116
{event.event}
117117
</span>

0 commit comments

Comments
 (0)