Skip to content

Commit ccd48cc

Browse files
committed
feat(coprocessor): set created_at as topological order within block
1 parent 10e5511 commit ccd48cc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct Transaction {
2121
output_tx: HashSet<TransactionHash>,
2222
linear_chain: TransactionHash,
2323
size: usize,
24+
tx_topo_oder_in_block: usize,
2425
}
2526

2627
impl Transaction {
@@ -34,6 +35,7 @@ impl Transaction {
3435
output_tx: HashSet::with_capacity(3),
3536
linear_chain: tx_hash, // before coallescing linear tx chains
3637
size: 0,
38+
tx_topo_oder_in_block: 0,
3739
}
3840
}
3941
}
@@ -235,10 +237,13 @@ fn topological_order(ordered_txs: &mut Vec<Transaction>) {
235237
}
236238
ordered_txs.clear();
237239
debug!("Reordered txs: {:?}", reordered);
240+
let mut topo_order_position = 0;
238241
for tx_hash in reordered.iter() {
239-
let Some(tx) = txs.remove(tx_hash) else {
242+
let Some(mut tx) = txs.remove(tx_hash) else {
240243
continue;
241244
};
245+
tx.tx_topo_oder_in_block = topo_order_position;
246+
topo_order_position += tx.size;
242247
ordered_txs.push(tx);
243248
}
244249
}
@@ -469,6 +474,9 @@ pub async fn dependence_chains(
469474
let tx_hash = log.transaction_hash.unwrap_or_default();
470475
if let Some(tx) = txs.get(&tx_hash) {
471476
log.dependence_chain = tx.linear_chain;
477+
log.block_timestamp = log.block_timestamp.saturating_add(
478+
time::Duration::microseconds(tx.tx_topo_oder_in_block as i64),
479+
);
472480
} else {
473481
// past chain
474482
log.dependence_chain = tx_hash;

0 commit comments

Comments
 (0)