RPC: submitblock: Support for returning specific rejection reasons #3727

pull luke-jr wants to merge 1 commits into bitcoin:master from luke-jr:submitblock_rejreason changing 1 files +6 −1
  1. luke-jr commented at 12:38 AM on February 22, 2014: member

    No description provided.

  2. jgarzik commented at 2:05 AM on February 22, 2014: contributor

    ACK the first commit. I need to trace through the code to fully review the second commit, which touches key validation code.

  3. sipa commented at 10:42 PM on February 22, 2014: member

    Looks correct to me. The only validation change is replace a "true" by state.Orphan (which returns true), and the changes to state itself should be unobservable except for the IsOrphan() method, which the core code doesn't call.

  4. in src/rpcmining.cpp:None in 3979137418 outdated
     620 | @@ -621,7 +621,23 @@ Value submitblock(const Array& params, bool fHelp)
     621 |      CValidationState state;
     622 |      bool fAccepted = ProcessBlock(state, NULL, &pblock);
     623 |      if (!fAccepted)
     624 | -        return "rejected"; // TODO: report validation state
     625 | +    {
     626 | +        std::string strRejectReason = state.GetRejectReason();
     627 | +        if (state.IsError())
     628 | +            throw JSONRPCError(RPC_MISC_ERROR, strRejectReason);
    


    laanwj commented at 7:13 AM on February 25, 2014:

    You could use RPC_TRANSACTION_REJECTED code here, which I introduce in #3730 (maybe rename it to transaction or block rejected...).


    luke-jr commented at 7:14 AM on February 25, 2014:

    RPC_INPUT_REJECTED?


    laanwj commented at 7:16 AM on February 25, 2014:

    Input is too general. It should be clear that this concerns transaction/block-level rejection, not just invalid input. Edit: also it would be useful to be able to get the reject code from the error as well, not just the string message.


    laanwj commented at 7:23 AM on April 16, 2014:

    I eventually added three transaction-validation related error codes in #3730, RPC_TRANSACTION_ERROR would be appropriate here:

    RPC_TRANSACTION_ERROR           = -25, // General error during transaction submission
    RPC_TRANSACTION_REJECTED        = -26, // Transaction was rejected by network rules
    RPC_TRANSACTION_ALREADY_IN_CHAIN= -27, // Transaction already in chain
    

    luke-jr commented at 9:13 AM on April 16, 2014:

    But there's no reason to think it has anything to do with transactions...


    laanwj commented at 9:45 AM on April 16, 2014:

    Obviously. But you could widen the scope.


    luke-jr commented at 9:48 AM on April 16, 2014:

    So rename it to RPC_ACCEPT_ERROR? Or what?


    laanwj commented at 9:52 AM on April 16, 2014:

    I'd say RPC_VERIFY_* and change the comments to be "Transaction or block"

  5. luke-jr commented at 2:40 PM on June 26, 2014: member

    Rebased, with @laanwj 's change implemented.

  6. gavinandresen commented at 3:57 PM on June 26, 2014: contributor

    Untested-but-code-reviewed ACK.

  7. BitcoinPullTester commented at 5:45 PM on June 26, 2014: none

    Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/p3727_8608fce20ac72af78d1f01f8c10d9dacc2c364ed/ for binaries and test log. This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/ Contact BlueMatt on freenode if something looks broken.

  8. jgarzik commented at 5:13 PM on July 29, 2014: contributor

    Shall we move this along and collect ACKs? Consensus seems to be we like this one.

  9. laanwj commented at 8:45 AM on July 30, 2014: member

    Untested ACK

  10. sipa commented at 11:08 AM on July 30, 2014: member

    This will not work for all types of errors. All ProcessBlock does now is do preliminary checks and store the block in the block database, and remember who we got the block from. Then we invoke ActivateBestChain which connects the new best chain if any, but as it's not about a specific block anymore, it does not return information about errors with the block - they're sent directly as rejections to the peer that gave us the block.

    To fix this, either plug into InvalidBlockFound, or we need some more generic way of listening for problems with particular blocks (another signal handler?).

  11. luke-jr commented at 4:33 PM on July 30, 2014: member

    @sipa In this case, the "peer that give us the block" is a RPC client. Can we tie in via that somehow?

  12. sipa commented at 9:09 PM on July 30, 2014: member

    An alternative is not using ProcessBlock, but calling CheckBlock, AcceptBlock and ConnectTip directly. The logic should be trivial as submitblock can just fail in case the block submitted is not an immediate successor that would cause switching immediately.

  13. laanwj added the label Block Creation on Jul 31, 2014
  14. laanwj commented at 9:17 AM on August 1, 2014: member

    @sipa Sounds like a good idea to me.

  15. luke-jr force-pushed on Oct 9, 2014
  16. RPC: submitblock: Support for returning specific rejection reasons e69a5873e7
  17. luke-jr force-pushed on Oct 30, 2014
  18. luke-jr commented at 2:19 AM on October 30, 2014: member

    Rebased on top of #5106

  19. luke-jr force-pushed on Nov 3, 2014
  20. luke-jr force-pushed on Nov 3, 2014
  21. luke-jr commented at 11:30 AM on November 3, 2014: member

    I believe this is now simple enough to be quickly re-ACK'd?

  22. sipa commented at 11:49 AM on November 3, 2014: member

    utACK

  23. laanwj merged this on Nov 3, 2014
  24. laanwj closed this on Nov 3, 2014

  25. laanwj referenced this in commit ff17816abf on Nov 3, 2014
  26. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me