Skip to content

Conversation

kevkevinpal
Copy link
Contributor

@kevkevinpal kevkevinpal commented Sep 11, 2023

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

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 11, 2023

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.

@kristapsk
Copy link
Contributor

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

@kevkevinpal
Copy link
Contributor Author

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

@kristapsk
Copy link
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

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch 3 times, most recently from 54acb38 to 1cc6b1c Compare September 12, 2023 01:56
@kevkevinpal kevkevinpal changed the title wallet: allowing walletpassphrase timeout to be empty wallet: allowing walletpassphrase timeout to be MAX_SLEEP_TIME if set to 0 Sep 12, 2023
@kevkevinpal
Copy link
Contributor Author

@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

@maflcko
Copy link
Member

maflcko commented Sep 12, 2023

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)

Copy link
Contributor

@ishaanam ishaanam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (da409dc), if anyone is curious, but the approach implemented in this PR is simpler.

@luke-jr
Copy link
Member

luke-jr commented Sep 13, 2023

(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?

@jonatack
Copy link
Member

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.

@maflcko
Copy link
Member

maflcko commented Sep 13, 2023

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?

@maflcko
Copy link
Member

maflcko commented Sep 13, 2023

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?

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 1cc6b1c to 7deb571 Compare September 13, 2023 19:53
@kevkevinpal
Copy link
Contributor Author

forced pushed to 7deb571

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

@kevkevinpal
Copy link
Contributor Author

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

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 7deb571 to a7bc5db Compare September 13, 2023 21:23
@kevkevinpal
Copy link
Contributor Author

Thanks @jonatack I added those changes and pushed a7bc5db

@maflcko
Copy link
Member

maflcko commented Sep 14, 2023

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:

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

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

@jonatack
Copy link
Member

@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.

@kevkevinpal
Copy link
Contributor Author

@kevkevinpal I think the OP is out of date.

Sorry not sure what you mean here

@ishaanam
Copy link
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.

@kevkevinpal
Copy link
Contributor Author

@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

@ishaanam
Copy link
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.

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch 2 times, most recently from 0d65b4c to c4ce733 Compare September 15, 2023 17:11
@kevkevinpal
Copy link
Contributor Author

kevkevinpal commented Sep 15, 2023

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

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from c4ce733 to 4e4ff8d Compare September 15, 2023 17:15
@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 4e4ff8d to 9be4f3e Compare September 15, 2023 21:53
@maflcko
Copy link
Member

maflcko commented Sep 17, 2023

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

@kevkevinpal
Copy link
Contributor Author

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

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 9be4f3e to 0fc8db0 Compare September 17, 2023 20:02
@kevkevinpal kevkevinpal changed the title 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 Sep 17, 2023
@kevkevinpal
Copy link
Contributor Author

Removed non mainnet if block and switched to using -1 instead of 0 to set time as MAX_SLEEP_TIME in 0fc8db0

@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 0fc8db0 to 7969c6b Compare October 20, 2023 01:53
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
@kevkevinpal kevkevinpal force-pushed the defaultWalletPassphraseTimeout branch from 7969c6b to 76b1c4c Compare October 20, 2023 01:54
@kevkevinpal
Copy link
Contributor Author

kevkevinpal commented Oct 20, 2023

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

@kevkevinpal
Copy link
Contributor Author

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

@kevkevinpal kevkevinpal closed this Nov 2, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Nov 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants