Skip to content

Commit fe28ad9

Browse files
committed
test(tfhe-worker): filter pattern spans by synthetic tx id
1 parent 2922869 commit fe28ad9

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

coprocessor/fhevm-engine/scheduler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ fhevm-engine-common = { path = "../fhevm-engine-common" }
2727
[features]
2828
nightly-avx512 = ["tfhe/nightly-avx512"]
2929
gpu = ["tfhe/gpu"]
30+
test-span-attrs = []

coprocessor/fhevm-engine/scheduler/src/dfg/scheduler.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ use super::{pattern, DFComponentGraph, DFGraph, OpNode};
2727
const OPERATION_RERANDOMISATION_DOMAIN_SEPARATOR: [u8; 8] = *b"TFHE_Rrd";
2828
const COMPACT_PUBLIC_ENCRYPTION_DOMAIN_SEPARATOR: [u8; 8] = *b"TFHE_Enc";
2929

30+
#[cfg(feature = "test-span-attrs")]
31+
macro_rules! execute_transaction_span {
32+
($tx_pattern_id:expr, $transaction_id:expr) => {
33+
tracing::info_span!(
34+
"execute_transaction",
35+
transaction_pattern_id = %$tx_pattern_id,
36+
test_transaction_id = %hex::encode($transaction_id),
37+
)
38+
};
39+
}
40+
41+
#[cfg(not(feature = "test-span-attrs"))]
42+
macro_rules! execute_transaction_span {
43+
($tx_pattern_id:expr, $transaction_id:expr) => {
44+
tracing::info_span!(
45+
"execute_transaction",
46+
transaction_pattern_id = %$tx_pattern_id,
47+
)
48+
};
49+
}
50+
3051
pub enum PartitionStrategy {
3152
MaxParallelism,
3253
MaxLocality,
@@ -334,11 +355,8 @@ fn execute_partition(
334355
}
335356

336357
// Prime the scheduler with ready ops from the transaction's subgraph
337-
let _exec_guard = tracing::info_span!(
338-
"execute_transaction",
339-
transaction_pattern_id = %pattern::pattern_to_base64url(transaction_pattern_id),
340-
)
341-
.entered();
358+
let transaction_pattern_id = pattern::pattern_to_base64url(transaction_pattern_id);
359+
let _exec_guard = execute_transaction_span!(transaction_pattern_id, &tid).entered();
342360
let started_at = std::time::Instant::now();
343361

344362
let Ok(ts) = daggy::petgraph::algo::toposort(&dfg.graph, None) else {
@@ -483,6 +501,7 @@ fn try_execute_node(
483501
}
484502

485503
type OpResult = Result<CompressedCiphertext>;
504+
486505
fn run_computation(
487506
operation: i32,
488507
inputs: Vec<SupportedFheCiphertexts>,

coprocessor/fhevm-engine/tfhe-worker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test-harness = { path = "../test-harness" }
5656
serde = { workspace = true }
5757
serial_test = { workspace = true }
5858
opentelemetry_sdk = { workspace = true, features = ["testing"] }
59+
scheduler = { path = "../scheduler", features = ["test-span-attrs"] }
5960

6061
[[bin]]
6162
name = "tfhe_worker"

coprocessor/fhevm-engine/tfhe-worker/src/tests/pattern_integration.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ fn span_id_key(id: SpanId) -> u64 {
3636
/// Multiple `execute_transaction` spans may share the same
3737
/// `transaction_pattern_id` when a transaction is split into several
3838
/// scheduler components.
39-
fn group_ops_by_transaction(spans: &[SpanData]) -> HashMap<String, Vec<(u64, Vec<String>)>> {
39+
fn group_ops_by_transaction(
40+
spans: &[SpanData],
41+
test_transaction_ids: &HashSet<String>,
42+
) -> HashMap<String, Vec<(u64, Vec<String>)>> {
4043
// execute_transaction span_id → transaction_pattern_id
4144
let exec_spans: HashMap<u64, String> = spans
4245
.iter()
4346
.filter(|s| s.name == "execute_transaction")
4447
.filter_map(|s| {
48+
let tx_id = get_string_attr(s, "test_transaction_id")?;
49+
if !test_transaction_ids.contains(&tx_id) {
50+
return None;
51+
}
4552
let tp = get_string_attr(s, "transaction_pattern_id")?;
4653
Some((span_id_key(s.span_context.span_id()), tp))
4754
})
@@ -439,8 +446,20 @@ async fn test_erc20_transaction_pattern_ids() -> Result<(), Box<dyn std::error::
439446

440447
// ── Span assertions ─────────────────────────────────────────────────
441448

449+
let test_transaction_ids = HashSet::from([
450+
hex::encode(tx_single_id),
451+
hex::encode(tx_triple_id),
452+
hex::encode(tx_nocmux_id),
453+
]);
442454
let spans = finished_test_spans().expect("failed to read spans");
443-
let groups = group_ops_by_transaction(&spans);
455+
assert!(
456+
spans.iter().any(|s| {
457+
s.name == "execute_transaction" && get_string_attr(s, "test_transaction_id").is_some()
458+
}),
459+
"execute_transaction spans are missing test_transaction_id; \
460+
scheduler test-span-attrs feature is likely disabled"
461+
);
462+
let groups = group_ops_by_transaction(&spans, &test_transaction_ids);
444463

445464
// We expect exactly 3 distinct transaction_pattern_ids.
446465
//

0 commit comments

Comments
 (0)