From 3d3a117bde2c926950b08188069298cc91889941 Mon Sep 17 00:00:00 2001 From: Michael Toutonghi Date: Tue, 15 May 2018 05:00:00 -0700 Subject: [PATCH] Fix forking potential at startup --- src/komodo_bitcoind.h | 2 +- src/main.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index d42a8f9e6..840e01472 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1323,7 +1323,7 @@ bool verusCheckPOSBlock(int32_t slowflag, CBlock *pblock, int32_t height) { fprintf(stderr,"ERROR: invalid PoS block %s - invalid diff target\n",blkHash.ToString().c_str()); } - else if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey,voutaddress) && + else if ( ExtractDestination(pblock->vtx[txn_count-1].vout[0].scriptPubKey, voutaddress) && ExtractDestination(tx.vout[voutNum].scriptPubKey, destaddress) ) { strcpy(voutaddr, CBitcoinAddress(voutaddress).ToString().c_str()); diff --git a/src/main.cpp b/src/main.cpp index d3b0c1d7e..44eb29f83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2840,6 +2840,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin else fprintf(stderr,"checktoshis %.8f numvouts %d\n",dstr(checktoshis),(int32_t)block.vtx[0].vout.size()); } } + if (ASSETCHAINS_SYMBOL[0] != 0 && pindex->nHeight == 1 && block.vtx[0].GetValueOut() != blockReward) + { + return state.DoS(100, error("ConnectBlock(): coinbase for block 1 pays wrong amount (actual=%d vs correct=%d)", block.vtx[0].GetValueOut(), blockReward), + REJECT_INVALID, "bad-cb-amount"); + } if ( block.vtx[0].GetValueOut() > blockReward+1 ) { if ( ASSETCHAINS_SYMBOL[0] != 0 || pindex->nHeight >= KOMODO_NOTARIES_HEIGHT1 || block.vtx[0].vout[0].nValue > blockReward ) @@ -3326,13 +3331,6 @@ static bool ActivateBestChainStep(CValidationState &state, CBlockIndex *pindexMo const CBlockIndex *pindexOldTip = chainActive.Tip(); const CBlockIndex *pindexFork = chainActive.FindFork(pindexMostWork); - // asset chains cannot reorg past block 1, which is specific to the asset chain - if (ASSETCHAINS_SYMBOL[0] != 0 && pindexFork && pindexFork->nHeight < 1 && chainActive.Tip()->nHeight != pindexFork->nHeight) - { - LogPrintf("Failed attempt to reorg past block 1 in asset chain %s\n", ASSETCHAINS_SYMBOL); - return false; - } - // - On ChainDB initialization, pindexOldTip will be null, so there are no removable blocks. // - If pindexMostWork is in a chain that doesn't have the same genesis block as our chain, // then pindexFork will be null, and we would need to remove the entire chain including