Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not download transactions during initial blockchain sync #7164

Merged
merged 1 commit into from Jan 19, 2016

Conversation

ptschip
Copy link
Contributor

@ptschip ptschip commented Dec 3, 2015

What I've noticed now that transaction rates are getting much higher is that every time a block is downloaded during the initial sync, sometimes 5, 10 or more new transactions are being downloaded as well and is slowing down the initial sync process. There is no reason to do a "getdata" and download these transactions since they are not getting accepted into the mempool anyway.

@@ -5653,7 +5653,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
//
// Message: getdata (non-blocks)
//
while (!pto->fDisconnect && !pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow)
while (!pto->fDisconnect && !pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow && !IsInitialBlockDownload())
Copy link
Member

Choose a reason for hiding this comment

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

No need to check IsInitialBlockDownload() every iteration of the while loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

made the change and pushed.

On 03/12/2015 6:19 AM, Wladimir J. van der Laan wrote:

In src/main.cpp
#7164 (comment):

@@ -5653,7 +5653,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
//
// Message: getdata (non-blocks)
//

  •    while (!pto->fDisconnect && !pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow)
    
  •    while (!pto->fDisconnect && !pto->mapAskFor.empty() && (*pto->mapAskFor.begin()).first <= nNow && !IsInitialBlockDownload())
    

No need to check IsInitialBlockDownload() every iteration of the while
loop.


Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/7164/files#r46555484.

@laanwj
Copy link
Member

laanwj commented Dec 3, 2015

Despite not liking how more and more depends on IsInitialBlockDownload(), I think this makes sense. Downloading transactions during initial sync just gets a long list of "Rejected: Non-final" and wastes bandwidth and verification overhead.

@jtimon
Copy link
Contributor

jtimon commented Dec 3, 2015

utACK

@petertodd
Copy link
Contributor

Concept ACK

@dcousens
Copy link
Contributor

dcousens commented Dec 3, 2015

conceptACK/utACK

@ptschip
Copy link
Contributor Author

ptschip commented Dec 3, 2015

acutally please don't merge this yet, there is a problem with the
regression tests, i think something to do with mocktime...it appears
that the tests always think that we are syncing the blockchain...i'm
investigating

On 03/12/2015 12:14 PM, Daniel Cousens wrote:

ACK


Reply to this email directly or view it on GitHub
#7164 (comment).

@ptschip
Copy link
Contributor Author

ptschip commented Dec 3, 2015

Travis is happy now...during running the regression tests, the block
timestamps in the cache were too old and so the memory pools would not
sync thinking that an initial block download was happening. The last
block needs to be within the last 24 hours. But, I think I need to add
one more thing, if the cache folder is more than 1 day old it needs to
automatically be rebuilt otherwise the regression tests will fail again.

in util.py:

   -block_time = 1388534400
   +block_time = int(round(time.time() - (200 * 10 * 60) ))

On 03/12/2015 12:14 PM, Daniel Cousens wrote:

ACK


Reply to this email directly or view it on GitHub
#7164 (comment).

# at 1 Jan 2014
block_time = 1388534400
# blocks are created with timestamps 10 minutes apart
# going backwards in time from now
Copy link
Member

Choose a reason for hiding this comment

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

Nit: ", starting 2000 minutes in the past"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, that sounds better

