Skip to content

Commit 205bf45

Browse files
committed
refactor(host-listener): clarify slow-lane naming
1 parent dc36f53 commit 205bf45

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

coprocessor/fhevm-engine/host-listener/src/database/ingest.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct IngestOptions {
2828
pub dependent_ops_max_per_chain: u32,
2929
}
3030

31-
fn compute_schedule_priorities(
31+
fn classify_slow_lane_priorities(
3232
chains: &[Chain],
3333
dependent_ops_by_chain: &HashMap<ChainHash, u64>,
3434
dependent_ops_max_per_chain: u32,
@@ -182,7 +182,7 @@ pub async fn ingest_block_logs(
182182
.await;
183183

184184
let slow_lane_enabled = options.dependent_ops_max_per_chain > 0;
185-
let seen_chain_ids = if slow_lane_enabled {
185+
let seen_dep_chain_ids = if slow_lane_enabled {
186186
Vec::new()
187187
} else {
188188
chains.iter().map(|chain| chain.hash.to_vec()).collect()
@@ -212,7 +212,7 @@ pub async fn ingest_block_logs(
212212
let mut schedule_priority_by_chain = HashMap::new();
213213
if slow_lane_enabled {
214214
let (schedule_priorities, allowed, throttled) =
215-
compute_schedule_priorities(
215+
classify_slow_lane_priorities(
216216
&chains,
217217
&dependent_ops_by_chain,
218218
options.dependent_ops_max_per_chain,
@@ -245,7 +245,10 @@ pub async fn ingest_block_logs(
245245
}
246246
if !slow_lane_enabled {
247247
let promoted = db
248-
.promote_seen_schedule_priorities_fast(&mut tx, &seen_chain_ids)
248+
.promote_seen_dep_chains_to_fast_priority(
249+
&mut tx,
250+
&seen_dep_chain_ids,
251+
)
249252
.await?;
250253
if promoted > 0 {
251254
info!(
@@ -261,10 +264,10 @@ pub async fn ingest_block_logs(
261264
mod tests {
262265
use fhevm_engine_common::types::SchedulePriority;
263266

264-
use super::compute_schedule_priorities;
267+
use super::classify_slow_lane_priorities;
265268
use crate::database::tfhe_event_propagate::{Chain, ChainHash};
266269

267-
fn mk_chain(last_byte: u8) -> Chain {
270+
fn fixture_dep_chain(last_byte: u8) -> Chain {
268271
Chain {
269272
hash: ChainHash::with_last_byte(last_byte),
270273
dependencies: vec![],
@@ -277,32 +280,32 @@ mod tests {
277280
}
278281

279282
#[test]
280-
fn compute_schedule_priorities_cap_zero_disables() {
281-
let chains = vec![mk_chain(1)];
283+
fn classify_slow_lane_priorities_cap_zero_disables() {
284+
let chains = vec![fixture_dep_chain(1)];
282285
let mut by_chain = std::collections::HashMap::new();
283286
by_chain.insert(chains[0].hash, 10_u64);
284287

285288
let (priorities, allowed, throttled) =
286-
compute_schedule_priorities(&chains, &by_chain, 0);
289+
classify_slow_lane_priorities(&chains, &by_chain, 0);
287290

288291
assert!(priorities.is_empty());
289292
assert_eq!(allowed, 0);
290293
assert_eq!(throttled, 0);
291294
}
292295

293296
#[test]
294-
fn compute_schedule_priorities_marks_only_over_limit() {
295-
let chain_fast = mk_chain(1);
296-
let chain_slow = mk_chain(2);
297-
let chain_missing = mk_chain(3);
297+
fn classify_slow_lane_priorities_marks_only_over_limit() {
298+
let chain_fast = fixture_dep_chain(1);
299+
let chain_slow = fixture_dep_chain(2);
300+
let chain_missing = fixture_dep_chain(3);
298301
let chains =
299302
vec![chain_fast.clone(), chain_slow.clone(), chain_missing];
300303
let mut by_chain = std::collections::HashMap::new();
301304
by_chain.insert(chain_fast.hash, 3_u64);
302305
by_chain.insert(chain_slow.hash, 5_u64);
303306

304307
let (priorities, allowed, throttled) =
305-
compute_schedule_priorities(&chains, &by_chain, 4);
308+
classify_slow_lane_priorities(&chains, &by_chain, 4);
306309

307310
assert_eq!(allowed, 3);
308311
assert_eq!(throttled, 5);

coprocessor/fhevm-engine/host-listener/src/database/tfhe_event_propagate.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ impl Database {
175175
}
176176
}
177177

178-
pub async fn promote_seen_schedule_priorities_fast(
178+
pub async fn promote_seen_dep_chains_to_fast_priority(
179179
&self,
180180
tx: &mut Transaction<'_>,
181-
seen_chain_ids: &[Vec<u8>],
181+
seen_dep_chain_ids: &[Vec<u8>],
182182
) -> Result<u64, SqlxError> {
183-
if seen_chain_ids.is_empty() {
183+
if seen_dep_chain_ids.is_empty() {
184184
return Ok(0);
185185
}
186186

@@ -192,7 +192,7 @@ impl Database {
192192
AND dc.dependence_chain_id = ANY($1::bytea[])
193193
"#,
194194
)
195-
.bind(seen_chain_ids)
195+
.bind(seen_dep_chain_ids)
196196
.execute(tx.deref_mut())
197197
.await?;
198198
Ok(rows.rows_affected())
@@ -842,7 +842,7 @@ impl Database {
842842
schedule_priority_by_chain: &HashMap<ChainHash, SchedulePriority>,
843843
) -> Result<(), SqlxError> {
844844
for chain in chains {
845-
let chain_id = chain.hash.to_vec();
845+
let dep_chain_id = chain.hash.to_vec();
846846
let schedule_priority = *schedule_priority_by_chain
847847
.get(&chain.hash)
848848
.unwrap_or(&SchedulePriority::FAST);
@@ -886,7 +886,7 @@ impl Database {
886886
EXCLUDED.schedule_priority
887887
)
888888
"#,
889-
chain_id,
889+
dep_chain_id,
890890
last_updated_at,
891891
chain.dependencies.len() as i64,
892892
&dependents,

0 commit comments

Comments
 (0)