Skip to content

Conversation

@morcos
Copy link
Contributor

@morcos morcos commented Jun 8, 2017

Checking for the existence in the CCoinsViewCache of the outputs of a new tx
will result in a disk hit for every output since they will not be found. On the
other hand if those outputs exist already, then the inputs must also have been
missing, so we can move this check inside the input existence check so in the
common case of a new tx it doesn't need to run.

The purpose of the check is to avoid spamming the orphanMap with slightly old
txs which we have already seen in a block, but it is already only optimistic
(depending on the outputs not being spent), so make it even more efficient by
only checking the cache and not the entire pcoinsTip.

@sipa this is my biggest feedback to #10195

For a single valid tx with 500 outputs in regtest on a machine with an SSD, the time to ATMP dropped from 4 ms to 2.4 ms.

Copy link
Member

@sipa sipa Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this risks resulting in true for transactions that are in fact not yet confirmed and not in the mempool, but were just disconnected in a reorg. Is that something we care about? If not, perhaps add a comment to explain.

Copy link
Member

@sdaftuar sdaftuar Jun 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just change HaveCoinInCache() to have the same semantics as HaveCoin(), and only return true if the coin is unspent? Seems confusing that their semantics aren't the same.

For many of the existing usages of HaveCoinInCache(), we store the result to potentially Uncache() later -- but I don't think it's possible to ever have a spent coin in your cache that is able to be uncached (ie not marked DIRTY)?

This issue affects the existing usage of HaveCoinInCache() in AlreadyHave(), I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sipa I actually think that's likely a better outcome, but it may be too confusing. If a tx was just disconnected in a reorg, and no longer has one of its inputs available, it means it or its parent was probably double spent and so it shouldn't be in the orphan map anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morcos Do you think it's worth the complexity? I like @sdaftuar's suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I like his suggestion as well.
I think this PR is "correct" as is, and I will make that change in a separate PR as a fix to HaveCoinsInCache?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

@sipa
Copy link
Member

sipa commented Jun 8, 2017

utACK 301566d1cb49e7ef78d91e0eb86783deee1885db

@sipa
Copy link
Member

sipa commented Jun 23, 2017

Needs rebase.

Checking for the existence in the CCoinsViewCache of the outputs of a new tx
will result in a disk hit for every output since they will not be found.  On the
other hand if those outputs exist already, then the inputs must also have been
missing, so we can move this check inside the input existence check so in the
common case of a new tx it doesn't need to run.

The purpose of the check is to avoid spamming the orphanMap with slightly old
txs which we have already seen in a block, but it is already only optimistic
(depending on the outputs not being spent), so make it even more efficient by
only checking the cache and not the entire pcoinsTip.
@morcos morcos force-pushed the dontcheckoutputs branch from 301566d to 18bacec Compare June 27, 2017 18:15
@morcos
Copy link
Contributor Author

morcos commented Jun 27, 2017

Simple rebase due to #10503

@TheBlueMatt
Copy link
Contributor

utACK 18bacec

@morcos
Copy link
Contributor Author

morcos commented Jul 7, 2017

Please tag for 0.15

@fanquake fanquake added this to the 0.15.0 milestone Jul 7, 2017
Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK. "Duh"-- it should have always done this.

@gmaxwell
Copy link
Contributor

This will spam the orphan map somewhat after flushing, unfortunately-- but we can fix this by making flushing less hard in the future... and the orphan map is much less important than it used to be already.

@TheBlueMatt
Copy link
Contributor

I still think we should take this for 15, but another thing to consider is to add a rolling bloom filter in net_processing ala TheBlueMatt@316516c (which is based on a big pile of changes, but could be pulled out separately), on top of this change.

@sipa sipa merged commit 18bacec into bitcoin:master Jul 14, 2017
sipa added a commit that referenced this pull request Jul 14, 2017
…s more efficient.

18bacec Make check to distinguish between orphan txs and old txs more efficient. (Alex Morcos)

Tree-SHA512: b6b4bad89aa561975dce7b68b2fdad5623af5ebcb9c38fd6a72b5f6d0544ed441df4865591ac018f7ae0df9b5c60820cb4d9e55664f5667c9268458df70fd554
@jnewbery jnewbery mentioned this pull request Jul 31, 2017
12 tasks
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 18, 2019
… old txs more efficient.

18bacec Make check to distinguish between orphan txs and old txs more efficient. (Alex Morcos)

Tree-SHA512: b6b4bad89aa561975dce7b68b2fdad5623af5ebcb9c38fd6a72b5f6d0544ed441df4865591ac018f7ae0df9b5c60820cb4d9e55664f5667c9268458df70fd554
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants