From 6c91446982506f98c1bae3421ef9a62d9acba8d0 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 5 Dec 2018 20:25:29 +0100 Subject: [PATCH] Expose check_pow for compact blocks, helper to get available Tx list --- src/blockencodings.cpp | 12 +++++++++--- src/blockencodings.h | 3 ++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/blockencodings.cpp b/src/blockencodings.cpp index b17ff3507d..2f756f5467 100644 --- a/src/blockencodings.cpp +++ b/src/blockencodings.cpp @@ -43,7 +43,13 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const { return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL; } - +std::vector PartiallyDownloadedBlock::GetAvailableTx() { + std::vector found_tx; + for (unsigned int i = 0; i < txn_available.size(); i++) { + if (txn_available[i]) found_tx.push_back(txn_available[i]); + } + return found_tx; +} ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector>& extra_txn) { if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty())) @@ -173,7 +179,7 @@ bool PartiallyDownloadedBlock::IsTxAvailable(size_t index) const { return txn_available[index] != nullptr; } -ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector& vtx_missing) { +ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector& vtx_missing, bool check_pow) { assert(!header.IsNull()); uint256 hash = header.GetHash(); block = header; @@ -197,7 +203,7 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector< return READ_STATUS_INVALID; CValidationState state; - if (!CheckBlock(block, state, Params().GetConsensus())) { + if (!CheckBlock(block, state, Params().GetConsensus(), check_pow)) { // TODO: We really want to just check merkle tree manually here, // but that is expensive, and CheckBlock caches a block's // "checked-status" (in the CBlock?). CBlock should be able to diff --git a/src/blockencodings.h b/src/blockencodings.h index fad1f56f54..75c9c698bf 100644 --- a/src/blockencodings.h +++ b/src/blockencodings.h @@ -200,10 +200,11 @@ class PartiallyDownloadedBlock { CBlockHeader header; explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {} + std::vector GetAvailableTx(); // extra_txn is a list of extra transactions to look at, in form ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector>& extra_txn); bool IsTxAvailable(size_t index) const; - ReadStatus FillBlock(CBlock& block, const std::vector& vtx_missing); + ReadStatus FillBlock(CBlock& block, const std::vector& vtx_missing, bool check_pow = true); }; #endif // BITCOIN_BLOCKENCODINGS_H