Fix uninitialized URI in batch RPC requests #11277

pull ryanofsky wants to merge 6 commits into bitcoin:master from ryanofsky:pr/mb changing 6 files +33 −23
  1. ryanofsky commented at 9:45 pm on September 7, 2017: member

    This fixes “Wallet file not specified” errors when making batch wallet RPC calls with more than one wallet loaded. This issue was reported by @NicolasDorier in #11257

    Request URI is not used for anything except multiwallet request dispatching, so this change has no other effect.

  2. laanwj added the label RPC/REST/ZMQ on Sep 7, 2017
  3. ryanofsky force-pushed on Sep 7, 2017
  4. NicolasDorier commented at 6:04 am on September 10, 2017: contributor
    I really want that for 0.15, as I rely on this for TumbleBit, will test soon.
  5. NicolasDorier commented at 7:16 am on September 10, 2017: contributor
    tACK c0c652ccc24f4c3dbd200f14822f10c373a5198d @laanwj I hope this can make it to 0.15. I enjoy multi-wallet, but I really can’t use it in any project without the batch support, as it would require me to rewrite things that already work.
  6. jnewbery commented at 1:55 pm on September 11, 2017: member

    I don’t like the fact that you’re creating a ‘private’ _call method in the AuthServiceProxy class, and then calling it (and the existing private method _batch) from a test script.

    One of the advantages of the TestNode class is that on the whole the test scripts don’t interface directly with the AuthServiceProxy class. That was deliberate and would allow us to:

    • remove the slightly cludgy AuthServiceProxyWrapper coverage class easily
    • modify the auth service proxy or even swap it out for a new implementation without having to change the scripts.

    Is there a way you can add the batch functionality to the TestNode class?

  7. in src/rpc/server.cpp:392 in c0c652ccc2 outdated
    381@@ -382,11 +382,10 @@ void JSONRPCRequest::parse(const UniValue& valRequest)
    382         throw JSONRPCError(RPC_INVALID_REQUEST, "Params must be an array or object");
    383 }
    384 
    385-static UniValue JSONRPCExecOne(const UniValue& req)
    386+static UniValue JSONRPCExecOne(JSONRPCRequest jreq, const UniValue& req)
    


    promag commented at 8:59 pm on September 13, 2017:
    Receive const std::string& uri instead?

    ryanofsky commented at 9:51 pm on October 3, 2017:

    Receive const std::string& uri instead?

    Don’t see the advantage, and the disadvantage is it leaves this code open to the exact same bug in the future if another field is added to JSONRPCRequest. Better to copy the whole object, IMO.

  8. in src/httprpc.cpp:195 in c0c652ccc2 outdated
    191@@ -192,7 +192,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)
    192 
    193         // array of requests
    194         } else if (valRequest.isArray())
    195-            strReply = JSONRPCExecBatch(valRequest.get_array());
    


    promag commented at 9:28 pm on September 13, 2017:
    Kind of unrelated, but above in L186 we could call JSONRPCExecOne I believe.

    ryanofsky commented at 9:49 pm on October 3, 2017:

    Kind of unrelated, but above in L186 we could call JSONRPCExecOne I believe.

    It would be good to unify the code paths more, but this wouldn’t be equivalent because it would handle errors differently. (Execone doesn’t use JSONErrorReply, so doesn’t set http error codes.)

  9. JeremyRubin commented at 2:13 pm on October 3, 2017: contributor
    needs rebase! utack c0c652c
  10. Fix uninitialized URI in batch RPC requests
    This fixes "Wallet file not specified" errors when making batch wallet RPC
    calls with more than one wallet loaded. This issue was reported by
    NicolasDorier <nicolas.dorier@gmail.com>
    https://github.com/bitcoin/bitcoin/issues/11257
    
    Request URI is not used for anything except multiwallet request dispatching, so
    this change has no other effects.
    
    Fixes #11257
    edafc718ad
  11. Limit AuthServiceProxyWrapper.__getattr__ wrapping
    Change AuthServiceProxyWrapper.__getattr__ to only wrap proxied attributes, not
    real attributes. This way AuthServiceProxyWrapper can continue logging RPC
    calls without complicating other object usages, and special case handling for
    the .url property can be dropped.
    e02007aade
  12. Make AuthServiceProxy._batch method usable
    Split off AuthServiceProxy.get_request method to make it easier to batch RPC
    requests without duplicating code and remove leading underscore from _batch
    method.
    
    This does not change any existing behavior.
    9f67646f17
  13. ryanofsky force-pushed on Oct 3, 2017
  14. ryanofsky commented at 10:29 pm on October 3, 2017: member

    I don’t like the fact that you’re creating a ‘private’ _call method in the AuthServiceProxy class, and then calling it (and the existing private method _batch) from a test script.

    One of the advantages of the TestNode class is that on the whole the test scripts don’t interface directly with the AuthServiceProxy class. That was deliberate and would allow us to: remove the slightly cludgy AuthServiceProxyWrapper coverage class easily modify the auth service proxy or even swap it out for a new implementation without having to change the scripts.

    Is there a way you can add the batch functionality to the TestNode class?

    All I’m really doing here is adding a simple 3-line test to multiwallet.py using the existing _batch method:

    0batch = w1._batch([w1.getblockchaininfo._get_request(), w1.getwalletinfo._get_request()])
    1assert_equal(batch[0]["result"]["chain"], "regtest")
    2assert_equal(batch[1]["result"]["walletname"], "w1")
    

    This only required two minor improvements to AuthServiceProxy and AuthServiceProxyWrapper, so I think the approach is good for this PR, which is supposed to be an RPC bugfix and not a test framework restructuring.

    But to discuss possible future test framework improvements, TestNode seems does not seem like a great place to move RPC sending code. The division where authproxy handles json & http stuff and test_node handles test stuff seems like a good one, and I think don’t think it’d be desirable to scramble it all up without a clear motivation. I also don’t think that batch rpc requests should follow a different code path from single rpc requests.

    As far as I know, nothing in this PR makes it more difficult to remove AuthServiceProxyWrapper in the future if that is a goal. The actual change I’m making to AuthServiceProxyWrapper is a bugfix and cleanup that makes the class less invasive.

    If calling methods that begin with underscores is a problem (and I think it’s a pretty superficial problem if it is a problem at all), we could simply drop the underscores, or make get_request and batch be standalone functions instead of member functions, or be operators like % and «.

  15. Add missing multiwallet rpc calls to python coverage logs
    This fixes a bug in coverage logging that's been around since the logging was
    introduced.
    505530c6cf
  16. Add missing batch rpc calls to python coverage logs
    Without this change, batch RPC calls are not included in coverage logs.
    74182f235c
  17. Add test for multiwallet batch RPC calls
    Tests bug reported in https://github.com/bitcoin/bitcoin/issues/11257
    4526d21e52
  18. ryanofsky force-pushed on Oct 4, 2017
  19. ryanofsky commented at 7:30 am on October 4, 2017: member

    Added 2 commits 52174747fd82db3118946d36e2b067fb5c41176e -> 3ca5398f2efb3a09b9be65b6ee4aa7acff2c3cd9 (pr/mb.4 -> pr/mb.5, compare)

    I went ahead and added % and « operators for making batch rpc calls in a new commit. I realized batch rpc calls weren’t being included in coverage logs, and operator syntax seemed like a less invasive way than overriding _get_reqest and _batch methods for AuthServiceProxyWrapper to be able to log the calls.

  20. ryanofsky force-pushed on Oct 4, 2017
  21. jnewbery commented at 5:42 pm on October 4, 2017: member

    If calling methods that begin with underscores is a problem (and I think it’s a pretty superficial problem if it is a problem at all), we could simply drop the underscores, or make get_request and batch be standalone functions instead of member functions, or be operators like % and «.

    The new operator overrides are cute, but perhaps unnecessary.

    My objection to using ‘private’ methods in the test script is simply one of convention. Obviously leading underscores don’t mean anything to the python interpreter, but to us humans it means ’this method/member is private and won’t be accessed directly outside of this class/module’. There’s no need to break that assumption needlessly.

    But to discuss possible future test framework improvements, TestNode seems does not seem like a great place to move RPC sending code.

    I disagree, but like you say this is a PR for fixing a bitcoind bug and not test framework restructuring. This PR does seem to be an improvement to the AuthServiceProxyWrapper class.

    Concept ACK with a weak preference to remove the syntactic sugar and rename the methods to make them ‘public’.

  22. ryanofsky force-pushed on Oct 4, 2017
  23. ryanofsky commented at 7:04 pm on October 4, 2017: member
    Updated 3ca5398f2efb3a09b9be65b6ee4aa7acff2c3cd9 -> 4526d21e52aa94f12121fcf01047c04f82c4990a (pr/mb.5 -> pr/mb.6) to get rid of operator overloading.
  24. JeremyRubin commented at 8:24 pm on October 4, 2017: contributor
    Chiming in to say that _call is fine – it’s just to indicate that it’s an intended for internal use function in python, ’truly private’ methods are double underscore.
  25. jnewbery commented at 9:08 pm on October 4, 2017: member

    ’truly private’ methods are double underscore.

    There’s no such thing as truly private methods in Python: https://docs.python.org/3/tutorial/classes.html#private-variables

  26. JeremyRubin commented at 11:26 pm on October 4, 2017: contributor

    I mean, it’s semantics, but technically neither does C++ because you can get around it (in some cases; like without private static globals?) as follows:

    0struct A {
    1private:
    2void foo() {}
    3}
    4struct B {
    5void foo() {}
    6}
    7
    8auto x = new A{};
    9((B*) x)->foo();
    

    In any case, the scare quotes were around ’truly private’: it’s not truly private, but it does make you call a mangled name. Then again, not many languages stop you from manipulating an object in your memory space if you want to manipulate it.

  27. laanwj commented at 3:59 pm on October 11, 2017: member

    @JeremyRubin That only works for virtual methods, AFAIK, and it works because the slot is at the same offset in the vtable. Non-virtual methods have the class name encoded into the symbol name

    That said, let’s try to respect private methods even though it’s not perfectly enforced, it’s meant as a convention to communicate to other people working on the code that the method shouldn’t be used externally…

  28. sipa commented at 1:28 am on October 12, 2017: member
    @JeremyRubin Even if it works, I’m pretty sure that it’s UB.
  29. NicolasDorier commented at 5:08 am on October 12, 2017: contributor
    Can we add to milestone 0.15.1?
  30. luke-jr approved
  31. luke-jr commented at 7:32 am on October 12, 2017: member
    tACK
  32. laanwj added this to the milestone 0.15.1 on Oct 12, 2017
  33. laanwj commented at 12:54 pm on October 12, 2017: member
    utACK 4526d21
  34. laanwj merged this on Oct 12, 2017
  35. laanwj closed this on Oct 12, 2017

  36. laanwj referenced this in commit f74459dba6 on Oct 12, 2017
  37. ruimarinho commented at 3:07 am on November 1, 2017: none
    Tested and working as expected. Mixing node with non-node requests now works fine. @laanwj any chance of backporting this to 0.15.1?
  38. MarcoFalke added the label Needs backport on Nov 1, 2017
  39. MarcoFalke commented at 4:00 pm on November 1, 2017: member
    @ruimarinho Thanks for the ping. Somehow the backport label was missing and I forgot to include it in #11447
  40. MarcoFalke referenced this in commit a7db0fd4ab on Nov 2, 2017
  41. MarcoFalke referenced this in commit 34fe055b6a on Nov 2, 2017
  42. MarcoFalke referenced this in commit 1e7ea108a1 on Nov 2, 2017
  43. MarcoFalke referenced this in commit 25e710c52a on Nov 2, 2017
  44. MarcoFalke referenced this in commit 8edff7ecbc on Nov 2, 2017
  45. MarcoFalke referenced this in commit 492093115e on Nov 2, 2017
  46. MarcoFalke referenced this in commit 70268454e8 on Nov 8, 2017
  47. MarcoFalke referenced this in commit 305f768242 on Nov 8, 2017
  48. MarcoFalke referenced this in commit 2eea279fe6 on Nov 8, 2017
  49. MarcoFalke referenced this in commit 1036c43fe5 on Nov 8, 2017
  50. MarcoFalke referenced this in commit 1c8c7f8af9 on Nov 8, 2017
  51. MarcoFalke referenced this in commit 3a6cdd459c on Nov 8, 2017
  52. MarcoFalke removed the label Needs backport on Nov 9, 2017
  53. MarcoFalke commented at 7:40 pm on November 9, 2017: member
    Removing backport tag: #11647
  54. MarcoFalke removed this from the milestone 0.15.2 on Nov 9, 2017
  55. jnewbery deleted the branch on Nov 9, 2017
  56. jnewbery restored the branch on Nov 9, 2017
  57. codablock referenced this in commit 6a10b36925 on Sep 26, 2019
  58. codablock referenced this in commit d7119e6487 on Sep 30, 2019
  59. barrystyle referenced this in commit 5970217cb6 on Jan 22, 2020
  60. 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: 2024-12-18 21:12 UTC

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