Skip to content

Extend checkpointing to 24 hours in the past. - #143

Merged
zander merged 1 commit into
bitcoinclassic:developfrom
zander:checkpoints
Apr 5, 2016
Merged

zander merged 1 commit into
bitcoinclassic:developfrom
zander:checkpoints

Conversation

@zander

@zander zander commented Mar 10, 2016

Copy link
Copy Markdown

Checkpoints are hardcoded points that are shipped in the client and we
skip checking of script validity if they come before a checkpoint.
This change builds on that and extends the no-check requirement from
known good points to proven-good points.
A chain with more than 24 hours work on it has proven to be correct
and we can skip the checking of scripts.

@christophebiocca

Copy link
Copy Markdown

Is this active only during initial sync?

Also haven't we had accidental forks last longer than 24 hours before? What would this code do in such a situation?

@zander

zander commented Mar 10, 2016

Copy link
Copy Markdown
Author

Is this active only during initial sync?

It is active during any sync that has more backlog that 24 hours of blocks.

Also haven't we had accidental forks last longer than 24 hours before? What would this code do in such a situation?

I don't think we had those, care to elaborate?

Only the checking of signatures is skipped. The block merkle hashes are still computed and checked, so the proof of work needed to create such a fork is still going to be the needed and we validate that its done properly.

@christophebiocca

Copy link
Copy Markdown

I don't think we had those, care to elaborate?

I was thinking of the March 2013 fork but:

  • It was only 6 hours.
  • This patch wouldn't have changed anything (because the locks issue was in the UTXO set modification, which would still happen with this code).

So nevermind that.

Comment thread src/main.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't the check be for number of blocks instead? Explanation here:

https://www.reddit.com/r/Bitcoin/comments/49v808/peter_todd_on_twitter_tldr_bitcoin_classic_is/d0v5tqy

EDIT: As many people I misunderstood this as signature of blocks, not in blocks. Gavin explained it here:

https://twitter.com/gavinandresen/status/708038930986303490

Leaving my comment as I hope it will help others understand the change better.

@ChronosCrypto

Copy link
Copy Markdown

In the Bitco.in forums, jl777 recently wrote: "I am pretty sure that if you skip validation, a bootstrapping node could be vulnerable to a fake chain from the attacker."

It looks like this PR would open such a vulnerability. Thoughts?

@deadalnix

Copy link
Copy Markdown

24h ? Are you serious guys ? In case of a fork, this can open the network to serious abuse. The feature kind of make sense, but 24h is ridiculously small. Also, you don't check how much PoW has been put in a block by checking its time, but by checking its height. I hope this isn't considered seriously for merging.

@christophebiocca

Copy link
Copy Markdown

Ok, I'll just dump my analysis here in case it helps others who are trying to figure out the pros/cons:

Benefits

  • 10% faster initial sync (because we only check 24 hours of signatures).
  • Sometimes faster catchup (if you were offline for a long time).

