Skip to content

Commit 51320ca

Browse files
committed
fix(coprocessor): add threshold for ignoring dependency_count and make dependent list unique
1 parent bd72122 commit 51320ca

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

coprocessor/fhevm-engine/.sqlx/query-dd1aca0ab7da74b59bfccede29d6f75a56cf847422c19db036f51169de1b43ef.json renamed to coprocessor/fhevm-engine/.sqlx/query-193e44bce47bd04357a3e86a707c63c35621140ab5ed044d895f480f2ef90d71.json

Lines changed: 2 additions & 2 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,12 @@ impl Database {
802802
WHEN dependence_chain.status = 'processed' THEN EXCLUDED.last_updated_at
803803
ELSE LEAST(dependence_chain.last_updated_at, EXCLUDED.last_updated_at)
804804
END,
805-
dependents = dependence_chain.dependents || EXCLUDED.dependents
805+
dependents = (
806+
SELECT ARRAY(
807+
SELECT DISTINCT d
808+
FROM unnest(dependence_chain.dependents || EXCLUDED.dependents) AS d
809+
)
810+
)
806811
"#,
807812
chain.hash.to_vec(),
808813
last_updated_at,

coprocessor/fhevm-engine/tfhe-worker/benches/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ async fn start_coprocessor(rx: Receiver<bool>, app_port: u16, db_url: &str) {
115115
dcid_cleanup_interval_sec: 0,
116116
processed_dcid_ttl_sec: 0,
117117
dcid_max_no_progress_cycles: 2,
118+
dcid_ignore_dependency_count_threshold: 100,
118119
};
119120

120121
std::thread::spawn(move || {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ pub struct Args {
121121
#[arg(long, value_parser = clap::value_parser!(u32), default_value_t = 2)]
122122
pub dcid_max_no_progress_cycles: u32,
123123

124+
/// Number of no-progress DCID releases before ignoring dependence counter
125+
#[arg(long, value_parser = clap::value_parser!(u32), default_value_t = 100)]
126+
pub dcid_ignore_dependency_count_threshold: u32,
127+
124128
/// Log level for the application
125129
#[arg(
126130
long,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,10 @@ impl LockMngr {
218218
}
219219

220220
/// Acquire the earliest dependence-chain entry for processing
221-
/// sorted by last_updated_at (FIFO).
221+
/// sorted by last_updated_at (FIFO). Here we ignore
222+
/// dependency_count as reorgs can lead to incorrect counts and
223+
/// set of dependents until we add block hashes to transaction
224+
/// hashes to uniquely identify transactions.
222225
/// Returns the dependence_chain_id if a lock was acquired
223226
pub async fn acquire_early_lock(
224227
&mut self,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ async fn start_coprocessor(rx: Receiver<bool>, app_port: u16, db_url: &str) {
124124
dcid_cleanup_interval_sec: 0,
125125
processed_dcid_ttl_sec: 0,
126126
dcid_max_no_progress_cycles: 2,
127+
dcid_ignore_dependency_count_threshold: 100,
127128
};
128129

129130
std::thread::spawn(move || {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,9 @@ async fn query_for_work<'a>(
343343
// If there is a current lock, we extend it and use its dependence_chain_id
344344
Some((id, reason)) => (Some(id), reason),
345345
None => {
346-
if *no_progress_cycles < 10 * args.dcid_max_no_progress_cycles {
346+
if *no_progress_cycles
347+
< args.dcid_ignore_dependency_count_threshold * args.dcid_max_no_progress_cycles
348+
{
347349
deps_chain_mngr.acquire_next_lock().await?
348350
} else {
349351
*no_progress_cycles = 0;

0 commit comments

Comments
 (0)