Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of undocumented/undefined boost::signals2 behavior in wallet #26442

Open
theuni opened this issue Nov 1, 2022 · 2 comments
Open

Use of undocumented/undefined boost::signals2 behavior in wallet #26442

theuni opened this issue Nov 1, 2022 · 2 comments

Comments

@theuni
Copy link
Member

theuni commented Nov 1, 2022

While working on a minimal rewrite for our remaining usage of boost::signals2 (POC branch here), I stumbled upon some undocumented/undefined behavior with our current usage.

Specifically the problem, introduced in #17261, is that signals aren't intended to connect to other signals. Currently this is violated in the wallet: https://github.com/bitcoin/bitcoin/blob/master/src/wallet/wallet.cpp#L3518

See the boost discussion here: https://groups.google.com/g/boost-list/c/So4i8JXneJ0

On my WIP replacement branch I implemented it by chaining the calls as suggested (and as-intended in our code):
https://github.com/theuni/bitcoin/blob/replace-boost-signals/src/btcsignals.h#L140 . This makes tests happy, so presumably that's what's going on with boost too, though there are details (like interim disconnections) which could give us trouble in the future.

Regardless of the fact that this works for now, I don't think that we should be relying on it. I haven't looked into the details, but I'm hoping it could be fixed with some simple stub functions.

Ping @achow101. Any easy/obvious workarounds?

@theuni theuni added the Bug label Nov 1, 2022
@maflcko maflcko added the Wallet label Nov 1, 2022
@achow101
Copy link
Member

achow101 commented Nov 1, 2022

CWallet itself does not actually need to have these signals itself, they really are just passthrough from the SPKMs. The exception is a few places where CWallet is doing something with a SPKM and needs to emit NotifyCanGetAddressesChanged, but it could just call the signal in the SPKM it's working on in order to do that instead of having it's own signal. So the obvious solution here would be to connect to the SPKM signals directly instead of CWallet's, and remove the signals from CWallet entirely. This could be done with a helper (perhaps modifying ConnectScriptPubKeyManNotifiers?), although perhaps there might be issues with connecting the signal for SPKMs that are created afterwards.

@furszy
Copy link
Member

furszy commented Nov 1, 2022

although perhaps there might be issues with connecting the signal for SPKMs that are created afterwards.

The wallet could trigger a signal on every added SPKM. e.g. trigger NewScriptPubKeyMan(const uint256& id) so the GUI subscribes to it calling ConnectScriptPubKeyMan(const uint256& id, callback).

Still, have to say that I'm not so convinced about it. Independently from boost's problem, I think that, layers division wise, the spkm signal should first pass through the wallet, which could perform some operations with it (update/refresh some state/cache), and then the wallet trigger the upper layers signal (or call a function in a signals dispatcher object like we do in the validation area).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants