Merge ElementsProject/elements#1057: Make error messages when talking to parent chain daemon more useful.

cfed38503e Make error messages when talking to parent chain daemon more useful. (Glenn Willen)

Pull request description:

  <!--
  *** Please remove the following help text before submitting: ***

  Pull requests without a rationale and clear improvement may be closed
  immediately.

  GUI-related pull requests should be opened against
  https://github.com/bitcoin-core/gui
  first. See CONTRIBUTING.md
  -->

  <!--
  Please provide clear motivation for your patch and explain how it improves
  Bitcoin Core user experience or Bitcoin Core developer experience
  significantly:

  * Any test improvements or new tests that improve coverage are always welcome.
  * All other changes should have accompanying unit tests (see `src/test/`) or
    functional tests (see `test/`). Contributors should note which tests cover
    modified code. If no tests exist for a region of modified code, new tests
    should accompany the change.
  * Bug fixes are most welcome when they come with steps to reproduce or an
    explanation of the potential issue as well as reasoning for the way the bug
    was fixed.
  * Features are welcome, but might be rejected due to design or scope issues.
    If a feature is based on a lot of dependencies, contributors should first
    consider building the system outside of Bitcoin Core, if possible.
  * Refactoring changes are only accepted if they are required for a feature or
    bug fix or otherwise improve developer experience significantly. For example,
    most "code style" refactoring changes require a thorough explanation why they
    are useful, what downsides they have and why they *significantly* improve
    developer experience or avoid serious programming bugs. Note that code style
    is often a subjective matter. Unless they are explicitly mentioned to be
    preferred in the [developer notes](/doc/developer-notes.md), stylistic code
    changes are usually rejected.
  -->

  <!--
  Bitcoin Core has a thorough review process and even the most trivial change
  needs to pass a lot of eyes and requires non-zero or even substantial time
  effort to review. There is a huge lack of active reviewers on the project, so
  patches often sit for a long time.
  -->

ACKs for top commit:
  stevenroose:
    utACK cfed38503e

Tree-SHA512: 1b76d50516bdc809d652e932f1336a8d17c51aae1094a664b3098cdd63ce0826175f25cb64539c6b3cf0ad086ccce4d883600ab960010fd9a0401c557a562e82
This commit is contained in:
Steven Roose 2021-10-19 20:28:54 +01:00
commit 04cedf3f6b
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87

View file

@ -158,19 +158,20 @@ bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDept
UniValue params(UniValue::VARR);
params.push_back(hash.GetHex());
UniValue reply = CallMainChainRPC("getblockheader", params);
if (!find_value(reply, "error").isNull()) {
LogPrintf("ERROR: Got error reply from bitcoind getblockheader.\n");
UniValue errval = find_value(reply, "error");
if (!errval.isNull()) {
LogPrintf("WARNING: Got error reply from bitcoind getblockheader: %s\n", errval.write());
return false;
}
UniValue result = find_value(reply, "result");
if (!result.isObject()) {
LogPrintf("ERROR: bitcoind getblockheader result was malformed (not object).\n");
LogPrintf("ERROR: bitcoind getblockheader result was malformed (not object): %s\n", result.write());
return false;
}
UniValue confirmations = find_value(result.get_obj(), "confirmations");
if (!confirmations.isNum() || confirmations.get_int64() < nMinConfirmationDepth) {
LogPrintf("Insufficient confirmations (got %s).\n", confirmations.write());
LogPrintf("Insufficient confirmations (got %s, need at least %d).\n", confirmations.write(), nMinConfirmationDepth);
return false;
}
@ -178,16 +179,16 @@ bool IsConfirmedBitcoinBlock(const uint256& hash, const int nMinConfirmationDept
if (nbTxs != 0) {
UniValue nTx = find_value(result.get_obj(), "nTx");
if (!nTx.isNum() || nTx.get_int64() != nbTxs) {
LogPrintf("ERROR: Invalid number of transactions in merkle block for %s\n",
hash.GetHex());
LogPrintf("ERROR: Invalid number of transactions in merkle block for %s (got %s, need exactly %d)\n",
hash.GetHex(), nTx.write(), nbTxs);
return false;
}
}
} catch (CConnectionFailed& e) {
LogPrintf("ERROR: Lost connection to mainchain daemon RPC, you will want to restart after fixing this!\n");
LogPrintf("WARNING: Lost connection to mainchain daemon RPC; will retry.\n");
return false;
} catch (...) {
LogPrintf("ERROR: Failure connecting to mainchain daemon RPC, you will want to restart after fixing this!\n");
LogPrintf("WARNING: Failure connecting to mainchain daemon RPC; will retry.\n");
return false;
}
return true;