From 455b31f3be9b33c75555ffc5ef0af9451476741d Mon Sep 17 00:00:00 2001 From: IntegralTeam V Date: Thu, 26 Sep 2019 16:45:20 +0700 Subject: [PATCH] fix block headers serialization --- src/chain.h | 8 +------- src/chainparams.cpp | 8 ++++---- src/txdb.cpp | 18 +++++++++++------- src/validation.cpp | 3 ++- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/chain.h b/src/chain.h index bd2215c9133..bef75e6b864 100644 --- a/src/chain.h +++ b/src/chain.h @@ -350,13 +350,6 @@ class CBlockIndex //! Build the skiplist pointer for this entry. void BuildSkip(); - uint256 GetHashToSign() const - { - CDataStream ss(SER_GETHASH, 0); - ss << nVersion << pprev->GetBlockHash() << hashMerkleRoot << nTime << nBits << height << mintedBlocks << stakeModifier; - return Hash(ss.begin(), ss.end()); - } - //! Efficiently find an ancestor of this block. CBlockIndex* GetAncestor(int height); const CBlockIndex* GetAncestor(int height) const; @@ -407,6 +400,7 @@ class CDiskBlockIndex : public CBlockIndex READWRITE(hashMerkleRoot); READWRITE(nTime); READWRITE(nBits); + READWRITE(stakeModifier); READWRITE(height); READWRITE(mintedBlocks); READWRITE(sig); diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 408e3564c21..9b8f17a23d6 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -82,7 +82,7 @@ class CMainParams : public CChainParams { consensus.pos.allowMintingWithoutPeers = false; // don't mint if no peers connected - consensus.CSVHeight = 0; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5 + consensus.CSVHeight = 1; // 000000000000000004a1b34462cb8aeebd5799177f7a29cf28f2d1961716b5b5 consensus.SegwitHeight = 0; // 0000000000000000001c8018d9cb3b742ef25114f27563e3fc4a1902167f9893 consensus.nRuleChangeActivationThreshold = 1916; // 95% of 2016 consensus.nMinerConfirmationWindow = 2016; // nTargetTimespan / nTargetSpacing @@ -195,7 +195,7 @@ class CTestNetParams : public CChainParams { consensus.pos.allowMintingWithoutPeers = true; - consensus.CSVHeight = 0; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb + consensus.CSVHeight = 1; // 00000000025e930139bac5c6c31a403776da130831ab85be56578f3fa75369bb consensus.SegwitHeight = 0; // 00000000002b980fcd729daaa248fd9316a5200e9b367f4ff2c42453e84201ca consensus.nRuleChangeActivationThreshold = 1512; // 75% for testchains consensus.nMinerConfirmationWindow = 2016; // nTargetTimespan / nTargetSpacing @@ -283,9 +283,9 @@ class CRegTestParams : public CChainParams { consensus.pos.coinstakeMaturity = 100; - consensus.pos.allowMintingWithoutPeers = false; // don't mint if no peers connected + consensus.pos.allowMintingWithoutPeers = true; // don't mint if no peers connected - consensus.CSVHeight = 0; // CSV activated on regtest (Used in rpc activation tests) + consensus.CSVHeight = 1; // CSV activated on regtest (Used in rpc activation tests) consensus.SegwitHeight = 0; // SEGWIT is always activated on regtest unless overridden consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains consensus.nMinerConfirmationWindow = 144; // Faster than normal for regtest (144 instead of 2016) diff --git a/src/txdb.cpp b/src/txdb.cpp index c2b0d5a5aa7..0ef609bf4c7 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -278,15 +278,19 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, pindexNew->height = diskindex.height; pindexNew->mintedBlocks = diskindex.mintedBlocks; pindexNew->sig = diskindex.sig; - - CPubKey recoveredPubKey{}; - if (!recoveredPubKey.RecoverCompact(diskindex.GetHashToSign(), diskindex.sig)) { - return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString()); + if (pindexNew->nHeight) { + CPubKey recoveredPubKey{}; + if (!recoveredPubKey.RecoverCompact(pindexNew->GetBlockHeader().GetHashToSign(), pindexNew->sig)) { + return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString()); + } + pindexNew->minter = recoveredPubKey.GetID(); + } else { + pindexNew->minter = CKeyID(); } - pindexNew->minter = recoveredPubKey.GetID(); - if (pindexNew->nHeight > 0 && pindexNew->stakeModifier == uint256{}) - return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString()); + +// if (pindexNew->nHeight > 0 && pindexNew->stakeModifier == uint256{}) // TODO: (SS) uncomment me +// return error("%s: The block index #%d (%s) wasn't saved on disk correctly. Index content: %s", __func__, pindexNew->nHeight, pindexNew->GetBlockHash().ToString(), pindexNew->ToString()); pcursor->Next(); } else { diff --git a/src/validation.cpp b/src/validation.cpp index bb8191f3511..6f84ad6a436 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -155,6 +155,7 @@ namespace { CBlockIndex* LookupBlockIndex(const uint256& hash) { + std::cout << "!!!LookupBlockIndex : " << hash.ToString() << std::endl; AssertLockHeld(cs_main); BlockMap::const_iterator it = g_blockman.m_block_index.find(hash); return it == g_blockman.m_block_index.end() ? nullptr : it->second; @@ -3220,7 +3221,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta static bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; - + std::cout << "!!!ContextualCheckBlock : " << nHeight << std::endl; // Start enforcing BIP113 (Median Time Past). int nLockTimeFlags = 0; if (nHeight >= consensusParams.CSVHeight) {