Skip to content

Commit

Permalink
Expose check_pow for compact blocks, helper to get available Tx list
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Dec 18, 2018
1 parent d1eaa44 commit 6c91446
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/blockencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {
return SipHashUint256(shorttxidk0, shorttxidk1, txhash) & 0xffffffffffffL;
}


std::vector<CTransactionRef> PartiallyDownloadedBlock::GetAvailableTx() {
std::vector<CTransactionRef> 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<std::pair<uint256, CTransactionRef>>& extra_txn) {
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
Expand Down Expand Up @@ -173,7 +179,7 @@ bool PartiallyDownloadedBlock::IsTxAvailable(size_t index) const {
return txn_available[index] != nullptr;
}

ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing) {
ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing, bool check_pow) {
assert(!header.IsNull());
uint256 hash = header.GetHash();
block = header;
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/blockencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,11 @@ class PartiallyDownloadedBlock {
CBlockHeader header;
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}

std::vector<CTransactionRef> GetAvailableTx();
// extra_txn is a list of extra transactions to look at, in <witness hash, reference> form
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);
bool IsTxAvailable(size_t index) const;
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing, bool check_pow = true);
};

#endif // BITCOIN_BLOCKENCODINGS_H

0 comments on commit 6c91446

Please sign in to comment.