Merge pull request #2190 from sipa/fixgenesis
Bugfix + simplify special case for genesis
This commit is contained in:
commit
5fca58cb8e
1 changed files with 8 additions and 15 deletions
23
src/main.cpp
23
src/main.cpp
|
@ -1592,6 +1592,14 @@ bool CBlock::ConnectBlock(CBlockIndex* pindex, CCoinsViewCache &view, bool fJust
|
||||||
// verify that the view's current state corresponds to the previous block
|
// verify that the view's current state corresponds to the previous block
|
||||||
assert(pindex->pprev == view.GetBestBlock());
|
assert(pindex->pprev == view.GetBestBlock());
|
||||||
|
|
||||||
|
// Special case for the genesis block, skipping connection of its transactions
|
||||||
|
// (its coinbase is unspendable)
|
||||||
|
if (GetHash() == hashGenesisBlock) {
|
||||||
|
view.SetBestBlock(pindex);
|
||||||
|
pindexGenesisBlock = pindex;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool fScriptChecks = pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate();
|
bool fScriptChecks = pindex->nHeight >= Checkpoints::GetTotalBlocksEstimate();
|
||||||
|
|
||||||
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
|
// Do not allow blocks that contain transactions which 'overwrite' older transactions,
|
||||||
|
@ -1727,21 +1735,6 @@ bool SetBestChain(CBlockIndex* pindexNew)
|
||||||
// Only when all have succeeded, we push it to pcoinsTip.
|
// Only when all have succeeded, we push it to pcoinsTip.
|
||||||
CCoinsViewCache view(*pcoinsTip, true);
|
CCoinsViewCache view(*pcoinsTip, true);
|
||||||
|
|
||||||
// special case for attaching the genesis block
|
|
||||||
// note that no ConnectBlock is called, so its coinbase output is non-spendable
|
|
||||||
if (pindexGenesisBlock == NULL && pindexNew->GetBlockHash() == hashGenesisBlock)
|
|
||||||
{
|
|
||||||
view.SetBestBlock(pindexNew);
|
|
||||||
if (!view.Flush())
|
|
||||||
return false;
|
|
||||||
pindexGenesisBlock = pindexNew;
|
|
||||||
pindexBest = pindexNew;
|
|
||||||
hashBestChain = pindexNew->GetBlockHash();
|
|
||||||
nBestHeight = pindexBest->nHeight;
|
|
||||||
bnBestChainWork = pindexNew->bnChainWork;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the fork (typically, there is none)
|
// Find the fork (typically, there is none)
|
||||||
CBlockIndex* pfork = view.GetBestBlock();
|
CBlockIndex* pfork = view.GetBestBlock();
|
||||||
CBlockIndex* plonger = pindexNew;
|
CBlockIndex* plonger = pindexNew;
|
||||||
|
|
Loading…
Reference in a new issue