Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break out finalizecomaptblock errors to be more helpful #740

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/blockencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
size_t tx_missing_offset = 0;
for (size_t i = 0; i < txn_available.size(); i++) {
if (!txn_available[i]) {
if (vtx_missing.size() <= tx_missing_offset)
if (vtx_missing.size() <= tx_missing_offset) {
LogPrint(BCLog::CMPCTBLOCK, "Transactions missing arg mismatches offset in loop: %zu %zu\n", vtx_missing.size(), tx_missing_offset);
return READ_STATUS_INVALID;
}
block.vtx[i] = vtx_missing[tx_missing_offset++];
} else
block.vtx[i] = std::move(txn_available[i]);
Expand All @@ -200,17 +202,23 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
header.SetNull();
txn_available.clear();

if (vtx_missing.size() != tx_missing_offset)
if (vtx_missing.size() != tx_missing_offset) {
LogPrint(BCLog::CMPCTBLOCK, "Transactions missing arg mismatches offset: %zu %zu\n", vtx_missing.size(), tx_missing_offset);
return READ_STATUS_INVALID;
}

CValidationState state;
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
// check its own merkle root and cache that check.
if (state.CorruptionPossible())
if (state.CorruptionPossible()) {
LogPrint(BCLog::CMPCTBLOCK, "Corrupted compact block? Possible shortid collision: %s\n", state.GetRejectReason());
return READ_STATUS_FAILED; // Possible Short ID collision
}

LogPrint(BCLog::CMPCTBLOCK, "CheckBlock fail: %s\n", state.GetRejectReason());
return READ_STATUS_CHECKBLOCK_FAILED;
}

Expand Down
8 changes: 7 additions & 1 deletion src/rpc/mining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1382,8 +1382,14 @@ UniValue finalizecompactblock(const JSONRPCRequest& request)

const std::vector<std::pair<uint256, CTransactionRef>> dummy;
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
if (partialBlock.InitData(cmpctblock, dummy) != READ_STATUS_OK || partialBlock.FillBlock(*pblock, found, false /* pow_check*/) != READ_STATUS_OK) {
if (partialBlock.InitData(cmpctblock, dummy) != READ_STATUS_OK) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "compact_hex appears malformed.");
}
auto result = partialBlock.FillBlock(*pblock, found, false /* pow_check*/);
if (result == READ_STATUS_FAILED) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Failed to complete block though all transactions were apparently found. Could be random short ID collision; requires full block instead.");
} else if (result != READ_STATUS_OK) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Failed to complete block though all transactions were apparently found.");
}

CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
Expand Down