(and it's 2000 minutes in the past).

I'll push it up with the changes for updating the cache every 24hours.

On 03/12/2015 3:34 PM, MarcoFalke wrote:

In qa/rpc-tests/test_framework/util.py
#7164 (comment):

@@ -154,9 +154,9 @@ def initialize_chain(test_dir):

     # Create a 200-block-long chain; each of the 4 nodes
     # gets 25 mature blocks and 25 immature.
  •    # blocks are created with timestamps 10 minutes apart, starting
    
  •    # at 1 Jan 2014
    
  •    block_time = 1388534400
    
  •    # blocks are created with timestamps 10 minutes apart
    
  •    # going backwards in time from now
    

Nit: ", starting 200 minutes in the past"?


Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/7164/files#r46629519.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok that should do it,

pushed and travis is good

have a look when you can.

On 03/12/2015 3:34 PM, MarcoFalke wrote:

In qa/rpc-tests/test_framework/util.py
#7164 (comment):

@@ -154,9 +154,9 @@ def initialize_chain(test_dir):

     # Create a 200-block-long chain; each of the 4 nodes
     # gets 25 mature blocks and 25 immature.
  •    # blocks are created with timestamps 10 minutes apart, starting
    
  •    # at 1 Jan 2014
    
  •    block_time = 1388534400
    
  •    # blocks are created with timestamps 10 minutes apart
    
  •    # going backwards in time from now
    

Nit: ", starting 200 minutes in the past"?


Reply to this email directly or view it on GitHub
https://github.com/bitcoin/bitcoin/pull/7164/files#r46629519.

@ptschip ptschip force-pushed the tx_getdata branch 3 times, most recently from 3fb49df to 725835b Compare December 4, 2015 05:50
@ptschip
Copy link
Contributor Author

ptschip commented Dec 4, 2015

@MarcoFalke Fixed that nit. Also added refreshing the cache every twelve hours which will prevent any very very long running regression tests from going over the 24hr limit for the age of the cache and subsequently preventing the mempools from syncing.

@laanwj
Copy link
Member

laanwj commented Dec 4, 2015

Ugh that "maximum 24 hours" check has tripped us up multiple times.

Another option to avoid the cache invalid issue would be to change nMaxTipAge to 0x7fffffff, as it is also for regtest, as it is for testnet (see #5987)

https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L172

I'd prefer that myself to having to expire the cache every 12 hours just to avoid this check. Although there's something to be said for testing IsInitialBlockDownload itself as well... so not sure

Yet another option would be to set a mock time, but this isn't easy to do consistently.

@ptschip ptschip force-pushed the tx_getdata branch 5 times, most recently from 2acebaa to 030c552 Compare December 4, 2015 20:24
@ptschip
Copy link
Contributor Author

ptschip commented Dec 4, 2015

@laanwj Changing nmaxtipage certainly is an easy fix but I never like the idea of changing the behaviour of an app before regression testing, it sometimes bites down the road. I used mocktime instead but then had issues with nodehandling because GetTime() doesn't increment properly once you set mocktime. Made some edits there to make GetTime() increment correctly if mocktime is set.

Also needed a small edit to p2pfullblocktest to set the time base to MOCKTIME.

Pushed and travis is happy...

@jtimon
Copy link
Contributor

jtimon commented Dec 4, 2015

re-utACK

@ptschip
Copy link
Contributor Author

ptschip commented Dec 5, 2015

Oops there is one last thing, there are a few of extended tests that might need the mocktime. I can't execute them because of ndbm which doesn't run on windows so I'll have to try things out on Travis. I think about 4 scripts that might need fixing up. Shouldn't take too long...I'll let you know when it's done.

@paveljanik
Copy link
Contributor

Rebase needed.

@sdaftuar
Copy link
Member

sdaftuar commented Dec 5, 2015

I like the overall goal here, but I'm not sure I follow the reasoning for changing the behavior of SetMockTime. One advantage of the way mocktime works now is that for the places in the code that call GetTime(), the behavior is deterministic -- the time will always be whatever the last mocktime call set it to. I think this determinism can be a useful feature for testing, and making it an offset of the current system time will eliminate the determinism.

Can we work around this problem differently in the tests? I don't actually understand why the time would need to advance but I haven't yet poked into the problems you ran into. But for instance, one workaround I've used in tests I've previously written is to just mine a single block at the beginning of the test to ensure that the nodes are out of IBD (I recognize this workaround may not easily apply to all testing scenarios though).

@ptschip
Copy link
Contributor Author

ptschip commented Dec 5, 2015

Mocktime needs to advance otherwise banning and unbanning doesn't work
so scripts such as nodehandling end up failing. I think having mocktime
advance, gives us a more realisitic functionality for testing as it
behaves in the same way as the application does in the real world.

On 05/12/2015 6:40 AM, Suhas Daftuar wrote:

I like the overall goal here, but I'm not sure I follow the reasoning
for changing the behavior of |SetMockTime|. One advantage of the way
mocktime works now is that for the places in the code that call
|GetTime()|, the behavior is deterministic -- the time will always be
whatever the last mocktime call set it to. I think this determinism
can be a useful feature for testing, and making it an offset of the
current system time will eliminate the determinism.

Can we work around this problem differently in the tests? I don't
actually understand why the time would need to advance but I haven't
yet poked into the problems you ran into. But for instance, one
workaround I've used in tests I've previously written is to just mine
a single block at the beginning of the test to ensure that the nodes
are out of IBD (I recognize this workaround may not easily apply to
all testing scenarios though).


Reply to this email directly or view it on GitHub
#7164 (comment).

@ptschip ptschip force-pushed the tx_getdata branch 2 times, most recently from ea8e6d6 to b51b7bf Compare December 5, 2015 17:15
@ptschip
Copy link
Contributor Author

ptschip commented Dec 5, 2015

@sdaftuar Thinking about this some more perhaps you are right, but maybe we can have both. We can have the mocktime we have now and also have a mocktime that will advance for those that need it. It would certainly be easier than having to fix up these python scripts.

@ptschip ptschip deleted the tx_getdata branch April 5, 2016 02:18
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Apr 27, 2016
@maflcko
Copy link
Member

maflcko commented Jun 9, 2016

Backported as part of #7938. Removing label 'Needs backport'.

thokon00 pushed a commit to faircoin/faircoin that referenced this pull request Jun 28, 2016
deadalnix pushed a commit to deadalnix/bitcoin that referenced this pull request Feb 27, 2017
After discussion in bitcoin#7164 I think this is better.

Max tip age was introduced in bitcoin#5987 to make it possible to run
testnet-in-a-box. But associating this behavior with the testnet chain
is wrong conceptually, as it is not needed in normal usage.
Should aim to make testnet test the software as-is.

Replace it with a (debug) option `-maxtipage`, which can be
specified only in the specific case.
zkbot added a commit to zcash/zcash that referenced this pull request Jan 6, 2021
Skip "tx" messages during initial block download.

We avoid requesting these messages by not request non-block inventory during IBD.
This is equivalent to bitcoin/bitcoin#7164, but we also
ignore unsolicited `tx` messages (which `zcashd` nodes will never send).

Fixes #4943.
@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.

None yet

9 participants