Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: 1t0ph20 on April 07, 2017, 05:22:02 PM



Title: Q: How removing transactions from mempool works
Post by: 1t0ph20 on April 07, 2017, 05:22:02 PM
Hello!

Quick question: A block is solved and propagated through the network. When a node validates a block, it must remove the valid transactions out of its mempool.

Is this "removal" process a linear operation? Meaning if you need to remove 1000 txns included in the block from 14000 txns in your mempool, you need to search through worst case all 140000 txns?


Title: Re: Q: How removing transactions from mempool works
Post by: achow101 on April 07, 2017, 05:35:01 PM
The mempool does not have a defined structure; it depends entirely on how you implement it. You can implement it poorly and have it be very inefficient, or implement it well and have it be very efficient.

The way that Bitcoin Core implements the mempool can be found here (along with a big comment describing what is going on): https://github.com/bitcoin/bitcoin/blob/86f7d5b69bb72b85d71c32329cc43e80897ce348/src/txmempool.h#L330


Title: Re: Q: How removing transactions from mempool works
Post by: 1t0ph20 on April 07, 2017, 05:53:12 PM
I see.

So if you receive a block that has a transaction in it that was not in your mempool but was included in the block, does that transaction get added to your mempool and then shortly removed once you finish validating the block?



Title: Re: Q: How removing transactions from mempool works
Post by: achow101 on April 07, 2017, 06:09:46 PM
I see.

So if you receive a block that has a transaction in it that was not in your mempool but was included in the block, does that transaction get added to your mempool and then shortly removed once you finish validating the block?
No, that would be unnecessary.