rpc: document RPC_TRANSACTION_ALREADY_IN_CHAIN exception #20941

pull jarolrod wants to merge 1 commits into bitcoin:master from jarolrod:rpcman-sendrawtx changing 1 files +3 −2
  1. jarolrod commented at 5:46 AM on January 15, 2021: member

    It is not documented in the RPCHelpMan of sendrawtransaction that if you attempt to send a transaction which already exists in a block, an RPC_TRANSACTION_ALREADY_IN_CHAIN exception will be raised. It is best to make developers aware of this so that it can be properly caught and avoid any headaches.

    Closes #5638

  2. fanquake added the label RPC/REST/ZMQ on Jan 15, 2021
  3. in src/rpc/rawtransaction.cpp:824 in fa614af69a outdated
     818 | @@ -819,7 +819,9 @@ static RPCHelpMan sendrawtransaction()
     819 |                  "\nNote that the transaction will be sent unconditionally to all peers, so using this\n"
     820 |                  "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
     821 |                  "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
     822 | -                "\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n",
     823 | +                "\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n"
     824 | +                "\nNOTE: an RPC_TRANSACTION_ALREADY_IN_CHAIN exception will be raised if you are\n"
     825 | +                "attempting to send a transaction that already exists in a block.\n",
    


    jonatack commented at 10:36 AM on January 15, 2021:

    suggestion to improve, tighten this up, and remove "Note that" and "NOTE:" while grouping together those two messages and keeping the related RPCs sentence at the end

    +++ b/src/rpc/rawtransaction.cpp
    @@ -816,12 +816,11 @@ static RPCHelpMan sendrawtransaction()
     {
         return RPCHelpMan{"sendrawtransaction",
                     "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n"
    -                "\nNote that the transaction will be sent unconditionally to all peers, so using this\n"
    +                "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
                     "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
                     "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
    -                "\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n"
    -                "\nNOTE: an RPC_TRANSACTION_ALREADY_IN_CHAIN exception will be raised if you are\n"
    -                "attempting to send a transaction that already exists in a block.\n",
    +                "\nRPC_TRANSACTION_ALREADY_IN_CHAIN will be raised if the transaction already exists in a block.\n"
    +                "\nRelated RPCs: createrawtransaction, signrawtransactionwithkey\n",
    

    jonatack commented at 10:39 AM on January 15, 2021:

    which would change the help from

    Submit a raw transaction (serialized, hex-encoded) to local node and network.
    
    Note that the transaction will be sent unconditionally to all peers, so using this
    for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
    nodes will normally not rebroadcast non-wallet transactions already in their mempool.
    
    Also see createrawtransaction and signrawtransactionwithkey calls.
    
    NOTE: an RPC_TRANSACTION_ALREADY_IN_CHAIN exception will be raised if you are
    attempting to send a transaction that already exists in a block.
    

    to

    Submit a raw transaction (serialized, hex-encoded) to local node and network.
    
    The transaction will be sent unconditionally to all peers, so using sendrawtransaction
    for manual rebroadcast may degrade privacy by leaking the transaction's origin, as
    nodes will normally not rebroadcast non-wallet transactions already in their mempool.
    
    RPC_TRANSACTION_ALREADY_IN_CHAIN will be raised if the transaction already exists in a block.
    
    Related RPCs: createrawtransaction, signrawtransactionwithkey
    

    jarolrod commented at 2:42 PM on January 15, 2021:

    addressed in 35bc72a1bcc6c7bb7618803490fc7957d070dc02 Thanks, this is much better :)

  4. jonatack commented at 10:43 AM on January 15, 2021: member

    Concept ACK

    I agree with #5638 (comment) that returning a {'in_chain': bool, 'in_mempool': bool, 'tx_hash': hash} structure would be better but this step doesn't hurt and while touching this we can improve the help.

  5. jarolrod force-pushed on Jan 15, 2021
  6. jarolrod commented at 2:41 PM on January 15, 2021: member

    updated fa614af69ac72b5250d3408e4c56f083f3ab6254 -> 35bc72a1bcc6c7bb7618803490fc7957d070dc02

    Implemented @jonatack suggestions

  7. in src/rpc/rawtransaction.cpp:822 in 35bc72a1bc outdated
     815 | @@ -816,10 +816,11 @@ static RPCHelpMan sendrawtransaction()
     816 |  {
     817 |      return RPCHelpMan{"sendrawtransaction",
     818 |                  "\nSubmit a raw transaction (serialized, hex-encoded) to local node and network.\n"
     819 | -                "\nNote that the transaction will be sent unconditionally to all peers, so using this\n"
     820 | +                "\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n"
     821 |                  "for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n"
     822 |                  "nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n"
     823 | -                "\nAlso see createrawtransaction and signrawtransactionwithkey calls.\n",
     824 | +                "\nRPC_TRANSACTION_ALREADY_IN_CHAIN will be raised if the transaction already exists in a block\n"
    


    MarcoFalke commented at 2:44 PM on January 15, 2021:

    This makes it sound like the only exception that can be thrown


    jarolrod commented at 3:03 PM on January 15, 2021:

    We can either document every exception that can be thrown or revert back to specifying that this is a note.

                    "\nNOTE: an RPC_TRANSACTION_ALREADY_IN_CHAIN will be raised if the transaction already exists in a block\n"
    

    jonatack commented at 3:13 PM on January 15, 2021:

    I would avoid both adding "note this"/"note that" (IIRC I added the first note but have since seen review feedback to avoid needless "note: "s, which I agree with) and listing all the exceptions. Is there a concrete suggestion how this change can be improved?


    MarcoFalke commented at 3:19 PM on January 15, 2021:

    "This may throw if the transaction couldn't be added to the mempool"


    jarolrod commented at 6:15 PM on January 15, 2021:

    "This may throw if the transaction couldn't be added to the mempool"

    That still sounds like it's the only exception which may be thrown. It also sounds like it's the only reason that a transaction fails to enter the mempool.


    jonatack commented at 6:29 PM on January 15, 2021:

    As-is seems more explicit but I don't have a strong opinion regarding it versus Marco's suggestion (thanks for the proposal!) I think they are both an improvement and don't see the implication that this the only exception.


    jonatack commented at 6:38 PM on January 15, 2021:
                    "\nRPC_TRANSACTION_ALREADY_IN_CHAIN will be raised if the transaction already exists in a block.\n"
    

    jonatack commented at 6:45 PM on January 15, 2021:

    Maybe:

    This will throw a specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, if the transaction cannot be added to the mempool.
    

    jarolrod commented at 9:53 PM on January 15, 2021:

    addressed in 74d23bf


    jarolrod commented at 9:53 PM on January 15, 2021:

    addressed in 74d23bf

  8. felipsoarez commented at 6:24 PM on January 15, 2021: none

    NACK, as i understand it, it is an unnecessary note, as discussed earlier, to avoid unnecessary notes.

  9. jarolrod commented at 6:33 PM on January 15, 2021: member

    NACK, as i understand it, it is an unnecessary note, as discussed earlier, to avoid unnecessary notes.

    See: #5638

    Yes, it would be more useful to change the code so that the function returns a {'in_chain': bool, 'in_mempool': bool, 'tx_hash': hash} structure, but an argument is made against that. It's worthwhile to evaluate if this is still the case, but outside the scope of this PR.

    This PR implements the proposed solution of documenting the exception so that developers don't find themselves frustrated by this and don't have to resort to looking to the source code.

  10. jonatack commented at 6:37 PM on January 15, 2021: member

    Yes, I did not mean to suggest that adding helpful documentation was a bad idea.

  11. jonatack commented at 6:39 PM on January 15, 2021: member

    ACK modulo missing full stop line 822 (and/or taking Marco's suggestion or the one at #20941 (review) or your proposed improvement)

  12. rpc: document RPC_TRANSACTION_ALREADY_IN_CHAIN exception
    It is not documented that if you attempt to send a transaction
    which already exists in a block, an RPC_TRANSACTION_ALREADY_IN_CHAIN
    exception will be raised. This should be documented so that developers
    are aware that this exception is raised.
    74d23bf7fb
  13. jarolrod force-pushed on Jan 15, 2021
  14. jarolrod commented at 9:52 PM on January 15, 2021: member

    updated 35bc72a -> 74d23bf

    Addressed the issue of wording around the exception by combining both suggestions from @jonatack and @MarcoFalke

  15. jonatack commented at 4:34 PM on January 16, 2021: member

    ACK 74d23bf7fbb6169ec658c36af57cd1f937823d9c

  16. MarcoFalke merged this on Feb 1, 2021
  17. MarcoFalke closed this on Feb 1, 2021

  18. MarcoFalke commented at 10:02 AM on February 1, 2021: member

    I'd still prefer to document exceptions/return codes/error values better, but that might be a task to solve for all RPCs

  19. sidhujag referenced this in commit ac3f0a4039 on Feb 2, 2021
  20. jarolrod deleted the branch on Apr 5, 2021
  21. DrahtBot locked this on Aug 18, 2022

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:14 UTC

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