From dfda54988e9fc05c11c8fcf60b6e48f95ab1283e Mon Sep 17 00:00:00 2001 From: jl777 Date: Thu, 20 Oct 2016 08:17:05 -0300 Subject: [PATCH] test --- src/komodo.h | 17 +++++++++++++++-- src/main.cpp | 12 ++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/komodo.h b/src/komodo.h index 94d1e9282..b7a0cdf63 100644 --- a/src/komodo.h +++ b/src/komodo.h @@ -522,10 +522,23 @@ int32_t komodo_heightnotary(int32_t height,uint8_t *pubkey33) // -1 if not notary, 0 if notary, 1 if special notary } +int32_t komodo_block2height(CBlock *block) +{ + int32_t i,height = 0; uint8_t *ptr = (uint8_t *)block->vin[0].scriptSig.data(); + if ( block->vin[0].scriptSig.size() > 5 ) + { + for (i=0; i<6; i++) + printf("%02x",ptr[i]); + for (i=0; i<4; i++) + height = (height << 8) + ptr[i+2]; + printf(" <- coinbase ht.%d\n",height); + } + return(height); +} + void komodo_block2pubkey33(uint8_t *pubkey33,CBlock& block) { - uint8_t *ptr; - ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); + uint8_t *ptr = (uint8_t *)block.vtx[0].vout[0].scriptPubKey.data(); memcpy(pubkey33,ptr+1,33); } diff --git a/src/main.cpp b/src/main.cpp index 48c920b55..153336117 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2037,7 +2037,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin const CChainParams& chainparams = Params(); AssertLockHeld(cs_main); // Check it again in case a previous version let a bad block in - if (!CheckBlock(block, state, !fJustCheck, !fJustCheck)) + if (!CheckBlock(pindex->nHeight,block, state, !fJustCheck, !fJustCheck)) return false; // verify that the view's current state corresponds to the previous block @@ -2967,7 +2967,7 @@ bool CheckBlockHeader(int32_t height,const CBlock& block, const CBlockHeader& bl return true; } -bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) +bool CheckBlock(int32_t height,const CBlock& block, CValidationState& state, bool fCheckPOW, bool fCheckMerkleRoot) { // These are checks that are independent of context. @@ -3187,7 +3187,7 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex, if (fTooFarAhead) return true; // Block height is too high } - if ((!CheckBlock(block, state)) || !ContextualCheckBlock(block, state, pindex->pprev)) { + if ((!CheckBlock(pindex->nHeight,block, state)) || !ContextualCheckBlock(block, state, pindex->pprev)) { if (state.IsInvalid() && !state.CorruptionPossible()) { pindex->nStatus |= BLOCK_FAILED_VALID; setDirtyBlockIndex.insert(pindex); @@ -3236,7 +3236,7 @@ static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned bool ProcessNewBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, bool fForceProcessing, CDiskBlockPos *dbp) { // Preliminary checks - bool checked = CheckBlock(*pblock, state); + bool checked = CheckBlock(komodo_block2height(pblock),*pblock, state); { LOCK(cs_main); @@ -3276,7 +3276,7 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) return false; - if (!CheckBlock(block, state, fCheckPOW, fCheckMerkleRoot)) + if (!CheckBlock(indexDummy.nHeight,block, state, fCheckPOW, fCheckMerkleRoot)) return false; if (!ContextualCheckBlock(block, state, pindexPrev)) return false; @@ -3608,7 +3608,7 @@ bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth if (!ReadBlockFromDisk(block, pindex)) return error("VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 1: verify block validity - if (nCheckLevel >= 1 && !CheckBlock(block, state)) + if (nCheckLevel >= 1 && !CheckBlock(pindex->nHeight,block, state)) return error("VerifyDB(): *** found bad block at %d, hash=%s\n", pindex->nHeight, pindex->GetBlockHash().ToString()); // check level 2: verify undo validity if (nCheckLevel >= 2 && pindex) {