Neptune-Crypto / neptune-core

anonymous peer-to-peer cash
Apache License 2.0
25 stars 7 forks source link

feature: persist unconfirmed transactions across re-orgs #157

Open dan-da opened 4 months ago

dan-da commented 4 months ago

To achieve feature parity with blockchains such as bitcoin neptune should persist unconfirmed tx when a re-org occurs.

At present the mempool is cleared instead, meaning that anyone who had sent an unconfirmed payment would have it forgotten and need to (a) notice it had never been confirmed and (b) somehow be certain it won't confirm in the future, and (c) re-send the payment.

Here is a discussion about the reasons for this limitation and possible solutions: https://github.com/Neptune-Crypto/neptune-core/pull/153#discussion_r1603425462

In summary, because Neptune accumulates user-transactions into a single block-transaction we no longer have user-tx data available for past blocks when a re-org occurs, and we only receive block-transactions from our peers. We need to add/remove user-level tx inputs/outputs (utxo) from the mempool, but no longer have enough information to do so.

It seems that a solution could be to create an on-disk store, perhaps called mempool-archive that stores utxos for the last N blocks indexed by block hash. When a re-org occurs this archive is consulted in order to (a) remove mempool tx that have been confirmed in the (now) latest block and (b) add tx mined only on the abandoned fork into the mempool.