Skip to content

Commit

Permalink
Fix comparing wrong blocksize parameter variable
Browse files Browse the repository at this point in the history
Compiler warning was unfortunately missed, but this
seems a clear case of comparing the wrong variable,
resulting in a condition which can never be true
(unsigned < 0).

A functional test is adapted to trigger the invalid
value case for `blockmaxsize` and check that the
message is produced.

Test Plan
---------

- `ninja all check-all`
  • Loading branch information
ftrader committed Sep 4, 2023
1 parent 308deaf commit a395e31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/init.cpp
Expand Up @@ -1739,7 +1739,7 @@ bool AppInitParameterInteraction(Config &config) {
return InitError(_("Cannot set both -blockmaxsize and -percentblockmaxsize"));
} else if (has_bms && !has_pbms) {
const int64_t nProposedMaxGeneratedBlockSize = gArgs.GetArg("-blockmaxsize", int64_t{-1});
if (nProposedExcessiveBlockSize < 0) {
if (nProposedMaxGeneratedBlockSize < 0) {
return InitError(_("Invalid value specified for -blockmaxsize"));
}
// Check blockmaxsize does not exceed maximum accepted block size.
Expand Down
6 changes: 6 additions & 0 deletions test/functional/abc-cmdline.py
Expand Up @@ -20,6 +20,8 @@
MAX_GENERATED_BLOCK_SIZE_ERROR = (
'Max generated block size (blockmaxsize) cannot exceed the excessive block size (excessiveblocksize)')

INVALID_GENERATED_BLOCK_SIZE_ERROR = (
'Invalid value specified for -blockmaxsize')

class ABC_CmdLine_Test (BitcoinTestFramework):

Expand Down Expand Up @@ -79,6 +81,10 @@ def excessiveblocksize_test(self):
self.nodes[0].assert_start_raises_init_error(
['-blockmaxsize=1500000', '-excessiveblocksize=1300000'], 'Error: ' + MAX_GENERATED_BLOCK_SIZE_ERROR)

self.log.info(" Attempt to set invalid blockmaxsize (mining limit)")
self.nodes[0].assert_start_raises_init_error(
['-blockmaxsize=-1'], 'Error: ' + INVALID_GENERATED_BLOCK_SIZE_ERROR)

# Make sure we leave the test with a node running as this is what thee
# framework expects.
self.start_node(0, [])
Expand Down

0 comments on commit a395e31

Please sign in to comment.