Skip to content

Commit f7a41c5

Browse files
committed
finalizecompactblock: Fix it, make test easier to fail
1 parent 8bbd5a3 commit f7a41c5

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/rpc/mining.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,7 @@ UniValue finalizecompactblock(const JSONRPCRequest& request)
13681368

13691369
// Cached transactions
13701370
std::vector<unsigned char> found_tx(ParseHex(request.params[2].get_str()));
1371-
CDataStream ssFound(block_tx, SER_NETWORK, PROTOCOL_VERSION);
1371+
CDataStream ssFound(found_tx, SER_NETWORK, PROTOCOL_VERSION);
13721372

13731373
std::vector<CTransactionRef> found;
13741374
ssFound >> found;
@@ -1380,10 +1380,21 @@ UniValue finalizecompactblock(const JSONRPCRequest& request)
13801380
CTxMemPool dummy_pool;
13811381
PartiallyDownloadedBlock partialBlock(&dummy_pool);
13821382

1383-
const std::vector<std::pair<uint256, CTransactionRef>> dummy;
1383+
// "Extra" list is really our combined list that will be put into place using InitData
1384+
std::vector<std::pair<uint256, CTransactionRef>> extra_txn;
1385+
for (const auto& found_tx : found) {
1386+
extra_txn.push_back(std::make_pair(found_tx->GetWitnessHash(), found_tx));
1387+
}
13841388
std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
1385-
if (partialBlock.InitData(cmpctblock, dummy) != READ_STATUS_OK || partialBlock.FillBlock(*pblock, found, false /* pow_check*/) != READ_STATUS_OK) {
1389+
if (partialBlock.InitData(cmpctblock, extra_txn) != READ_STATUS_OK) {
1390+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "compact_hex appears malformed.");
1391+
}
1392+
const std::vector<CTransactionRef> dummy_missing;
1393+
auto result = partialBlock.FillBlock(*pblock, dummy_missing, false /* pow_check*/);
1394+
if (result == READ_STATUS_FAILED) {
13861395
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.");
1396+
} else if (result != READ_STATUS_OK) {
1397+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Failed to complete block though all transactions were apparently found.");
13871398
}
13881399

13891400
CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);

test/functional/feature_blocksign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def mine_block(self, make_transactions):
109109

110110
# Make a few transactions to make non-empty blocks for compact transmission
111111
if make_transactions:
112-
for i in range(5):
112+
for i in range(20):
113113
miner.sendtoaddress(miner_next.getnewaddress(), int(miner.getbalance()['bitcoin']/10), "", "", True)
114114
# miner makes a block
115115
block = miner.getnewblockhex()

0 commit comments

Comments
 (0)