Neptune-Crypto / neptune-core

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

Can the mempool handle reorganizations? #145

Closed Sword-Smith closed 1 month ago

Sword-Smith commented 2 months ago

I don't think it can currently. One simple solution would be to simply clear the mempool in the case of a reorganization.

dan-da commented 2 months ago

Clearing would lose pending/unconfirmed tx. I think those need to be kept.

With bitcoin, I believe it adds any extra/orphaned tx from the reorg into the mempool. But iiuc we can't really do that because we no longer have the user-level tx, everything was aggregated into block-tx. So any such orphans would just be lost.

I believe (need to verify) that bitcoin also must remove any tx from mempool that have already been included in one of the new blocks. This is where we may have a problem, and probably why you suggested clearing the mempool.

My question would be: does there exist any possibility to detect if a user-level tx has been accumulated into a block-level tx? If so, then it would seem we can detect and remove these. If not, then I don't see any solution other than clearing mempool unfortunately.

aszepieniec commented 2 months ago

does there exist any possibility to detect if a user-level tx has been accumulated into a block-level tx?

Yes: the user-level transactions are no longer valid. More specifically: the removal records induce updates of the mutator set which is designed to catch would-be double-spending attempts. Removal records consist of a list of indices and membership proofs in the SWBF MMR, and the latter field has no bearing on equality or duplicates -- so you are looking for a duplicate of index sets.