Skip to content

Commit 15a1e21

Browse files
danielntmddanielntmd
andauthored
chore: (A-815) fix l1 tx utils fallback id logic (#22187)
This is purely a correctness fix, no behavioral changes as the id is only used for store operations and when there is no store, this fallback is never hit. **Fallback logic previous:** If `txs.map` is empty then `this.txs.map(tx => tx.id)` resolves to nothing and `Math.max(0)` resolves to 0. Next iteration, `this.txs.map(tx => tx.id)` resolves to 0 and `Math.max(0, 0)` resolves to 0 again. Collision! **Fallback logic fixed:** If `txs.map` is empty then `this.txs.map(tx => tx.id)` resolves to empty and `Math.max(-1) + 1` resolves to 0. Next iteration, `this.txs.map(tx => tx.id)` resolves to 0 and `Math.max(0, -1) + 1` resolves to 1, a unique id. Co-authored-by: danielntmd <danielntmd@nethermind.io>
1 parent babb6c6 commit 15a1e21

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

yarn-project/ethereum/src/l1_tx_utils/l1_tx_utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ export class L1TxUtils extends ReadOnlyL1TxUtils {
281281
// Create the new state for monitoring
282282
const l1TxState: L1TxState = {
283283
...baseState,
284-
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), 0),
284+
id: (await this.store?.consumeNextStateId(account)) ?? Math.max(...this.txs.map(tx => tx.id), -1) + 1,
285285
txHashes: [txHash],
286286
cancelTxHashes: [],
287287
status: TxUtilsState.IDLE,

0 commit comments

Comments
 (0)