Skip to content

Commit 416297d

Browse files
committed
fix(coprocessor): useblock hash to identify transaction
fixes a bug where 2 transactions are swapped during a reorg while keeping the same tx id the 4 tx (2 are reorged out) are merged and create a cycle
1 parent df9e61f commit 416297d

28 files changed

+728
-189
lines changed
Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/.sqlx/query-53182475f1e686be9094f38025ca6e37b55a9640ec10b8f082b73d6f474da001.json

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

coprocessor/fhevm-engine/.sqlx/query-63f097acd50a5ec09f959668fce297d0c2c1c9851741c2a5bbb3238af2fe5b75.json

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ALTER TABLE computations
2+
ADD COLUMN IF NOT EXISTS block_hash BYTEA NOT NULL DEFAULT '\x00'::BYTEA,
3+
ADD COLUMN IF NOT EXISTS block_number BIGINT NOT NULL DEFAULT 0;
4+
5+
ALTER TABLE computations ALTER COLUMN block_hash DROP DEFAULT;
6+
ALTER TABLE computations ALTER COLUMN block_number DROP DEFAULT;
7+
8+
-- fully identify a host chain transaction
9+
CREATE INDEX IF NOT EXISTS idx_computations_transaction
10+
ON computations (transaction_id, block_hash);
11+
12+
-- For next release
13+
-- DROP INDEX IF EXISTS idx_computations_transaction_id;

coprocessor/fhevm-engine/host-listener/src/cmd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ async fn db_insert_block_no_retry(
938938
is_allowed: false, // updated in the next loop
939939
block_number,
940940
block_timestamp,
941+
block_hash,
941942
};
942943
tfhe_event_log.push(log);
943944
continue;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::contracts::TfheContract::TfheContractEvents;
2929

3030
type CoprocessorApiKey = Uuid;
3131
type FheOperation = i32;
32+
pub type BlockHash = FixedBytes<32>;
3233
pub type Handle = FixedBytes<32>;
3334
pub type TransactionHash = FixedBytes<32>;
3435
pub type TenantId = i32;
@@ -88,6 +89,7 @@ pub struct LogTfhe {
8889
pub is_allowed: bool,
8990
pub block_number: u64,
9091
pub block_timestamp: sqlx::types::time::PrimitiveDateTime,
92+
pub block_hash: BlockHash,
9193
}
9294

9395
pub type Transaction<'l> = sqlx::Transaction<'l, Postgres>;
@@ -292,9 +294,11 @@ impl Database {
292294
transaction_id,
293295
is_allowed,
294296
created_at,
295-
schedule_order
297+
schedule_order,
298+
block_hash,
299+
block_number
296300
)
297-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9)
301+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $9, $10, $11)
298302
ON CONFLICT (tenant_id, output_handle, transaction_id) DO NOTHING
299303
"#,
300304
tenant_id as i32,
@@ -306,6 +310,8 @@ impl Database {
306310
log.transaction_hash.map(|txh| txh.to_vec()),
307311
log.is_allowed,
308312
log.block_timestamp,
313+
log.block_hash.to_vec(),
314+
log.block_number as i64,
309315
);
310316
query
311317
.execute(tx.deref_mut())

0 commit comments

Comments
 (0)