hirosystems / stacks-blockchain-api

API for the Stacks blockchain
https://stacks-blockchain-api.vercel.app
GNU General Public License v3.0
171 stars 108 forks source link

automatically mark mempool transactions with conflicting nonces as failed #2041

Open rafaelcr opened 1 month ago

rafaelcr commented 1 month ago

The API returns a bunch of mempool transactions that are impossible to mine given that they conflict with other confirmed transactions from the same senders with the same nonce, so they end up being stuck for days (until they get pruned after 256 blocks). For example, this transaction with nonce 4461 is still pending:

Screenshot 2024-08-02 at 22 33 06

However, that sender STX address already has a confirmed transaction with the same nonce (in this case a coinbase, but the same happens with any tx type):

Screenshot 2024-08-02 at 22 34 20

These stuck transactions can cause user confusion but they most definitely affect the fee estimation algorithms. (I'm not sure why the Stacks node does not drop them automatically.)

smcclellan commented 1 month ago

@zone117x for feedback.

zone117x commented 2 weeks ago

We should add logic to the API that upon a tx confirmation, it checks the mempool table for txs from that sender with that nonce and marks them as failed or pruned.

This makes sense to me. The only thing to be careful about is "restoration" / un-pruning txs during re-orgs when necessary, otherwise it can give the appearance of txs "disappearing", when they are not included in a canonical block and are also pruned from the mempool.