Skip to content

Commit 699252f

Browse files
committed
rpc: add skip_type_check for evo RPCs accepting block hash or height
The new automatic type checking from bitcoin#26039 rejects numeric heights sent by JSON-RPC clients for RPCArg::Type::STR parameters. Add skip_type_check to all evo.cpp RPCs where parameters accept both block hashes (strings) and heights (numbers): - protx diff: baseBlock, block - protx listdiff: baseBlock, block - evodb verify: startBlock, stopBlock - evodb repair: startBlock, stopBlock Also simplify ParseBlockIndex by removing the catch-all that was swallowing the specific 'Block not found' error. ParseBlock already throws a clear error on bad input, so the catch-all was redundant and masked useful error messages.
1 parent 04e96e7 commit 699252f

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/rpc/evo.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,26 +1604,23 @@ static const CBlockIndex* ParseBlockIndex(const UniValue& v, const ChainstateMan
16041604
{
16051605
AssertLockHeld(::cs_main);
16061606

1607-
try {
1608-
const auto hash{ParseBlock(v, chainman, strName)};
1609-
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
1610-
if (!pindex) {
1611-
throw std::runtime_error(strprintf("Block %s with hash %s not found", strName, v.getValStr()));
1612-
}
1613-
return pindex;
1614-
} catch (...) {
1615-
// Same phrasing as ParseBlock() as it can parse heights
1616-
throw std::runtime_error(strprintf("%s must be a block hash or chain height and not %s", strName, v.getValStr()));
1607+
const auto hash{ParseBlock(v, chainman, strName)};
1608+
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
1609+
if (!pindex) {
1610+
throw std::runtime_error(strprintf("Block %s with hash %s not found", strName, v.getValStr()));
16171611
}
1612+
return pindex;
16181613
}
16191614

16201615
static RPCHelpMan protx_diff()
16211616
{
16221617
return RPCHelpMan{"protx diff",
16231618
"\nCalculates a diff between two deterministic masternode lists. The result also contains proof data.\n",
16241619
{
1625-
{"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height."},
1626-
{"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height."},
1620+
{"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height.",
1621+
RPCArgOptions{.skip_type_check = true}},
1622+
{"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height.",
1623+
RPCArgOptions{.skip_type_check = true}},
16271624
{"extended", RPCArg::Type::BOOL, RPCArg::Optional::OMITTED, "Show additional fields."},
16281625
},
16291626
CSimplifiedMNListDiff::GetJsonHelp(/*key=*/"", /*optional=*/false),
@@ -1663,8 +1660,10 @@ static RPCHelpMan protx_listdiff()
16631660
return RPCHelpMan{"protx listdiff",
16641661
"\nCalculate a full MN list diff between two masternode lists.\n",
16651662
{
1666-
{"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height."},
1667-
{"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height."},
1663+
{"baseBlock", RPCArg::Type::STR, RPCArg::Optional::NO, "The starting block hash or height.",
1664+
RPCArgOptions{.skip_type_check = true}},
1665+
{"block", RPCArg::Type::STR, RPCArg::Optional::NO, "The ending block hash or height.",
1666+
RPCArgOptions{.skip_type_check = true}},
16681667
},
16691668
RPCResult {
16701669
RPCResult::Type::OBJ, "", "",
@@ -1839,8 +1838,10 @@ static RPCHelpMan evodb_verify()
18391838
"This is a read-only operation that does not modify the database.\n"
18401839
"If no heights are specified, defaults to the full range from DIP0003 activation to chain tip.\n",
18411840
{
1842-
{"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height)."},
1843-
{"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip)."},
1841+
{"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height).",
1842+
RPCArgOptions{.skip_type_check = true}},
1843+
{"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip).",
1844+
RPCArgOptions{.skip_type_check = true}},
18441845
},
18451846
RPCResult{
18461847
RPCResult::Type::OBJ, "", "",
@@ -1877,8 +1878,10 @@ static RPCHelpMan evodb_repair()
18771878
"If verification fails, recalculates diffs from blockchain data and replaces corrupted records.\n"
18781879
"If no heights are specified, defaults to the full range from DIP0003 activation to chain tip.\n",
18791880
{
1880-
{"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height)."},
1881-
{"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip)."},
1881+
{"startBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The starting block hash or height (defaults to DIP0003 activation height).",
1882+
RPCArgOptions{.skip_type_check = true}},
1883+
{"stopBlock", RPCArg::Type::STR, RPCArg::Optional::OMITTED, "The ending block hash or height (defaults to current chain tip).",
1884+
RPCArgOptions{.skip_type_check = true}},
18821885
},
18831886
RPCResult{
18841887
RPCResult::Type::OBJ, "", "",

0 commit comments

Comments
 (0)