Skip to content

Conversation

@morcos
Copy link
Contributor

@morcos morcos commented Apr 13, 2016

AlreadyHave is called for transactions in 3 places:

  • when an INV is received to decide whether to schedule a request of the tx
  • when a TX is received to decide whether to process it
  • when actually requesting a tx to see if it has been received since scheduling the request

In a large number of these cases, the transaction in question is new and fails each of the tests in the return statement. In particular it is very unlikely (< 10%) to hit the pcoinsTip check and then be found. But pcoinsTip must check the database to be sure it can't find the transaction. Switching the full HaveCoins check for the fast HaveCoinsInCache check will still prevent the vast majority of false negatives but will never need a database access. The downside is after the cache has been flushed there maybe be a very few more cases of requesting already confirmed transactions from peers.

@pstratem
Copy link
Contributor

utACK c6cb6f7

@laanwj laanwj added the P2P label Apr 14, 2016
@sipa
Copy link
Member

sipa commented Apr 14, 2016

utACK c6cb6f7

@btcdrak
Copy link
Contributor

btcdrak commented Apr 14, 2016

utACK c6cb6f7

@instagibbs
Copy link
Member

utACK c6cb6f7

@laanwj laanwj merged commit c6cb6f7 into bitcoin:master Apr 14, 2016
laanwj added a commit that referenced this pull request Apr 14, 2016
c6cb6f7 Avoid unnecessary database access for unknown transactions (Alex Morcos)
codablock pushed a commit to codablock/dash that referenced this pull request Oct 19, 2017
c6cb6f7 Avoid unnecessary database access for unknown transactions (Alex Morcos)
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Aug 13, 2020
1ba085e Avoid unnecessary database access for unknown transactions (Alex Morcos)

Pull request description:

  Based on top of:
  - [x] #1799

  Only last commit is new.
  Now that we have implemented `HaveCoinsInCache`, we can use it to speed up `AlreadyHave`, by avoiding unnecessary database access for unknown transactions.
  (backported from bitcoin#7874)

ACKs for top commit:
  Fuzzbawls:
    utACK 1ba085e
  furszy:
    utACK 1ba085e

Tree-SHA512: f17c19b1ab00bac7bcf87fcfc513cfc7d2a690474a38bce6a9b9ba3c86ec5c4e064eb8a937e7cfdc8ef87d13e4b970d7de1be9a5957af19f2fa33c71286765b6
@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.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants