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
[rpc] fix getchaintxstats() #11021
[rpc] fix getchaintxstats() #11021
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK e73f8bc.
src/rpc/blockchain.cpp
Outdated
@@ -1516,8 +1512,14 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
} | |||
} | |||
|
|||
blockcount = std::min(blockcount, pindex->nHeight - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edge case: chain has 1 block only - blockcount
will be 0 - should be a different error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@promag Thank you for you review.
I added a commit that throws a new RPC_INVALID_PARAMETER if block's height below 2.
src/rpc/blockchain.cpp
Outdated
@@ -1512,6 +1512,9 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
} | |||
} | |||
|
|||
if (pindex->nHeight < 2) { | |||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block's height should be 2 or more."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the error should be RPC_MISC_ERROR
since it's not a parameter. The message should be something like Chain height should be greater than 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the error could be avoided by making the algorithm compatible with 1 block chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tx-rate for 1st block (and genesis block) can not calculate (or meaningless).
be avoided by making the algorithm compatible with 1 block chain.
So, I think we can treat this situation equal to nTimeDiff = 0.
Can you improve the test in |
Yes, I will add some tests in |
@promag I avoided the error about low blockheight and added some tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height - 1")
should be only for < 1
case. nblocks
is the size of the window, not really necessary to satisfy. Even the default value will throw for a chain with less than a month.
Also, CBlockIndex::GetAncestor
return nullptr
for out of bounds, just check that result.
@promag
When blockheight = 1, nblocks = 1 does not satisfy this condition. (blockheight> = 2 is required)
Of course I can add to check it , but I think that the value of the parameter is always within the range. Am I missing something? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @AkioNak . Looks great. A couple of suggestions:
- perhaps add a
"block_count"
element to the return object, so it's obvious over how many blocks the"txrate"
is being calculated. - I'd prefer to not return a
txrate
at all ifnTimeDiff
is zero, ie:
if (nTimeDiff > 0) {
ret.push_back(Pair("txrate", ((double)nTxDiff) / nTimeDiff);
}
That's just personal preference though. Tested ACK even without those changes.
One small style nit inline.
test/functional/blockchain.py
Outdated
@@ -56,6 +56,22 @@ def _test_getchaintxstats(self): | |||
# we have to round because of binary math | |||
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) | |||
|
|||
b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1)) | |||
b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200)) | |||
ntimediff = b200['mediantime'] - b1['mediantime'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: name the variable time_diff
. (the n
prefix in the C++ code is no longer the style we use, and shouldn't be carried over to the python code)
I also recommend that you update the commit messages to be a bit more meaningful. I don't think this project has commit message style rules, but there are some general tips here: https://chris.beams.io/posts/git-commit/ |
@jnewbery Thank you for your suggestion. I agree with them. |
BTW, if |
@promag No. Even if |
IMO the response could have both values |
@promag In the edge case (block height <2), since there is no comparison target, its values are both zero. If that is OK then I will add it. |
783d353
to
5eb1309
Compare
@jnewbery I have just done followings.
|
src/rpc/blockchain.cpp
Outdated
@@ -1480,6 +1480,7 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
"{\n" | |||
" \"time\": xxxxx, (numeric) The timestamp for the statistics in UNIX format.\n" | |||
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" | |||
" \"block_count\": xxxxx, (numeric) The block height that ends the window.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a confusing name; I would associate block_count
with the size of the window over which txrate
is computed. To denote the block height that ends the window, I would use height
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. My earlier suggestion was for block_count
to be the size of the window.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@promag I added both |
3ddbee7
to
02755d0
Compare
I resolved the conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good now. I have a few nits inline.
You'll need to squash your commits down. Use git rebase -i
and feel free to message me on IRC if you want some pointers on how to do that.
src/rpc/blockchain.cpp
Outdated
@@ -1479,6 +1479,9 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
"{\n" | |||
" \"time\": xxxxx, (numeric) The timestamp for the statistics in UNIX format.\n" | |||
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" | |||
" \"block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n" | |||
" \"txratecount\": xxxxx, (numeric) The number of transactions in the window.\n" | |||
" \"txrateinterval\": xxxxx, (numeric) The elapsed time in the window.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love the txratecount
and txrateinterval
names (rate and count are fundamentally different things, and txrateinterval
mentions tx but not time, but the value returned is time).
I suggest:
window_block_count
window_tx_count
window_interval
Note that new RPC arguments and return values should be snake case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also perhaps add a comment to the help text that these values are only returned if block_count
is > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to rename those names and to add condition to the help text.
src/rpc/blockchain.cpp
Outdated
if (!request.params[0].isNull()) { | ||
blockcount = request.params[0].get_int(); | ||
|
||
if (blockcount < 1 || blockcount >= pindex->nHeight) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to disallow 0? blockcount
can be 0 if we run this on a node with just the genesis block, so why not allow it to be set to 0 when running with a longer chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the reason to disallow 0 is that this RPC was originally intended to be able to calculate txrate
.
Therefore if user specifies 0 by parameter, PRC should returns illegal parameter error.
So, for only genesis block and 1st block, I think it can allow 0 internally when user is not specify block count in 1st parameter, and can avoid error to be occured.
But now, it is easier to understand if we allow 0.
src/rpc/blockchain.cpp
Outdated
ret.push_back(Pair("txratecount", nTxDiff)); | ||
ret.push_back(Pair("txrateinterval", nTimeDiff)); | ||
} | ||
if (nTimeDiff > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps move this up into the if (blockcount > 0)
code block (since nTimeDiff
can only be non-zero when blockcount
> 0)? Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to move it.
src/rpc/blockchain.cpp
Outdated
@@ -1479,6 +1479,9 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
"{\n" | |||
" \"time\": xxxxx, (numeric) The timestamp for the statistics in UNIX format.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: improve this help message as part of this PR. Perhaps:
The timestamp for the final block in the window in UNIX format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to improve that help message.
src/rpc/blockchain.cpp
Outdated
@@ -1526,7 +1535,14 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
UniValue ret(UniValue::VOBJ); | |||
ret.push_back(Pair("time", (int64_t)pindex->nTime)); | |||
ret.push_back(Pair("txcount", (int64_t)pindex->nChainTx)); | |||
ret.push_back(Pair("txrate", ((double)nTxDiff) / nTimeDiff)); | |||
if (blockcount > 0) { | |||
ret.push_back(Pair("block_count", blockcount)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps display block_count
if it is equal to zero? (but not the other two values since they're meaningless if block_count == 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to display block_count
even if it is equal to zero.
261bd2b
to
0e30d62
Compare
@jnewbery Thank you for your various suggestion. I accepted with them and squashed commits for file by file. |
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n" | ||
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" | ||
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n" | ||
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, above it's txcount
so here should be window_txcount
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine. New arguments and return values should use snake_case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to @jnewbery ,too.
src/rpc/blockchain.cpp
Outdated
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" | ||
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n" | ||
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" | ||
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window. Only returned if \"window_block_count\" is > 0.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include unit (seconds)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree to append time unit(seconds)
src/rpc/blockchain.cpp
Outdated
if (!request.params[0].isNull()) { | ||
blockcount = request.params[0].get_int(); | ||
|
||
if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->nHeight)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blockcount > 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blockcount == 0
is not an error so blockcount > 0
has to remain, I believe, for the case where pindex
points at genesis block which means pindex->nHeight == 0
.
src/rpc/blockchain.cpp
Outdated
@@ -1515,8 +1514,18 @@ UniValue getchaintxstats(const JSONRPCRequest& request) | |||
} | |||
} | |||
|
|||
if (blockcount < 1 || blockcount >= pindex->nHeight) { | |||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block count: should be between 1 and the block's height"); | |||
if (pindex->nHeight < 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to else
like:
if (!request.params[0].isNull()) {
...
} else {
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this is clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference either way!
@AkioNak thanks for sticking with this. Looks really good now. Just a few more nits. |
1. Calculate nblocks more adaptive. If not specify nblocks-parameter, illegal parameter error will happen when target block height is below blocks for 1 month. To avoid this error, set default nblocks to min(blocks for 1 month, target block's height - 1) And allowing 0 so that this RPC works good even if target block is genesis block or 1st block. 2. Correct error message. nblocks accepts [0 .. block's height -1] . so fix as following: "Invalid block count: should be between 0 and the block's height - 1" 3. Add check 0-divide. If nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. To avoid this error, do not return "txrate" if nTimeDiff = 0. 4. Add following 3 elements to the return object. 1) 'window_block_count' : Size of the window in number of blocks. 2) 'window_tx_count' : The number of transactions in the window. 3) 'window_interval' : The elapsed time in the window. They clarify how 'txrate' is calculated. 2) and 3) are returned only if 'window_block_count' is a positive value. 5. Improve help text for 'time' as following. 'The timestamp for the final block in the window in UNIX format.
1. Add a test for no parameters. 2. Add a test for the block's height = 1. 3. Add a test for nblocks is out of range.
0e30d62
to
07704c1
Compare
@promag @jnewbery @kallewoof I fixed followings.
|
Looks good to me! tested ACK 07704c1. |
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
Postumous utACK non-test parts of 07704c1 |
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
07704c1 Add some tests for getchaintxstats (Akio Nakamura) 3336676 Fix getchaintxstats() (Akio Nakamura) Pull request description: 1. calculate nblocks more adaptive. -> set default nblocks to min (blocks for 1 month, target block's height - 1) -> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks. 2. correct error message. -> nblocks accepts [1 .. block's height -1] . so add a word "-1". 3. add check 0-divide. -> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} . -> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response. Tree-SHA512: e1962ce7bb05a5bc7dec03eb04a8e7578f50fdb68927fcfc0a2232905ef4d679293eee148ebe0866682d209a8c458d21fbe71715e7311adb81f37089aae1ed93
-> set default nblocks to min (blocks for 1 month, target block's height - 1)
-> before PR: if not specify nblocks-parameter, illegal parameter error will happen when target block height is below nblocks.
-> nblocks accepts [1 .. block's height -1] . so add a word "-1".
-> if nTimeDiff = 0 then use UniValue(UniValue::VNULL) and returns {... "txrate": null} .
-> before PR: if nTimeDiff = 0 then returns {... "txrate":} and bitcoin-cli cannot handle the response.