Skip to content

Commit

Permalink
Merge bitcoin#15991: Bugfix: fix pruneblockchain returned prune height
Browse files Browse the repository at this point in the history
f402012 fixup: Fix prunning test (João Barbosa)
97f517d Fix RPC/pruneblockchain returned prune height (Jonas Schnelli)

Pull request description:

  The help of `pruneblockchain` tells us that the return value is `Height of the last block pruned.`,... but the implementation naively returns the provided input `height` and therefore not respecting that pruning can't be done on all possible blockheight due to the fact that we only prune complete blockfiles (which combine multiple blocks).

  This fixes the return value to actually return the correct prune height.

ACKs for commit f40201:
  MarcoFalke:
    ACK f402012

Tree-SHA512: 88c910030ffb83196663e5ebebc29d036fcdbbb2ab266e4538991867924a61bacd8361c1fbf294a0ea7e02347ae183d792f10a10b8f6187e8a4c4c6e4124d7e6
  • Loading branch information
jonasschnelli committed Jun 13, 2019
2 parents afab131 + f402012 commit 431d81b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,12 @@ static UniValue pruneblockchain(const JSONRPCRequest& request)
}

PruneBlockFilesManual(height);
return uint64_t(height);
const CBlockIndex* block = ::ChainActive().Tip();
assert(block);
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
block = block->pprev;
}
return uint64_t(block->nHeight);
}

static UniValue gettxoutsetinfo(const JSONRPCRequest& request)
Expand Down
19 changes: 3 additions & 16 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
wait_until,
)

MIN_BLOCKS_TO_KEEP = 288

# Rescans start at the earliest block up to 2 hours before a key timestamp, so
# the manual prune RPC avoids pruning blocks in the same window to be
# compatible with pruning based on key creation time.
Expand Down Expand Up @@ -273,20 +271,9 @@ def height(index):
else:
return index

def prune(index, expected_ret=None):
def prune(index):
ret = node.pruneblockchain(height=height(index))
# Check the return value. When use_timestamp is True, just check
# that the return value is less than or equal to the expected
# value, because when more than one block is generated per second,
# a timestamp will not be granular enough to uniquely identify an
# individual block.
if expected_ret is None:
expected_ret = index
if use_timestamp:
assert_greater_than(ret, 0)
assert_greater_than(expected_ret + 1, ret)
else:
assert_equal(ret, expected_ret)
assert_equal(ret, node.getblockchaininfo()['pruneheight'])

def has_block(index):
return os.path.isfile(os.path.join(self.nodes[node_number].datadir, "regtest", "blocks", "blk{:05}.dat".format(index)))
Expand Down Expand Up @@ -326,7 +313,7 @@ def has_block(index):
assert not has_block(1), "blk00001.dat is still there, should be pruned by now"

# height=1000 should not prune anything more, because tip-288 is in blk00002.dat.
prune(1000, 1001 - MIN_BLOCKS_TO_KEEP)
prune(1000)
assert has_block(2), "blk00002.dat is still there, should be pruned by now"

# advance the tip so blk00002.dat and blk00003.dat can be pruned (the last 288 blocks should now be in blk00004.dat)
Expand Down

0 comments on commit 431d81b

Please sign in to comment.