Skip to content

Commit a8ce993

Browse files
committed
fix(coprocessor): host-listener, block time in computations.created_at & .schedule_order
use block time instead of the default now() == transaction time
1 parent 45bd44f commit a8ce993

File tree

6 files changed

+51
-5
lines changed

6 files changed

+51
-5
lines changed

coprocessor/fhevm-engine/host-listener/.sqlx/query-596c0373ac6af8afaf8893e772a175ab88dc83c8788d8ca57c72fb1e42a00cd2.json

Lines changed: 22 additions & 0 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/cmd/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use alloy::sol_types::SolEventInterface;
77
use anyhow::{anyhow, Result};
88
use fhevm_engine_common::telemetry;
99
use futures_util::stream::StreamExt;
10+
use sqlx::types::time::{OffsetDateTime, PrimitiveDateTime};
1011
use sqlx::types::Uuid;
1112

1213
use std::collections::{HashSet, VecDeque};
@@ -828,6 +829,18 @@ async fn db_insert_block_no_retry(
828829
let mut tx = db.new_transaction().await?;
829830
let mut is_allowed = HashSet::<Handle>::new();
830831
let mut tfhe_event_log = vec![];
832+
let block_timestamp = OffsetDateTime::from_unix_timestamp(
833+
block_logs.summary.timestamp as i64,
834+
)
835+
.unwrap_or_else(|_| {
836+
error!(
837+
timestamp = block_logs.summary.timestamp,
838+
"Invalid block timestamp, using now",
839+
);
840+
OffsetDateTime::now_utc()
841+
});
842+
let block_timestamp =
843+
PrimitiveDateTime::new(block_timestamp.date(), block_timestamp.time());
831844
for log in &block_logs.logs {
832845
let current_address = Some(log.inner.address);
833846
let is_acl_address = &current_address == acl_contract_address;
@@ -860,6 +873,7 @@ async fn db_insert_block_no_retry(
860873
transaction_hash: log.transaction_hash,
861874
is_allowed: false, // updated in the next loop
862875
block_number: log.block_number,
876+
block_timestamp,
863877
};
864878
tfhe_event_log.push(log);
865879
continue;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub struct LogTfhe {
8484
pub transaction_hash: Option<TransactionHash>,
8585
pub is_allowed: bool,
8686
pub block_number: Option<u64>,
87+
pub block_timestamp: sqlx::types::time::PrimitiveDateTime,
8788
}
8889

8990
pub type Transaction<'l> = sqlx::Transaction<'l, Postgres>;
@@ -282,9 +283,11 @@ impl Database {
282283
is_scalar,
283284
dependence_chain_id,
284285
transaction_id,
285-
is_allowed
286+
is_allowed,
287+
created_at,
288+
schedule_order
286289
)
287-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
290+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9)
288291
ON CONFLICT (tenant_id, output_handle, transaction_id) DO NOTHING
289292
"#,
290293
tenant_id as i32,
@@ -295,6 +298,7 @@ impl Database {
295298
bucket.to_vec(),
296299
log.transaction_hash.map(|txh| txh.to_vec()),
297300
log.is_allowed,
301+
log.block_timestamp,
298302
);
299303
query.execute(tx.deref_mut()).await.map(|_| ())
300304
}

coprocessor/fhevm-engine/stress-test-generator/.sqlx/query-0fe024db8ce4cb065633e9f02bd96e67b62460c4d725030ce6fb3b488d0541a7.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/stress-test-generator/src/utils.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use host_listener::database::tfhe_event_propagate::{
66
ClearConst, Database as ListenerDatabase, Handle, LogTfhe, TransactionHash,
77
};
88
use rand::Rng;
9+
use sqlx::types::time::PrimitiveDateTime;
910
use sqlx::Postgres;
1011
use std::sync::Arc;
1112
use tracing::info;
@@ -231,6 +232,7 @@ pub async fn generate_trivial_encrypt(
231232
transaction_hash: Some(transaction_hash),
232233
is_allowed,
233234
block_number: None,
235+
block_timestamp: PrimitiveDateTime::MAX,
234236
};
235237
let mut tx = listener_event_to_db.new_transaction().await?;
236238
listener_event_to_db
@@ -385,6 +387,7 @@ pub async fn insert_tfhe_event(
385387
transaction_hash: Some(transaction_hash),
386388
is_allowed,
387389
block_number: None,
390+
block_timestamp: PrimitiveDateTime::MAX,
388391
};
389392
listener_event_to_db
390393
.insert_tfhe_event(&mut tx, &log)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloy::primitives::{FixedBytes, Log};
22
use bigdecimal::num_bigint::BigInt;
3+
use sqlx::types::time::PrimitiveDateTime;
34

45
use fhevm_engine_common::types::AllowEvents;
56
use host_listener::contracts::TfheContract;
@@ -42,6 +43,7 @@ async fn insert_tfhe_event(
4243
transaction_hash: log.transaction_hash,
4344
is_allowed,
4445
block_number: log.block_number,
46+
block_timestamp: PrimitiveDateTime::MAX,
4547
};
4648
db.insert_tfhe_event(tx, &event).await
4749
}

0 commit comments

Comments
 (0)