wallet: allowing walletpassphrase timeout to be MAX_SLEEP_TIME if set to -1 #28454

pull kevkevinpal wants to merge 1 commits into bitcoin:master from kevkevinpal:defaultWalletPassphraseTimeout changing 3 files +10 −6
  1. kevkevinpal commented at 10:57 pm on September 11, 2023: contributor

    In this change we allow the timeout for walletpassphrase to be set to MAX_SLEEP_TIME, if set as -1 then we then use the MAX_SLEEP_TIME amount

    context from PR 28403

    added release notes for RPC Wallet

    Also tests were modified to use the max timeout amount using timeout = -1

  2. DrahtBot commented at 10:57 pm on September 11, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept NACK kristapsk

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    No conflicts as of last run.

  3. DrahtBot added the label Wallet on Sep 11, 2023
  4. kevkevinpal force-pushed on Sep 11, 2023
  5. kevkevinpal force-pushed on Sep 11, 2023
  6. kristapsk commented at 11:13 pm on September 11, 2023: contributor
    Concept NACK. I don’t think this is a good idea for mainnet.
  7. kevkevinpal commented at 11:18 pm on September 11, 2023: contributor

    Concept NACK. I don’t think this is a good idea for mainnet.

    Any specific reason why? A user can currently input a time larger than MAX_SLEEP_TIME and it would be set to it, we are just defaulting to it if no arg is added.

    Or are you more concerned that a user wouldn’t notice the optional arg and unexpectedly have a command with a long timeout running?

    There was also the suggestion of 0 being used instead of omitting the arg to signal max timeout

  8. kristapsk commented at 11:24 pm on September 11, 2023: contributor

    Or are you more concerned that a user wouldn’t notice the optional arg and unexpectedly have a command with a long timeout running?

    Yes

  9. kevkevinpal force-pushed on Sep 12, 2023
  10. kevkevinpal force-pushed on Sep 12, 2023
  11. kevkevinpal force-pushed on Sep 12, 2023
  12. kevkevinpal renamed this:
    wallet: allowing walletpassphrase timeout to be empty
    wallet: allowing walletpassphrase timeout to be MAX_SLEEP_TIME if set to 0
    on Sep 12, 2023
  13. kevkevinpal commented at 1:58 am on September 12, 2023: contributor
    @kristapsk I modified the PR to 1cc6b1c which now keeps it as a non optional param but now if the user sets 0 then we will use the MAX_SLEEP_TIME
  14. maflcko commented at 6:48 am on September 12, 2023: member
    Seems fine to do this. While 0 is currently accepted, it should have no use case that someone can rely on. (If someone wanted to immediately re-lock, it seems easier to do it synchronously with the walletlock RPC, than to wait for the async callback and poll the locked-state in a loop)
  15. ishaanam commented at 1:02 am on September 13, 2023: contributor
    This looks good to me, though I think it could use some release notes. An alternative to this could be that if the timeout is set to 0, then the wallet never automatically locks. I’ve implemented this here (da409dc5df6bb2ef3208b39d0b2a563debd03376), if anyone is curious, but the approach implemented in this PR is simpler.
  16. maflcko added the label Needs release note on Sep 13, 2023
  17. luke-jr commented at 4:12 pm on September 13, 2023: member

    (If someone wanted to immediately re-lock, it seems easier to do it synchronously with the walletlock RPC, than to wait for the async callback and poll the locked-state in a loop)

    I wonder if there’s an argument around a JSON-RPC batch that unlocks, runs some method, and re-locks… Probably wouldn’t work today, but might be worth adding?

  18. jonatack commented at 5:03 pm on September 13, 2023: contributor

    Would be good to add test coverage and a release note.

    now if the user sets 0 then we will use the MAX_SLEEP_TIME

    That said, I think this breaks https://en.wikipedia.org/wiki/Principle_of_least_astonishment (should behave in a way that most users will expect it to behave), and in a less secure direction.

  19. maflcko commented at 7:49 pm on September 13, 2023: member

    I wonder if there’s an argument around a JSON-RPC batch that unlocks, runs some method, and re-locks… Probably wouldn’t work today, but might be worth adding?

    Agree that this would be nice, but seems unrelated to this pull, or would the batch feature require this RPC?

  20. maflcko commented at 7:51 pm on September 13, 2023: member

    That said, I think this breaks https://en.wikipedia.org/wiki/Principle_of_least_astonishment (should behave in a way that most users will expect it to behave), and in a less secure direction.

    The same is used for the rpc client/server timeout, so I think it seems more consistent to map 0 to max. Though, if it is too controversial, any negative value can be mapped to max instead?

  21. kevkevinpal force-pushed on Sep 13, 2023
  22. kevkevinpal commented at 7:54 pm on September 13, 2023: contributor

    forced pushed to 7deb571

    added release notes and changed tests in this commit to use timeout=0

  23. kevkevinpal commented at 7:56 pm on September 13, 2023: contributor

    That said, I think this breaks https://en.wikipedia.org/wiki/Principle_of_least_astonishment (should behave in a way that most users will expect it to behave), and in a less secure direction.

    The same is used for the rpc client/server timeout, so I think it seems more consistent to map 0 to max. Though, if it is too controversial, any negative value can be mapped to max instead?

    I would be open to using a negative value eg(-1) since any negative value rn throws an error. But I do think if we’re using 0 else where we should either continue doing the same or change it there aswell

  24. in doc/release-notes-28454.md:4 in 7deb571196 outdated
    0@@ -0,0 +1,6 @@
    1+RPC Wallet
    2+----------
    3+
    4+- The `walletpassphrase` call will now use MAX_SLEEP_TIME
    


    jonatack commented at 8:00 pm on September 13, 2023:

    MAX_SLEEP_TIME isn’t a user-facing value

    0- The `walletpassphrase` call now uses the value of 100,000,000 seconds (~3 years)
    
  25. in doc/release-notes-28454.md:5 in 7deb571196 outdated
    0@@ -0,0 +1,6 @@
    1+RPC Wallet
    2+----------
    3+
    4+- The `walletpassphrase` call will now use MAX_SLEEP_TIME
    5+  if the user sets 0 for the timeout arg.
    


    jonatack commented at 8:02 pm on September 13, 2023:
    0  if the user passes a `timeout` value of `0`. (#28454)
    
  26. jonatack commented at 8:09 pm on September 13, 2023: contributor
    What would be a use case for encrypting a wallet and then setting a 3-year timeout? Maybe I’m missing something, but it seems like doing so should be explicit (as it is currently). I would expect users to pass as short a value as possible, i.e. a few seconds or minutes.
  27. kevkevinpal force-pushed on Sep 13, 2023
  28. DrahtBot added the label CI failed on Sep 13, 2023
  29. kevkevinpal commented at 9:24 pm on September 13, 2023: contributor
    Thanks @jonatack I added those changes and pushed a7bc5db
  30. DrahtBot removed the label CI failed on Sep 13, 2023
  31. maflcko commented at 6:24 am on September 14, 2023: member

    What would be a use case for encrypting a wallet and then setting a 3-year timeout? Maybe I’m missing something, but it seems like doing so should be explicit (as it is currently). I would expect users to pass as short a value as possible, i.e. a few seconds or minutes.

    Setting a high timeout allows the user to run a wallet operation (of unknown duration) and then immediately re-lock it after it finished, see #28454 (comment).

    For example, this can be done inside a python context:

    0print("wallet is locked")
    1with unlocked_wallet() as w:
    2  w.getnewaddress()
    3print("wallet is now locked again")
    

    Where unlocked_wallet unlocks the wallet and returns w that locks when leaving the context.

  32. jonatack commented at 4:32 pm on September 14, 2023: contributor
    @kevkevinpal I think the OP is out of date. @MarcoFalke Thanks for the reply. It still seems safer to keep it explicit, so an application developer or cli user doesn’t shoot themselves in the foot. As mentioned in #28454 (comment), this change would violate behaving in a way that most users will expect it to behave, and in a less secure direction. So I’m quite hesitant here.
  33. kevkevinpal commented at 10:21 pm on September 14, 2023: contributor

    @kevkevinpal I think the OP is out of date.

    Sorry not sure what you mean here

  34. ishaanam commented at 3:26 pm on September 15, 2023: contributor
    @kevkevinpal The description of this PR no longer describes what has been implemented because this PR was changed to not allow timeout to be optional.
  35. kevkevinpal commented at 3:29 pm on September 15, 2023: contributor

    @kevkevinpal The description of this PR no longer describes what has been implemented because this PR was changed to not allow timeout to be optional.

    Thanks, updated the PR description to match the commit message

  36. ishaanam commented at 4:17 pm on September 15, 2023: contributor
    I think that it would also be fine to only implement this for testnet and regtest. The wallet locking too soon has been a frequently occurring problem with wallet tests. If this is required for the batch feature however, then that is another case.
  37. kevkevinpal force-pushed on Sep 15, 2023
  38. kevkevinpal force-pushed on Sep 15, 2023
  39. kevkevinpal commented at 5:14 pm on September 15, 2023: contributor

    I think that it would also be fine to only implement this for testnet and regtest. The wallet locking too soon has been a frequently occurring problem with wallet tests. If this is required for the batch feature however, then that is another case.

    Added if block to check if non-mainnet (let me know if you want to exclude signet for any reason). Also updated the help doc to say that this would only happen in non mainnet. Updated commit message to include info about this only working in non mainnet in 9be4f3e

  40. kevkevinpal force-pushed on Sep 15, 2023
  41. DrahtBot added the label CI failed on Sep 15, 2023
  42. kevkevinpal force-pushed on Sep 15, 2023
  43. DrahtBot removed the label CI failed on Sep 16, 2023
  44. in src/wallet/rpc/encrypt.cpp:65 in 9be4f3e9e1 outdated
    59@@ -59,6 +60,12 @@ RPCHelpMan walletpassphrase()
    60         }
    61         // Clamp timeout
    62         constexpr int64_t MAX_SLEEP_TIME = 100000000; // larger values trigger a macos/libevent bug?
    63+
    64+        // Allow sleep time to be set to max time by using zero in non mainnet
    65+        if (Params().GetChainType() != ChainType::MAIN && nSleepTime == 0) {
    


    maflcko commented at 9:25 am on September 17, 2023:

    I am not really a fan of writing test-only code in real code. This is even more true for the RPC interface.

    Either this feature makes sense, in which case it should be done for mainnet, or it does not, in which case it shouldn’t be done at all.


    kevkevinpal commented at 7:52 pm on September 17, 2023:
    I agreed I can switch it back to being for all chaintypes
  45. maflcko commented at 9:27 am on September 17, 2023: member
    On a second thought, I wonder if someone uses 0 as a brittle alias for walletlock. Maybe not worth it to risk breaking that?
  46. kevkevinpal commented at 7:53 pm on September 17, 2023: contributor

    On a second thought, I wonder if someone uses 0 as a brittle alias for walletlock. Maybe not worth it to risk breaking that?

    I can switch it from 0 to -1 since negative values are not being used currently for timeout

  47. kevkevinpal force-pushed on Sep 17, 2023
  48. kevkevinpal renamed this:
    wallet: allowing walletpassphrase timeout to be MAX_SLEEP_TIME if set to 0
    wallet: allowing walletpassphrase timeout to be MAX_SLEEP_TIME if set to -1
    on Sep 17, 2023
  49. kevkevinpal commented at 8:04 pm on September 17, 2023: contributor
    Removed non mainnet if block and switched to using -1 instead of 0 to set time as MAX_SLEEP_TIME in 0fc8db0
  50. DrahtBot added the label Needs rebase on Oct 5, 2023
  51. kevkevinpal force-pushed on Oct 20, 2023
  52. wallet: walletpassphrase timeout to be set to MAX_SLEEP_TIME
    In this change we allow the timeout for walletpassphrase to be
    set to MAX_SLEEP_TIME,
    if set as -1 then we then use the MAX_SLEEP_TIME amount
    
    context from PR 28403
    
    added release notes for RPC Wallet
    
    Also tests were modified to use the max timeout amount using timeout = -1
    76b1c4ca6e
  53. kevkevinpal force-pushed on Oct 20, 2023
  54. kevkevinpal commented at 1:59 am on October 20, 2023: contributor

    rebased to 76b1c4c and since this PR 28617 has been merged only the test-framework will be modified so I am not sure if this change is needed anymore.

    Thoughts @maflcko? I am happy to close this

  55. DrahtBot removed the label Needs rebase on Oct 20, 2023
  56. maflcko removed the label Needs release note on Oct 20, 2023
  57. kevkevinpal commented at 7:31 pm on November 2, 2023: contributor

    rebased to 76b1c4c and since this PR 28617 has been merged only the test-framework will be modified so I am not sure if this change is needed anymore.

    Thoughts @maflcko? I am happy to close this

    closing this pull request

  58. kevkevinpal closed this on Nov 2, 2023


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-09-29 04:12 UTC

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