Drawbacks

  • This effectively lowers you to a quasi SPV level of security (slightly better because it validates that the UTXO changes are consistent). SPV has been safe in practice for most people, but if you're still running a full node, it's likely because you want the security guarantees it provides (or you're just helping the network, in which case validation of blocks is the point).
  • It leaves no information about which blocks were validated, and which were skipped over. This would make recovering really tricky without regenerating the whole chainstate.
  • Unlike the checkpoints (which can only break if you use a checkpoint that turns out to be invalid despite the scrutiny all releases go through), this can break based on network conditions. That is, correctness of checkpoint-behaviour is known at compile time, this isn't.
  • Most of the performance gains present here could be achieved with just including more recent checkpoints (a week old or whatever) with each release.
  • Using time instead of height or (even better) total additional work weakens guarantees further.

Unknowns

  • If all miners start working on a chain with 1 invalid block, this code (I think) will reject it at first, then silently switch over after 24 hours. I may be wrong about that.
  • We don't know how having this would change miner's incentives to not behave badly.
  • Does this check fees/coinbase transaction? If not we do run the risk of miners trying to ignore the halving.

@tl121

tl121 commented Mar 10, 2016

Copy link
Copy Markdown

This pull request will reduce network reliability and confidence in network reliability at the expense of improving performance in one time only case (initial sync) or rare cases of properly operated nodes (catch up after node down case). Performance in both these cases is presently acceptable for users with adequate computers. Users not willing to run a bitcoin node 24/7 should run SPV wallets.

Checkpoints are acceptable in time frames of months, and for historical data. This allows any errors or hacks to become exposed and spread throughout the community at human speeds. They are a questionable optimization at best when used in periods of months. They strike me as insane if used in a time frame measured in days.

@jtoomim

jtoomim commented Mar 11, 2016

Copy link
Copy Markdown

Everybody: note that this is the develop branch, not master. This is an idea that is being played around with, and nothing more.

@zander: nTime is insecure against trickery. See https://www.reddit.com/r/btc/comments/428tjl/softforking_the_block_time_to_2_min_my_primarily/ for an example of things you can do to manipulate it.

An improvement would be to use

if (IsInitialBlockDownload() && block.nTime > yesterday)

since IsInitialBlockDownload() checks to see if the chain tip is at least 144 blocks behind the best seen header. The block.nTime > yesterday check is still needed to make sure that the last day's worth of blocks are checked.

I'm unconvinced that this would be safe even with the IsInitialBlockDownload() check. Perhaps more than 144 blocks should be required? Perhaps a check to make sure that the node was recently restarted? E.g., switching into this mode when we've been online continuously for 30 days just because some miners created and broadcast an abnormal chain would be a bad thing.

I'm unconvinced this is going to provide a very large performance benefit, since (a) you still have to update the UTXO, which takes more time than signature verification unless you've changed the -dbcache setting (or have an enterprise-grade SSD), and (b) most of the benefit could also be obtained by just adding some new checkpoints to chainparams.cpp, which is easier and a lot safer. (Currently, the most recent checkpoint is block 295000.)

@NiKiZe

NiKiZe commented Mar 11, 2016

Copy link
Copy Markdown

Sounds like a good idea to catch up quickly, however unverified blocks should not be distributed to other nodes, and to validate these blocks there should be a background thread or something similar started to check all the signatures. (there can be one thread per core to take advantage of multi core systems and thus speed up the process)

@jtoomim

jtoomim commented Mar 11, 2016

Copy link
Copy Markdown

It would also be a good idea to make this behavior configurable with one or more command-line options.

@Polve

Polve commented Mar 11, 2016

Copy link
Copy Markdown

I would find optimal to pass a command line option with the hash of a trusted checkpoint.

This way, if no checkpoint is passed the program uses the hardcoded one, otherwise the one trusted by the operator.

@zander

zander commented Mar 11, 2016

Copy link
Copy Markdown
Author

I'm a bit surprised about the amount of interest on this pull request, which was mostly get get Travis to build and test it on all platforms...

I have to say I am very thankful for the amount of reviews and amount of thought that went into the ideas how to attack this. When writing this I tried hard to find a way to attack this and systematically rejected any threats. Its awesome to have all you guys try to attack it too. Thats what makes Bitcoin better!

I have so far not heard any actual credible attack vector yet.

The threat model of Bitcoin has for as long as I remember stated that the majority of the miners have to be honest. This makes sense since if the majority of the hashpower is against the coin they are protecting, the value of that coin goes down to zero. This is the basis of Bitcoin guys!
The attacks proposed by Peter would require a 51% attack (off-grid) for more than 24 hours.

Anyone suggesting that this speedup makes Bitcoin more insecure is saying that a 51% attack that lasts longer than 24 hours before all those blocks can be pushed onto the network all at the same time to actually replace the current tip. My answer to those is that if that happens, we have much bigger worries and those coins stolen would end up with practically no value anyway.

Or, simply said;
people are suggesting we kill the princess (Bitcoin here) in order to get her to cooperate. Sorry, it won't give you what you want.

@ChronosCrypto

Copy link
Copy Markdown

I have not heard a response to this concern: a bootstrapping node could be connected solely to malicious peers serving a fake chain. This PR makes such a scenario undetectable.

@dgenr8

dgenr8 commented Mar 11, 2016

Copy link
Copy Markdown

@zander Do you have any "pro" agruments to add to @christophebiocca's list?

Also, to consider:

  • There is a 1% chance of 116 or fewer blocks in 24 hours.
  • If a bug forks the network, an upgrade can't fix it after 24 hours, unless it also changes this rule.

@zander

zander commented Mar 11, 2016

Copy link
Copy Markdown
Author

People have asked about actual performance numbers. I did an offline run of about a week worth of blocks to check (actual live data).
Using a release-build, plenty of memory for the dbcache, -par 1

3 runs before this patch;
483sec, 480sec, 478 sec (thats around 8 minutes).

3 runs after this patch, all older blocks.
80 sec, 78 sec, 80 sec. (1min18)

Thats a factor 6 speedup, in short.

Comment thread src/main.cpp Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This if () block should be removed -- the hard-coded checkpoints will always be way behind the current time.

@gavinandresen

Copy link
Copy Markdown

RE: making this configurable: I vote to use the existing -checkpoints / fCheckpointsEnabled to enable or disable this feature. If somebody has bothered to set -checkpoints=0 in their bitcoin.conf, that should continue to work.

A new -checkpointtime=number_of_seconds (0/default means auto-configure based on -par) would be spiffy.

Checkpoints are hardcoded points that are shipped in the client and we
skip checking of script validity if they come before a checkpoint.

This change builds on that and extends the no-check requirement from
known good points to acceptable points.

It would be absurd to have more than 100 block reorg, the cost of such
an event would be catastrophic in itself (it is the reason why we have
that coinbase spending limit there), but lets be certain and make it
one day (approx 144 blocks) at minimum.
Additionally, to avoid predictability, make a node have the amount of
script-checking-threads as a multiplication factor.
@zander

zander commented Mar 18, 2016

Copy link
Copy Markdown
Author

Processed all the feedback and pushed an even simpler version.

@zander
zander merged commit dbdcba1 into bitcoinclassic:develop Apr 5, 2016
@zander
zander deleted the checkpoints branch April 5, 2016 11:58
@zander

zander commented Apr 5, 2016

Copy link
Copy Markdown
Author

Further feedback always welcome!

@HostFat

HostFat commented Apr 5, 2016

Copy link
Copy Markdown

Last time that I've read about this on Slack, it was advised 7 days instead of one ...

@zander

zander commented Apr 5, 2016

Copy link
Copy Markdown
Author

Last time that I've read about this on Slack, it was advised 7 days instead of one ...

Please read the code that was actually merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.