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

Refactor: separate gui from wallet and node #10244

Merged
merged 21 commits into from Apr 5, 2018
Merged

Conversation

@ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Apr 20, 2017

This is a refactoring PR that does not change behavior in any way. This change:

  1. Creates abstract Node and Wallet interfaces in src/interface/
  2. Updates Qt code to call the new interfaces. This largely consists of diffs of the form:
-    InitLogging();
-    InitParameterInteraction();
+    node.initLogging();
+    node.initParameterInteraction();

This change allows followup PR #10102 (makes bitcoin-qt control bitcoind over an IPC socket) to work without any significant updates to Qt code. Additionally:

  • It provides a single place to describe the interface between GUI and daemon code.
  • It can make better GUI testing possible, because Node and Wallet objects have virtual methods that can be overloaded for mocking.
  • It can be used to help make the GUI more responsive (see #10504)

Other notes:

  • I used python scripts hide-globals.py and replace-syms.py to identify all the places where Qt code was accessing libbitcoin global variables and calling functions accessing those global variables.
  • These changes were originally part of #10102. Thanks to @JeremyRubin for the suggestion of splitting them out.

Commits:

@laanwj
Copy link
Member

@laanwj laanwj commented Apr 20, 2017

ClientModel and WalletModel were already meant as abstraction layer for accessing the core from the GUI. What is your rationale for adding another layer?

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 20, 2017

ClientModel and WalletModel were already meant as abstraction layer for accessing the core from the GUI. What is your rationale for adding another layer?

ClientModel and WalletModel might have been intended to be an abstraction layer, but they are not functioning like one. There are libbitcoin functions and global variables accessed all over Qt code right now. With this change, all of these calls (there are around 200 of them) are stripped out of Qt code and moved into a one file: src/ipc/local/interfaces.cpp.

@jonasschnelli
Copy link
Member

@jonasschnelli jonasschnelli commented Apr 20, 2017

I once did a similar thing,.. but stopped at some point and now I know why.
It's an impressive code change and I kinda like a central point (your interfaces.cpp) where communication between the node, the wallet and the GUI happens.

I also agree with @laanwj that the clientmodel (node) and the walletmodal (wallet) are originally though to be that layer.
Though, there are many violations AFAIK.

What would be the downsides of using the exiting layers (clientmodel / walletmodel) better?

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 20, 2017

What would be the downsides of using the exiting layers (clientmodel / walletmodel) better?

If you look at the ClientModel class, you can see it is doing a lot more work than the ipc::local::Node class is. Similarly with WalletModel and ipc::local::Wallet. The ipc classes are just simple shims around low-level node and wallet functionality, while Qt objects implement higher level logic specific to our current GUI. I think ClientModel and WalletModel classes are still useful after this change. They will just have 1 job instead of 2. Instead of serving as both abstraction layers and MVC model classes, they will serve only as MVC model classes.

Also, and in more concrete terms, the reason these interfaces live outside the src/qt directory is that with #10102, they need to be accessed not only by bitcoin-qt but also by bitcoind (specifically inside the StartServer function in src/ipc/server.cpp which is called here: ryanofsky@ab0afba#diff-6e30027c2045842fe842430d98d099fb

@jonasschnelli
Copy link
Member

@jonasschnelli jonasschnelli commented Apr 21, 2017

The general IPC interface makes sense to me. The main problem I see for any type of low latency IPC/RPC is the missing asynchronity.
Take getWalletTxDetails. This IPC call may take 2-3 seconds depending on the communication protocol and database you are using. Ideally the GUI is design to handle it asynchronous (like an RPC call) otherwise this will lead to GUI thread freezes. Not sure if this would be solvable as a generic part in the IPC layer of if the wallet/GUI logic must handle it.

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 21, 2017

The main problem I see for any type of low latency IPC/RPC is the missing asynchronity.

Not sure if you saw the comments about this in the other pr starting here: #10102 (comment)

These changes are orthogonal to event processing / blocking issues in the UI. If UI blocked before, it will still block after these changes, if UI didn't block before, it won't start blocking now because of these changes. If remote calls are too slow because of socket/serialization overhead, we can process UI events in the background while they are being made. There are many ways to accomplish this, with one possible way described in that comment above. If anything, having calls get funnelled through an IPC framework makes it easier, not harder to add more asynchronicity.

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 21, 2017

Also would point out that Node and Wallet interfaces in ipc/interfaces.h were mainly designed with goal of changing existing Qt code as little as possible. They aren't in any way set in stone, and I would expect them to evolve over time. Probably some calls will get consolidated, others will get broken up, calls that currently return big chunks of data will be made streaming, etc.

@jonasschnelli
Copy link
Member

@jonasschnelli jonasschnelli commented Apr 21, 2017

Thinking again and discussing this with @sipa / @laanwj, I think we should use the existing client-/walletmodal as node/wallet abstraction (including a possible IPC abstraction).

What's missing in the first place are better asynchronous messaging between the GUI and the wallet/node.

IMO using a thread with queue for general node/wallet communication (and eventual additional threads for procedures that usually take longer) seems after a low hanging fruit with direct benefits.

Using QT slots/signals for all(most?) communication would be required anyways and would be beneficial even without IPC and therefor should be done first.

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 21, 2017

What's missing in the first place are better asynchronous messaging between the GUI and the wallet/node.

Again I think this is (and should be) an independent issue, but if you want to flesh out some more concrete suggestions and I would be happy to hear them.

IMO using a thread with queue for general node/wallet communication (and eventual additional threads for procedures that usually take longer) seems after a low hanging fruit with direct benefits.

This is exactly what the change I was suggesting in #10102 (comment) does.

@laanwj
Copy link
Member

@laanwj laanwj commented Apr 21, 2017

Using QT slots/signals for all(most?) communication would be required anyways and would be beneficial even without IPC and therefor should be done first.

This was my point too. Making the GUI asynchronous would avoid ever hard-freezing the GUI. Modern operating systems assume that an application has crashed if its GUI thread is unresponsive. This is a priority for improving user experience. For example: Currently, if e.g. a transaction is sent while the cs_main lock is held the entire thing hangs for a moment. Ideally it would display a modal dialog with a status, or progress animation instead. There are similar issues at startup.

Sure, this is only partially related to IPC work: When the GUI already would communicate with Qt signals and slots with the core backend (similar to how RPCConsole and RPCThread communicate, for example), it could be mostly oblivious whether this backend exists in-process or communicates over a pipe.

Although it's laudable that you're working on this, it looks to me that what you are doing currently is simply replicating what we do now but replacing direct core calls with IPC calls. The drawback is that it calcifies some things that shouldn't have been designed that way in the first place (e.g. into multiple abstraction layers), making it harder to improve later.

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 21, 2017

The drawback is that it calcifies some things

Could you be more concrete about this? I don't see how it is true. Direct calls before are still direct calls now. If we want to follow the RPCConsole / RPCExecutor model in other parts of Qt code, I don't see how any of the changes I've made for IPC make this more difficult.

@ryanofsky
Copy link
Contributor Author

@ryanofsky ryanofsky commented Apr 21, 2017

I had a look at discussion in IRC (https://botbot.me/freenode/bitcoin-core-dev/msg/84348426/)

With respect, what I think you guys are missing on the WalletModel/ClientModel topic is that the ipc::local::WalletImpl and ipc::local::NodeImpl classes in ipc/local/interfaces.cpp are only temporarily being created and invoked within the bitcoin-qt process. In the next PR they are created and run in the bitcoind process instead of bitcoin-qt. That's the reason these classes do not reside in the src/qt directory and one reason why they don't really substitute for the WalletModel/ClientModel classes. See my previous comment for details and a code pointer: #10244 (comment).

However, I do see that it is kind of silly to have cases where Qt code calls a WalletModel/ClientModel method that merely forwards to a WalletImpl/NodeImpl method. I can easily clear this up by inlining these WalletModel/ClientModel methods, which would make the classes more lean.

Also, if this PR will be too difficult to review because of its size (https://botbot.me/freenode/bitcoin-core-dev/msg/84348447/), I can easily decompose it into smaller PRs that could be gradually merged. It is already broken up into separate commits, and many of the individual commits could be further broken up (right now they try to group together related changes).

@ryanofsky ryanofsky force-pushed the pr/ipc-local branch 4 times, most recently from 3f77678 to 4c91131 Apr 28, 2017
@ryanofsky ryanofsky force-pushed the pr/ipc-local branch 2 times, most recently from ca542df to 78be4d1 May 23, 2017
@ryanofsky ryanofsky force-pushed the pr/ipc-local branch 5 times, most recently from f31ecfc to 89cad8e May 25, 2017
sidhujag added a commit to syscoin/syscoin that referenced this issue Aug 26, 2020
Change gui code to use gArgs, Params() functions directly instead of going
through interfaces::Node.

Remotely accessing bitcoin-node ArgsManager from bitcoin-gui works fine in
bitcoin#10102, when bitcoin-gui spawns a new
bitcoin-node process and controls its startup, but for bitcoin-gui to support
-ipcconnect option in bitcoin#19461 and connect
to an existing bitcoin-node process, it needs ability to parse arguments itself
before connecting out.

This change also simplifies bitcoin#10102 a
bit, by making the bitcoin-gui -> bitcoin-node startup sequence more similar to
the bitcoin-node -> bitcoin-wallet startup sequence where the parent process
parses arguments and passes them to the child process instead of the parent
process using the child process to parse arguments.
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 28, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 28, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 28, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 28, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 28, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 29, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 29, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 30, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 30, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 30, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Aug 30, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Sep 27, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Sep 29, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Sep 29, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 1, 2020
…build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 1, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 2, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 2, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 2, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 2, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 5, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 5, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 5, 2020
Suggested by John Newbery <john@johnnewbery.com>
bitcoin#10244 (comment)
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 5, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
xdustinface added a commit to xdustinface/dash that referenced this issue Oct 14, 2020
…windows gitian build

17780d6 scripted-diff: Avoid `interface` keyword to fix windows gitian build (Russell Yanofsky)

Pull request description:

  Rename `interface` to `interfaces`

  Build failure reported by ken2812221 in bitcoin#10244 (comment)

Tree-SHA512: e02c97c728540f344202c13b036f9f63af23bd25e25ed7a5cfe9e2c2f201a12ff232cc94a93fbe37ef6fb6bf9e036fe62210ba798ecd30de191d09338754a8d0

-BEGIN VERIFY SCRIPT-
git mv src/interface src/interfaces
ren() { git grep -l "$1" | xargs sed -i "s,$1,$2,g"; }
ren interface/            interfaces/
ren interface::           interfaces::
ren BITCOIN_INTERFACE_    BITCOIN_INTERFACES_
ren "namespace interface" "namespace interfaces"
-END VERIFY SCRIPT-
paaqp
Copy link

ghost commented on 5884558 Mar 20, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Linked issues

Successfully merging this pull request may close these issues.

None yet