Page MenuHomePhabricator

Merge #17192: util: Add CHECK_NONFATAL and use it in src/rpc
ClosedPublic

Authored by nakihito on Apr 16 2020, 19:29.

Details

Summary

faeb6665362e35f573ad715ade0ef2db62d71839 util: Add CHECK_NONFATAL and use it in src/rpc (MarcoFalke)

Pull request description:

Fixes #17181

Currently, we use `assert` in RPC code to document logic and code assumptions. However, it seems a bit extreme to abort all of Bitcoin Core on an assert failure in one of the RPC threads. I suggest to replace all `assert`s with a macro `CHECK_NONFATAL(condition)` that throws a runtime error when the condition evaluates to `false`. That runtime error will then be returned to the rpc caller and will include instructions to report the error to our issue tracker.

ACKs for top commit:

practicalswift:
  ACK faeb6665362e35f573ad715ade0ef2db62d71839
laanwj:
  ACK faeb6665362e35f573ad715ade0ef2db62d71839
ryanofsky:
  Code review ACK faeb6665362e35f573ad715ade0ef2db62d71839

Tree-SHA512: 9b748715a5e0767ac11f1324a95a3a6ec672a0e0658013492219223bda83ce4b1b447fd8183bbb235f7df5ef7dddda7666ad569544b4d61cc65f232ca7a800ec

Backport of Core PR17192

This is an out-of-order backport so that the older backports can be done without the asserts like here.

Test Plan
make
test_runner.py

ninja
test_runner.py

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Owners added a reviewer: Restricted Owners Package.Apr 16 2020, 19:29

[Bot Message]
One or more PR numbers were detected in the summary.
Links to those PRs have been inserted into the summary for reference.

deadalnix requested changes to this revision.Apr 17 2020, 00:32
deadalnix added a subscriber: deadalnix.
deadalnix added inline comments.
src/rpc/util.h
101 ↗(On Diff #18872)

What about RPCResult ?

This revision now requires changes to proceed.Apr 17 2020, 00:32
nakihito added inline comments.
src/rpc/util.h
101 ↗(On Diff #18872)

This is an out-of-order backport so that the older backports can be done without the asserts like here.

From the developer notes:

    Assertions should not have side-effects
        *Rationale*: Even though the source code is set to refuse to compile with assertions disabled, having side-effects in assertions is unexpected and makes the code harder to understand

If assert is compiled out the insertion is lost.

It hasn't been backported yet to avoid the above.

This revision is now accepted and ready to land.Apr 18 2020, 08:33