Skip to content

Commit 2373b73

Browse files
committed
fix(coprocessor): do not update is_completed on unallowed handles
1 parent 3b11a36 commit 2373b73

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

coprocessor/fhevm-engine/.sqlx/query-596c0373ac6af8afaf8893e772a175ab88dc83c8788d8ca57c72fb1e42a00cd2.json renamed to coprocessor/fhevm-engine/.sqlx/query-80773377196369e45a314d7a463e8961eabb91626acc28eb22aca8771b3615fb.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,10 @@ impl Database {
291291
transaction_id,
292292
is_allowed,
293293
created_at,
294-
schedule_order
294+
schedule_order,
295+
is_completed
295296
)
296-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9)
297+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9, $10)
297298
ON CONFLICT (tenant_id, output_handle, transaction_id) DO NOTHING
298299
"#,
299300
tenant_id as i32,
@@ -305,6 +306,7 @@ impl Database {
305306
log.transaction_hash.map(|txh| txh.to_vec()),
306307
log.is_allowed,
307308
log.block_timestamp,
309+
!log.is_allowed,
308310
);
309311
query
310312
.execute(tx.deref_mut())

coprocessor/fhevm-engine/tfhe-worker/src/tfhe_worker.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ async fn upload_transaction_graph_results<'a>(
568568
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
569569
// Get computation results
570570
let graph_results = tx_graph.get_results();
571-
let mut handles_to_update = tx_graph.get_intermediate_handles();
572-
handles_to_update.append(unneeded_handles);
571+
let mut handles_to_update = vec![];
573572

574573
// Traverse computations that have been scheduled and
575574
// upload their results/errors.
@@ -641,24 +640,25 @@ async fn upload_transaction_graph_results<'a>(
641640
}
642641
}
643642
}
644-
let mut s = tracer.start_with_context("insert_ct_into_db", loop_ctx);
645-
s.set_attribute(KeyValue::new("tenant_id", *tenant_id as i64));
646-
s.set_attributes(
647-
cts_to_insert
648-
.iter()
649-
.map(|(_, (h, (_, (_, _))))| KeyValue::new("handle", format!("0x{}", hex::encode(h)))),
650-
);
651-
s.set_attributes(
652-
cts_to_insert
653-
.iter()
654-
.map(|(_, (_, (_, (_, db_type))))| KeyValue::new("ciphertext_type", *db_type as i64)),
655-
);
656-
#[allow(clippy::type_complexity)]
657-
let (tenant_ids, (handles, (ciphertexts, (ciphertext_versions, ciphertext_types)))): (
658-
Vec<_>,
659-
(Vec<_>, (Vec<_>, (Vec<_>, Vec<_>))),
660-
) = cts_to_insert.into_iter().unzip();
661-
let _ = query!(
643+
if !cts_to_insert.is_empty() {
644+
let mut s = tracer.start_with_context("insert_ct_into_db", loop_ctx);
645+
s.set_attribute(KeyValue::new("tenant_id", *tenant_id as i64));
646+
s.set_attributes(
647+
cts_to_insert.iter().map(|(_, (h, (_, (_, _))))| {
648+
KeyValue::new("handle", format!("0x{}", hex::encode(h)))
649+
}),
650+
);
651+
s.set_attributes(
652+
cts_to_insert.iter().map(|(_, (_, (_, (_, db_type))))| {
653+
KeyValue::new("ciphertext_type", *db_type as i64)
654+
}),
655+
);
656+
#[allow(clippy::type_complexity)]
657+
let (tenant_ids, (handles, (ciphertexts, (ciphertext_versions, ciphertext_types)))): (
658+
Vec<_>,
659+
(Vec<_>, (Vec<_>, (Vec<_>, Vec<_>))),
660+
) = cts_to_insert.into_iter().unzip();
661+
let _ = query!(
662662
"
663663
INSERT INTO ciphertexts(tenant_id, handle, ciphertext, ciphertext_version, ciphertext_type)
664664
SELECT * FROM UNNEST($1::INTEGER[], $2::BYTEA[], $3::BYTEA[], $4::SMALLINT[], $5::SMALLINT[])
@@ -670,24 +670,24 @@ async fn upload_transaction_graph_results<'a>(
670670
error!(target: "tfhe_worker", { tenant_id = *tenant_id, error = %err }, "error while inserting new ciphertexts");
671671
err
672672
})?;
673-
// Notify all workers that new ciphertext is inserted
674-
// For now, it's only the SnS workers that are listening for these events
675-
let _ = sqlx::query!("SELECT pg_notify($1, '')", EVENT_CIPHERTEXT_COMPUTED)
676-
.execute(trx.as_mut())
677-
.await?;
678-
s.end();
679-
680-
let mut s = tracer.start_with_context("update_computation", loop_ctx);
681-
s.set_attribute(KeyValue::new("tenant_id", *tenant_id as i64));
682-
s.set_attributes(
683-
handles_to_update
684-
.iter()
685-
.map(|(h, _)| KeyValue::new("handle", format!("0x{}", hex::encode(h)))),
686-
);
687-
688-
let (handles_vec, txn_ids_vec): (Vec<_>, Vec<_>) = handles_to_update.into_iter().unzip();
673+
// Notify all workers that new ciphertext is inserted
674+
// For now, it's only the SnS workers that are listening for these events
675+
let _ = sqlx::query!("SELECT pg_notify($1, '')", EVENT_CIPHERTEXT_COMPUTED)
676+
.execute(trx.as_mut())
677+
.await?;
678+
s.end();
679+
}
689680

690-
let _ = query!(
681+
if !handles_to_update.is_empty() {
682+
let mut s = tracer.start_with_context("update_computation", loop_ctx);
683+
s.set_attribute(KeyValue::new("tenant_id", *tenant_id as i64));
684+
s.set_attributes(
685+
handles_to_update
686+
.iter()
687+
.map(|(h, _)| KeyValue::new("handle", format!("0x{}", hex::encode(h)))),
688+
);
689+
let (handles_vec, txn_ids_vec): (Vec<_>, Vec<_>) = handles_to_update.into_iter().unzip();
690+
let _ = query!(
691691
"
692692
UPDATE computations
693693
SET is_completed = true, completed_at = CURRENT_TIMESTAMP
@@ -706,9 +706,8 @@ async fn upload_transaction_graph_results<'a>(
706706
error!(target: "tfhe_worker", { tenant_id = *tenant_id, error = %err }, "error while updating computations as completed");
707707
err
708708
})?;
709-
710-
s.end();
711-
709+
s.end();
710+
}
712711
Ok(())
713712
}
714713

0 commit comments

Comments
 (0)