No description provided.
[rpc] getblockchaininfo: add size_on_disk, prune_target_size #11367
pull esotericnonsense wants to merge 1 commits into bitcoin:master from esotericnonsense:2017-09-getblockchaininfo-addsize changing 4 files +58 −13-
esotericnonsense commented at 8:38 AM on September 19, 2017: contributor
- fanquake added the label RPC/REST/ZMQ on Sep 19, 2017
-
esotericnonsense commented at 8:54 AM on September 19, 2017: contributor
If #11359 gets in it might be nice to have the prune hwm in there too, but I didn't want to add the dependency.
-
in src/rpc/blockchain.cpp:1140 in a2d851fff5 outdated
1136 | @@ -1137,6 +1137,8 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1137 | " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" 1138 | " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" 1139 | " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored\n" 1140 | + " \"disk_size\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n"
jnewbery commented at 6:08 PM on September 19, 2017:nit: perhaps
disk_usageorsize_on_disk?Also consider placing this above
prunedso all of the pruning-related fields are grouped.
promag commented at 10:35 PM on September 19, 2017:Also align description.
jnewbery commented at 6:13 PM on September 19, 2017: memberconcept ACK. One nit inline.
Consider adding an explicit test for the
getblockchaininfoRPC method totest/functional/blockchain.py.in src/rpc/blockchain.cpp:1185 in a2d851fff5 outdated
1181 | @@ -1180,6 +1182,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1182 | obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); 1183 | obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); 1184 | obj.push_back(Pair("pruned", fPruneMode)); 1185 | + obj.push_back(Pair("disk_size", CalculateCurrentUsage()));
promag commented at 10:45 PM on September 19, 2017:Missing lock of
cs_LastBlockFile.esotericnonsense force-pushed on Sep 20, 2017esotericnonsense renamed this:RPC: getblockchaininfo: Add disk_size, prune_target_size
[rpc] getblockchaininfo: add size_on_disk, prune_target_size
on Sep 20, 2017esotericnonsense force-pushed on Sep 20, 2017esotericnonsense force-pushed on Sep 20, 2017esotericnonsense commented at 3:05 PM on September 20, 2017: contributoresotericnonsense force-pushed on Sep 20, 2017in src/rpc/blockchain.cpp:1140 in ae3cbb994c outdated
1134 | @@ -1135,8 +1135,10 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1135 | " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n" 1136 | " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" 1137 | " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" 1138 | + " \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n" 1139 | " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" 1140 | " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored\n"
jnewbery commented at 7:48 PM on September 20, 2017:The help text for
pruneheightshould also include "(only present if pruning is enabled)"
esotericnonsense commented at 11:53 PM on September 20, 2017:4a61af9
jnewbery commented at 7:49 PM on September 20, 2017: memberone more documentation nit. Otherwise looks good to me
esotericnonsense force-pushed on Sep 20, 2017in src/validation.h:159 in 4a61af9666 outdated
155 | @@ -156,6 +156,7 @@ struct BlockHasher 156 | 157 | extern CScript COINBASE_FLAGS; 158 | extern CCriticalSection cs_main; 159 | +extern CCriticalSection cs_LastBlockFile;
sipa commented at 12:05 AM on September 21, 2017:I'd rather not expose more variables that are private to validation to the outside world.
Perhaps you can instead create a wrapper around
CalculateCurrentUsage, which just grabscs_LastBlockFileand calls the internal one, and expose that? That way the RPC code wouldn't need to know about the existence of that lock eve.
promag commented at 9:03 AM on September 21, 2017:Why not just lock
cs_LastBlockFileinCalculateCurrentUsage? It's a recursive mutex and IMO should be locked where it's needed (BTW the same for remaining locks...).in src/rpc/blockchain.cpp:1187 in 4a61af9666 outdated
1180 | @@ -1179,7 +1181,18 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1181 | obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast())); 1182 | obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); 1183 | obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); 1184 | + obj.push_back(Pair("size_on_disk", CalculateCurrentUsage())); 1185 | obj.push_back(Pair("pruned", fPruneMode)); 1186 | + if (fPruneMode) { 1187 | + CBlockIndex *block = chainActive.Tip();
promag commented at 9:04 AM on September 21, 2017:CBlockIndex* block = ...;in src/rpc/blockchain.cpp:1173 in 4a61af9666 outdated
1169 | @@ -1168,7 +1170,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1170 | + HelpExampleRpc("getblockchaininfo", "") 1171 | ); 1172 | 1173 | - LOCK(cs_main); 1174 | + LOCK2(cs_main, cs_LastBlockFile); // cs_LastBlockFile for CalculateCurrentUsage()
jonasschnelli commented at 5:24 AM on September 22, 2017:As @sipa already commented,
CalculateCurrentUsage()should be responsible for concurrency locking (not the calling code part).in src/rpc/blockchain.cpp:1141 in 4a61af9666 outdated
1134 | @@ -1135,8 +1135,10 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) 1135 | " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n" 1136 | " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" 1137 | " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" 1138 | + " \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n" 1139 | " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" 1140 | - " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored\n" 1141 | + " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored (only present if pruning is enabled)\n" 1142 | + " \"prune_target_size\": xxxxxx, (numeric) the target size used by pruning (only present if pruning is enabled)\n"
jonasschnelli commented at 5:25 AM on September 22, 2017:Indentation seems wrong (others need to space-up).
esotericnonsense commented at 6:24 PM on September 22, 2017:I followed the example of 'verificationprogress'; can indent the others further if you think that makes sense.
jonasschnelli commented at 5:26 AM on September 22, 2017: contributorConcept ACK
esotericnonsense force-pushed on Sep 22, 2017esotericnonsense commented at 6:25 PM on September 22, 2017: contributorRebased on master, moved the lock into CalculateCurrentUsage,
CBlockIndex *block=>CBlockIndex* block.Travis failed on one platform (iirc linux64) on a timeout in p2p-segwit last time. Not sure why. We'll see how it goes. edit: looks good.
sipa commented at 6:53 PM on September 22, 2017: memberutACK 071879a6263aa286e166f9cf07f409e6df35bc02
jnewbery commented at 8:27 PM on September 22, 2017: memberI've just tested this with
-prune=1and I get the bizarre result:→ bitcoin-cli getblockchaininfo { ... "prune_target_size": 18446744073709551615,That's because of this section in
init.cpp:nPruneTarget = (uint64_t) nPruneArg * 1024 * 1024; if (nPruneArg == 1) { // manual pruning: -prune=1 LogPrintf("Block pruning enabled. Use RPC call pruneblockchain(height) to manually prune block and undo files.\n"); nPruneTarget = std::numeric_limits<uint64_t>::max(); fPruneMode = true; ...Returning the max int for
prune_target_sizeis meaningless and confusing. I recommend you don't returnprune_target_sizeif bitcoind is configured for manual pruning (ie if-prune=1) (and perhaps also add another fieldpruning_modethat returns whether pruning is automatic or manual).esotericnonsense commented at 10:04 PM on September 22, 2017: contributorHmmm. Yes, that isn't desirable behaviour.
Options I can see: a) nPruneArg is exposed from init.cpp, or an fPruneManualMode (in which case it could be explicitly checked for in FindFilesToPrune) or b) the RPC checks for int_max to determine whether automatic pruning is disabled
b) fixes the RPC without having to touch pruning code but otherwise seems a bit messy to me.
meshcollider commented at 3:06 AM on September 23, 2017: contributorOr instead of b) just see if gArgs.GetArg("-prune", 0) is 1? But yeah maybe adding a manual prune bool to validation.cpp would be more sensible
jnewbery commented at 11:36 AM on September 23, 2017: memberI think just testing the value of
gArgs.GetArg("-prune", 0)is appropriate for this pr. No need to touch the init or validation code.esotericnonsense force-pushed on Sep 24, 2017esotericnonsense commented at 5:07 PM on September 24, 2017: contributor$ grep "prune" ~/.bitcoin/bitcoin.conf prune=550 $ ./bitcoin-cli getblockchaininfo | grep "prune" "pruned": true, "pruneheight": 0, "pruneauto": true, "prune_target_size": 576716800, $ grep "prune" ~/.bitcoin/bitcoin.conf prune=1 $ ./bitcoin-cli getblockchaininfo | grep "prune" "pruned": true, "pruneheight": 0, "pruneauto": false, $ grep "prune" ~/.bitcoin/bitcoin.conf prune=0 $ ./bitcoin-cli getblockchaininfo | grep "prune" "pruned": false,esotericnonsense force-pushed on Sep 25, 2017esotericnonsense commented at 10:08 PM on September 25, 2017: contributorRebased on master and added tests for the relevant fields in test/functional/blockchain.py.
My box:
... blockchain.py | ✓ Passed | 13 s ... ALL | ✓ Passed | 695 s (accumulated) Runtime: 180 sin src/rpc/blockchain.cpp:1196 in bbca675c7a outdated
1191 | + block = block->pprev; 1192 | + } 1193 | + 1194 | + obj.push_back(Pair("pruneheight", block->nHeight)); 1195 | + 1196 | + bool fPruneAuto = (gArgs.GetArg("-prune", 0) > 1);
jnewbery commented at 1:48 PM on September 26, 2017:current code style is snake_case for variables (https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#developer-notes).
prune_autoorauto_pruneshould be fine.
jnewbery commented at 2:03 PM on September 26, 2017:nit: Since
1is a magic number meaning manual pruning, I think it's clearer to use equality like in init.cpp, rather than greater-than:bool fPruneAuto = (gArgs.GetArg("-prune", 0) != 1);
esotericnonsense commented at 2:36 PM on September 26, 2017:I was torn there, because that actually gives True in the case prune=0, but that case can never happen because execution would skip over the
if (fPruneMode)block. I'll change it.in src/rpc/blockchain.cpp:1197 in bbca675c7a outdated
1192 | + } 1193 | + 1194 | + obj.push_back(Pair("pruneheight", block->nHeight)); 1195 | + 1196 | + bool fPruneAuto = (gArgs.GetArg("-prune", 0) > 1); 1197 | + obj.push_back(Pair("pruneauto", fPruneAuto));
jnewbery commented at 1:48 PM on September 26, 2017:Please also use snake_case for RPC fields. I think
automatic_pruningis appropriate here.in test/functional/blockchain.py:79 in bbca675c7a outdated
74 | + 75 | # pruneheight should be greater or equal to 0 76 | assert res['pruneheight'] >= 0 77 | 78 | + # check other pruning fields given that prune=1 79 | + assert_equal(res['pruned'], True)
jnewbery commented at 1:50 PM on September 26, 2017:No need for
assert_equalwhen comparing a value toTrueorFalse. The following is fine:assert res['pruned'] assert not res['pruneauto']in test/functional/blockchain.py:95 in bbca675c7a outdated
92 | + # check related fields 93 | + assert_equal(res['pruned'], True) 94 | + assert_equal(res['pruneheight'], 0) 95 | + assert_equal(res['pruneauto'], True) 96 | + assert_equal(res['prune_target_size'], 576716800) 97 | + assert_equal(res['size_on_disk'], 55550)
jnewbery commented at 1:51 PM on September 26, 2017:suggest that you change this to assert that
size_on_diskis greater than zero. This test would fail unnecessarily if a change in the implementation changed the size on disk.in test/functional/blockchain.py:71 in bbca675c7a outdated
68 | + 69 | + # result should have these additional pruning keys if manual pruning is enabled 70 | + assert_equal(sorted(res.keys()), sorted(['pruneheight', 'pruneauto'] + keys)) 71 | + 72 | + # size_on_disk should be >= 0 73 | + assert res['size_on_disk'] >= 0
jnewbery commented at 1:52 PM on September 26, 2017:assert_greater_than_or_equal()is better here (since it will print out the value ofres['size_on_disk']if the assert fails)
esotericnonsense commented at 2:46 PM on September 26, 2017:As below I've dropped the 'equal to' because I don't see why it should ever be 0 unless there's some caching going on.
jnewbery commented at 2:09 PM on September 26, 2017: memberImplementation looks good. I've slightly tested and it works well.
A few style nits inline.
esotericnonsense force-pushed on Sep 26, 2017esotericnonsense force-pushed on Sep 26, 2017esotericnonsense commented at 2:49 PM on September 26, 2017: contributorChanges made and rebased on master (second push, first was a mistake).
jnewbery commented at 3:35 PM on September 26, 2017: memberTested ACK 2b73ece6e34961a6745114b6932945692ed987e7
in src/validation.cpp:3238 in 2b73ece6e3 outdated
3229 | @@ -3230,8 +3230,10 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, 3230 | */ 3231 | 3232 | /* Calculate the amount of disk space the block & undo files currently use */ 3233 | -static uint64_t CalculateCurrentUsage() 3234 | +uint64_t CalculateCurrentUsage() 3235 | { 3236 | + LOCK(cs_LastBlockFile);
TheBlueMatt commented at 7:35 PM on September 27, 2017:While you're at it can you add this lock to PruneOneBlockFile and GetBlockFileInfo (both of which are only called without lock during testing, so its not an actual issue, just annoying).
esotericnonsense commented at 6:51 PM on September 29, 2017:Done in b7dfc6c4b89b62f9bb79ea009ee103a6299ac005.
TheBlueMatt commented at 8:15 PM on September 27, 2017: memberutACK 2b73ece6e34961a6745114b6932945692ed987e7
MarcoFalke commented at 1:19 PM on September 29, 2017: memberNeeds rebase™
b7dfc6c4b8[rpc] getblockchaininfo: add size_on_disk, prune_target_size, automatic_pruning
Fix pruneheight help text. Move fPruneMode block to match output ordering with help text. Add functional tests for new fields in getblockchaininfo.
esotericnonsense force-pushed on Sep 29, 2017esotericnonsense commented at 6:51 PM on September 29, 2017: contributor®ebased
MarcoFalke commented at 9:08 AM on September 30, 2017: memberutA©K b7dfc6c4b89b62f9bb79ea009ee103a6299ac005
TheBlueMatt commented at 8:35 PM on October 2, 2017: memberre-utACK b7dfc6c4b89b62f9bb79ea009ee103a6299ac005. In the future, can you avoid rebasing when squashing unless you need to? Avoiding rebasing onto latest master makes it easier for reviewers to identify what changed between reviews.
esotericnonsense commented at 10:13 PM on October 2, 2017: contributorYes, I can do that in the future. I hadn't considered that. Do you prefer for each change to be made in an individual commit (with a squash before the PR is implemented)?
MarcoFalke commented at 5:58 AM on October 3, 2017: memberIt is fine to just amend the existing commits with fix-ups, as reviewers have the original commits fetched locally. So it is easy to compare the two versions.
However, with a rebase on master in between, the reviewer needs to painfully repeat the same rebase in some way.
laanwj merged this on Oct 9, 2017laanwj closed this on Oct 9, 2017laanwj referenced this in commit 3a93270c55 on Oct 9, 2017luke-jr referenced this in commit cd46034514 on Nov 11, 2017luke-jr referenced this in commit fec3a143a9 on Nov 11, 2017nmarley referenced this in commit 007c906322 on Nov 1, 2018nmarley referenced this in commit 5462995194 on Nov 1, 2018nmarley referenced this in commit 2abb2702b1 on Nov 1, 2018nmarley referenced this in commit 78654534b9 on Nov 4, 2018bitcartel referenced this in commit 719508e703 on Nov 14, 2018renuzit referenced this in commit 4232bc4fed on May 16, 2019milesmanley referenced this in commit 1b83c1dd5c on May 16, 2019garethtdavies referenced this in commit 1b791d18a4 on May 30, 2019garethtdavies referenced this in commit c347d88e43 on May 30, 2019garethtdavies referenced this in commit 69f404ed00 on May 30, 2019renuzit referenced this in commit e864cba9be on May 31, 2019PastaPastaPasta referenced this in commit 7190e996cd on Dec 22, 2019PastaPastaPasta referenced this in commit dd0b490a59 on Jan 2, 2020PastaPastaPasta referenced this in commit c1772617d4 on Jan 4, 2020PastaPastaPasta referenced this in commit 910e24125e on Jan 12, 2020PastaPastaPasta referenced this in commit 83b15d2cd2 on Jan 12, 2020PastaPastaPasta referenced this in commit 7b9b9dfb64 on Jan 12, 2020PastaPastaPasta referenced this in commit 459be640db on Jan 12, 2020PastaPastaPasta referenced this in commit d3ae079c05 on Jan 12, 2020PastaPastaPasta referenced this in commit ea146df3f0 on Jan 12, 2020PastaPastaPasta referenced this in commit 23ec9e7cc8 on Jan 12, 2020ckti referenced this in commit 88bafb3112 on Mar 28, 2021gades referenced this in commit 990493d2e9 on Jun 26, 2021DrahtBot locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me