bitcoin/bitcoin — pull request #1233 by TheBlueMatt (2012-05-09 06:28:29+00:00)
Title: Buffer block downloading and commit/check blocks in parallel

This is based on cblockstore and commits blocks in a separate thread from downloading/initial checking (in CheckBlock). It offers a nice performance gain over cblockstore alone.

* pfrom->Misbehaving is now called in a callback instead of after EmitBlock as nDoS is not known until the block is committed. This could give us a bit more work to do from a bad node's blocks, but should be pretty safe as the buffer is limited to 20 blocks by default (-blockbuffersize).

* A setBlocksSeen is added which holds a set of blocks which have passed basic DOS checks (CheckBlock and the minwork computations), ie is the list of orphans + accepted blocks. This allows us to avoid cs_main locking when doing the duplicate detection in the initial checking

* FinishEmitBlock callbacks are done in series and, therefore, CBlockStore had to be changed to allow for InOrder callback threads. Though FinishEmitBlock callbacks could be called out of order, this would result in a significant number of "orphan" blocks being committed before being merged into the main block tree, which is pretty ugly and inefficiency.

* GetLastCheckpoint now returns a cached value instead of scanning mapBlockIndex each time. This is primarily to avoid a cs_main lock in the initial checking, but is also a micro-optimization.