IntersectMBO / IntersectMBO/ouroboros-consensus

Mempool: snapshotFromValidTxs rebuilds the GenTxId set on every snapshot

Open
#2,111 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
67
Forks
43
Avg merge
5d 13h
Merged PRs (30d)
43

Description

[`snapshotFromValidTxs`](https://github.com/IntersectMBO/ouroboros-consensus/blob/bd119d907b7701aac5f7825e6645614a7473e9bf/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Impl/Common.hs#L510) builds `txIds = Set.fromList (map txId validTxs)` for `snapshotHasTx` on every snapshot.
`getSnapshot` calls it per invocation, and the tx-submission [mempool reader](https://github.com/IntersectMBO/ouroboros-consensus/blob/bd119d907b7701aac5f7825e6645614a7473e9bf/ouroboros-consensus-diffusion/src/ouroboros-consensus-diffusion/Ouroboros/Consensus/NodeKernel.hs#L903-L924) snapshots on every read, so the `O(n log n)` rebuild runs often.

The InternalState already maintains [`isTxIds :: Set (GenTxId blk)`](https://github.com/IntersectMBO/ouroboros-consensus/blob/bd119d907b7701aac5f7825e6645614a7473e9bf/ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Impl/Common.hs#L113) incrementally.
The `snapshotFromIS`/`getSnapshot` path could reuse it instead of rebuilding.
(The revalidation path `computeSnapshot` builds a fresh tx list, so it would still rebuild.)

Orthogonal to #2003: this is about how often the set is built, not the per-comparison cost.
Found while analysing #2003.

Contributor guide

Open the contributing guide

Research direction

Start in ouroboros-consensus/src/ouroboros-consensus/Ouroboros/Consensus/Mempool/Impl/Common.hs at snapshotFromValidTxs, snapshotFromIS, getSnapshot, and InternalState.isTxIds. Trace the mempool reader in ouroboros-consensus-diffusion/.../NodeKernel.hs to understand the snapshot path. Done means the regular snapshot path reuses isTxIds for snapshotHasTx, while computeSnapshot still rebuilds its set.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
blockchain
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.