Retain only the most recent time samples
authorMichael Hendricks <michael@ndrix.org>
Wed, 30 Nov 2011 03:15:59 +0000 (20:15 -0700)
committerMichael Hendricks <michael@ndrix.org>
Fri, 2 Dec 2011 00:28:14 +0000 (17:28 -0700)
commit1c4aab926e0b25e0c896d4703d858eda1eb14ea5
tree240889e74db6e8ebdbdbad818c7056d964eadde8
parent5e1ddc421060e24bdcda75a863d9a5e03e633423
Retain only the most recent time samples

Remembering all time samples makes nTimeOffset slow to respond to
system clock corrections.  For instance, I start my node with a system
clock that's 30 minutes slow and run it for a few days.  During that
time, I accumulate 10,000 offset samples with a median of 1800
seconds.  Now I correct my system clock.  Without this change, my node
must collect another 10,000 samples before nTimeOffset is correct
again.  With this change, I must only accumulate 100 samples to
correct the offset.

Storing unlimited time samples also allows an attacker with many IP
addresses (ex, a large botnet) to perform a memory exhaustion attack
against Bitcoin nodes.  The attacker sends a version message from each
IP to his target, consuming more of the target's memory each time.
Time samples are small, so this attack might be impractical under the
old code, but it's impossible with the new code.
src/util.cpp
src/util.h