Skip to content

Commit 694a496

Browse files
Eikixantoniupop
authored andcommitted
fix(coprocessor): honor ordered txs for handle deps (#1884)
* fix(coprocessor): honor ordered txs for handle deps * fix(coprocessor): honor ordered txs for handle deps
1 parent e2918f4 commit 694a496

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ fn scan_transactions(
7777
}
7878

7979
fn tx_of_handle(
80+
ordered_txs_hash: &[TransactionHash],
8081
ordered_txs: &HashMap<TransactionHash, Transaction>,
8182
) -> (
8283
HashMap<Handle, TransactionHash>,
@@ -85,12 +86,18 @@ fn tx_of_handle(
8586
// handle to tx maps
8687
let mut handle_creator = HashMap::new(); // no intermediate value
8788
let mut handle_consumer = HashMap::new();
88-
for tx in ordered_txs.values() {
89+
for tx_hash in ordered_txs_hash {
90+
let Some(tx) = ordered_txs.get(tx_hash) else {
91+
continue;
92+
};
8993
for handle in &tx.allowed_handle {
9094
handle_creator.insert(*handle, tx.tx_hash);
9195
}
9296
}
93-
for tx in ordered_txs.values() {
97+
for tx_hash in ordered_txs_hash {
98+
let Some(tx) = ordered_txs.get(tx_hash) else {
99+
continue;
100+
};
94101
for handle in &tx.input_handle {
95102
if tx.output_handle.contains(handle) {
96103
// self dependency, ignore
@@ -116,14 +123,18 @@ fn tx_of_handle(
116123
}
117124

118125
async fn fill_tx_dependence_maps(
126+
ordered_txs_hash: &[TransactionHash],
119127
txs: &mut HashMap<TransactionHash, Transaction>,
120128
used_txs_chains: &mut HashMap<TransactionHash, HashSet<TransactionHash>>,
121129
past_chains: &ChainCache,
122130
) {
123131
// handle to tx maps
124-
let (handle_creator, handle_consumer) = tx_of_handle(txs);
132+
let (handle_creator, handle_consumer) = tx_of_handle(ordered_txs_hash, txs);
125133
// txs relations
126-
for tx in txs.values_mut() {
134+
for tx_hash in ordered_txs_hash {
135+
let Some(tx) = txs.get_mut(tx_hash) else {
136+
continue;
137+
};
127138
// this tx depends on dep_tx
128139
for input_handle in &tx.input_handle {
129140
if tx.output_handle.contains(input_handle) {
@@ -545,7 +556,13 @@ pub async fn dependence_chains(
545556
TransactionHash,
546557
HashSet<TransactionHash>,
547558
> = HashMap::with_capacity(txs.len());
548-
fill_tx_dependence_maps(&mut txs, &mut used_txs_chains, past_chains).await;
559+
fill_tx_dependence_maps(
560+
&ordered_hash,
561+
&mut txs,
562+
&mut used_txs_chains,
563+
past_chains,
564+
)
565+
.await;
549566
debug!("Transactions: {:?}", txs.values());
550567
let mut ordered_txs = topological_order(ordered_hash, txs);
551568
let chains = if connex {

0 commit comments

Comments
 (0)