From 13a737de71b840b93df9342522aa043f9b35643b Mon Sep 17 00:00:00 2001 From: Brannon King Date: Tue, 7 Jan 2020 13:45:15 -0700 Subject: [PATCH] fixed blockfilter_index_tests --- src/chainparams.cpp | 2 +- src/index/blockfilterindex.cpp | 17 +++++++++++------ src/test/blockfilter_index_tests.cpp | 5 +++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index de1be5b62..1804f7799 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -331,7 +331,7 @@ public: // FIXME: update heights and add activation tests consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests) consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests) - consensus.CSVHeight = 432; // CSV activated on regtest (Used in rpc activation tests) + consensus.CSVHeight = 0; // CSV activated on regtest (Used in rpc activation tests) consensus.SegwitHeight = 150; // SEGWIT is always activated on regtest unless overridden consensus.MinBIP9WarningHeight = 294; consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); diff --git a/src/index/blockfilterindex.cpp b/src/index/blockfilterindex.cpp index 68712cfac..197939185 100644 --- a/src/index/blockfilterindex.cpp +++ b/src/index/blockfilterindex.cpp @@ -60,7 +60,10 @@ BlockFilterIndex::BlockFilterIndex(BlockFilterType filter_type, bool BlockFilterIndex::Init() { - m_db->ReadFilePos(m_next_filter_pos); + if (!m_db->ReadFilePos(m_next_filter_pos)) { + m_next_filter_pos.nFile = 0; + m_next_filter_pos.nPos = 0; + } return BaseIndex::Init(); } @@ -175,7 +178,8 @@ bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex BlockFilter filter(m_filter_type, block, block_undo); size_t bytes_written = WriteFilterToDisk(m_next_filter_pos, filter); - if (bytes_written == 0) return false; + if (bytes_written == 0) + return false; (*m_db) << "INSERT INTO block VALUES(?, ?, ?, ?, ?, ?)" << pindex->nHeight @@ -185,7 +189,7 @@ bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex << m_next_filter_pos.nFile << m_next_filter_pos.nPos; - if (!(m_db->rows_modified() > 0)) { + if (m_db->rows_modified() <= 0) { return false; } @@ -193,10 +197,11 @@ bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex return true; } -static bool CopyHeightIndexToHashIndex(sqlite::database& db, - int start_height, int stop_height) +static bool CopyHeightIndexToHashIndex(sqlite::database& db, int start_height, int stop_height) { - db << "UPDATE block SET height = NULL WHERE height >= ? and height <= ?" + if (start_height > stop_height) + return true; + db << "UPDATE block SET height = NULL WHERE height BETWEEN ? AND ?" << start_height << stop_height; return db.rows_modified() > 0; } diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp index cf87aa930..f1303b1c4 100644 --- a/src/test/blockfilter_index_tests.cpp +++ b/src/test/blockfilter_index_tests.cpp @@ -76,10 +76,11 @@ static CBlock CreateBlock(const CBlockIndex* prev, std::unique_ptr pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey); CBlock& block = pblocktemplate->block; block.hashPrevBlock = prev->GetBlockHash(); + block.hashClaimTrie = uint256S("0x0000000000000000000000000000000000000000000000000000000000000001"); block.nTime = prev->nTime + 1; // Replace mempool-selected txns with just coinbase plus passed-in txns: - block.vtx.resize(1); + block.vtx.resize(1); // coinbase TXN for (const CMutableTransaction& tx : txns) { block.vtx.push_back(MakeTransactionRef(tx)); } @@ -87,7 +88,7 @@ static CBlock CreateBlock(const CBlockIndex* prev, unsigned int extraNonce = 0; IncrementExtraNonce(&block, prev, extraNonce); - while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce; + while (!CheckProofOfWork(block.GetPoWHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce; return block; }