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

doc: Add multiprocess design doc #28978

Merged
merged 1 commit into from Jan 2, 2024
Merged

Conversation

ryanofsky
Copy link
Contributor

Add multiprocess design doc and existing multiprocess documentation into design and usage sections.

Links to rendered markdown:

https://github.com/ryanofsky/bitcoin/blob/pr/ipcdoc/doc/design/multiprocess.md
https://github.com/ryanofsky/bitcoin/blob/pr/ipcdoc/doc/multiprocess.md


This PR is part of the process separation project.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 30, 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
ACK TheCharlatan, fjahr, stickies-v, achow101

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

@DrahtBot DrahtBot added the Docs label Nov 30, 2023
@ryanofsky ryanofsky mentioned this pull request Nov 30, 2023
49 tasks
doc/multiprocess.md Outdated Show resolved Hide resolved
doc/multiprocess.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 66e19e7 -> f566245 (pr/ipcdoc.6 -> pr/ipcdoc.7, compare) fixing broken links and making small edits.

doc/multiprocess.md Outdated Show resolved Hide resolved
doc/multiprocess.md Outdated Show resolved Hide resolved
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated f566245 -> 837c53d (pr/ipcdoc.7 -> pr/ipcdoc.8, compare) adding suggested future enhancement and making a few other tweaks

doc/design/multiprocess.md Show resolved Hide resolved
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

Approach ACK. I'm still working on my understanding of multiprocess but this document was very helpful already in its current state, no major suggestions at this point.

doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
Copy link
Contributor

@fjahr fjahr left a comment

Choose a reason for hiding this comment

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

ACK 837c53d

For me this can already be merged as is but I also have a list of nits if you retouch. I have made myself familiar multiprocess a while ago but not looked at it recently. For me this was a nice refresher and I definitely think it's helpful for newcomers.

A few more ideas of what might be interesting to add, but they are not essential and may also be done in a follow-up or just be ignored:

  • Could mention potential security implications (or lack thereof) of using capnp and libmultiprocess (at least as long as it's not maintained under the bitcoin-core org.
  • Similar to the usage example there could be an example of how a developer may go about changing something in the interfaces, mentioning common pitfalls etc.
  • If possible maybe a visualization/diagram how the pieces of the architecture fit together could be helpful to grasp the high level quicker.

doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Show resolved Hide resolved
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated 837c53d -> fd98bee (pr/ipcdoc.8 -> pr/ipcdoc.9, compare) with suggested changes.
Updated fd98bee -> c80bd16 (pr/ipcdoc.9 -> pr/ipcdoc.10, compare) with more edits and tweaks.

re: #28978 (review)

Approach ACK. I'm still working on my understanding of multiprocess but this document was very helpful already in its current state, no major suggestions at this point.

Thank you, applied your suggestions, and improved the example flow section based on your feedback.

re: #28978 (review)

ACK 837c53d

For me this can already be merged as is but I also have a list of nits if you retouch. I have made myself familiar multiprocess a while ago but not looked at it recently. For me this was a nice refresher and I definitely think it's helpful for newcomers.

A few more ideas of what might be interesting to add, but they are not essential and may also be done in a follow-up or just be ignored:

  • Could mention potential security implications (or lack thereof) of using capnp and libmultiprocess (at least as long as it's not maintained under the bitcoin-core org.

Great idea, added security consideration section addressing these things.

  • Similar to the usage example there could be an example of how a developer may go about changing something in the interfaces, mentioning common pitfalls etc.

I think developer notes, particularly the Internal interface guidelines section will be a good place for this type of information. I added another link to it in the Interface Definition Maintenance section here. Probably the developer notes will need to have a little more information added, but that depends on more code being merged so should probably be left for future PRs.

  • If possible maybe a visualization/diagram how the pieces of the architecture fit together could be helpful to grasp the high level quicker.

Yeah some visualizations would probably help. I added 3 simple diagrams, showing process/socket connections, code generation, and a call diagram, so hopefully these are helpful.

doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Show resolved Hide resolved
doc/multiprocess.md Outdated Show resolved Hide resolved
doc/design/multiprocess.md Outdated Show resolved Hide resolved
Also split up existing multiprocess documentation into design and usage
sections
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Updated c80bd16 -> 91dc48c (pr/ipcdoc.10 -> pr/ipcdoc.11, compare) fixing table tag and reference heading.

I think this PR gets another ACK it could be merged to add the new documentation, and improvements could be implemented in a followup PR.

doc/design/multiprocess.md Outdated Show resolved Hide resolved
Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

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

ACK 91dc48c

@DrahtBot DrahtBot requested a review from fjahr December 27, 2023 07:57
@fjahr
Copy link
Contributor

fjahr commented Dec 28, 2023

ACK 91dc48c

@DrahtBot DrahtBot removed the request for review from fjahr December 28, 2023 20:19
Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

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

ACK 91dc48c - left a couple of improvements but agreed that iterating in future PRs is better.

```
cd <BITCOIN_SOURCE_DIRECTORY>
make -C depends NO_QT=1 MULTIPROCESS=1
CONFIG_SITE=$PWD/depends/x86_64-pc-linux-gnu/share/config.site ./configure
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Perhaps useful to parameterize the host platform to highlight it's configurable? E.g.

HOST_PLATFORM="x86_64-pc-linux-gnu"
cd <BITCOIN_SOURCE_DIRECTORY>
make -C depends NO_QT=1 MULTIPROCESS=1
CONFIG_SITE=$PWD/depends/$HOST_PLATFORM/share/config.site ./configure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

nit: Perhaps useful to parameterize the host platform to highlight it's configurable? E.g.

Thanks I split it into a separate variable and clarified how it could be set in #10102.

- In the generated code, we have C++ client subclasses that inherit from the abstract classes in [`src/interfaces/`](../../src/interfaces/). These subclasses are the workhorses of the IPC mechanism.
- They implement all the methods of the interface, marshalling arguments into a structured format, sending them as requests to the IPC server via a UNIX socket, and handling the responses.
- These subclasses effectively mask the complexity of IPC, presenting a familiar C++ interface to developers.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests.
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps useful to elaborate on what the mpgen wrapping adds to the Cap'n Proto output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

Perhaps useful to elaborate on what the mpgen wrapping adds to the Cap'n Proto output?

Great suggestion, done in #10102. The main difference is mpgen clients subclasses have a high-level blocking interface, while capnp client subclasses require you to do asynchronous and pass arguments and return values in capnp message format.


An alternate approach could use custom [C++ Attributes](https://en.cppreference.com/w/cpp/language/attributes) embedded in interface declarations to automatically generate `.capnp` files from C++ headers. This has not been pursued because parsing C++ headers is more complicated than parsing Cap’n Proto interface definitions, especially portably on multiple platforms.

In the meantime, the developer guide [Internal interface guidelines](developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.
Copy link
Contributor

Choose a reason for hiding this comment

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

dead link

Suggested change
In the meantime, the developer guide [Internal interface guidelines](developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.
In the meantime, the developer guide [Internal interface guidelines](../developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

dead link

Thanks, fixed in #10102

- Upon receiving the request, the Cap'n Proto dispatching code in the `bitcoin-node` process calls the `getBlockHash` method of the `Chain` [server class](#c-server-classes-in-generated-code).
- The server class is automatically generated by the `mpgen` tool from the [`chain.capnp`](https://github.com/ryanofsky/bitcoin/blob/pr/ipc/src/ipc/capnp/chain.capnp) file in [`src/ipc/capnp/`](../../src/ipc/capnp/).
- The `getBlockHash` method of the generated `Chain` server subclass in `bitcoin-wallet` receives a Cap’n Proto request object with the `height` parameter, and calls the `getBlockHash` method on its local `Chain` object with the provided `height`.
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process,
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

Thanks, fixed in #10102


- **Cap’n Proto struct**: A structured data format used in Cap’n Proto, similar to structs in C++, for organizing and transporting data across different processes.

- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change
- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))
- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin Core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

nit

Thanks, fixed in #10102

@achow101
Copy link
Member

achow101 commented Jan 2, 2024

ACK 91dc48c

@achow101 achow101 merged commit d036a86 into bitcoin:master Jan 2, 2024
16 checks passed
@jamesob
Copy link
Member

jamesob commented Jan 5, 2024

Post-merge ACK. This doc is very helpful, thanks @ryanofsky!

ryanofsky added a commit to ryanofsky/bitcoin that referenced this pull request Jan 11, 2024
All suggested by stickies-v <stickies-v@protonmail.com>
bitcoin#28978 (review)

Co-authored-by: stickies-v <stickies-v@protonmail.com>
Copy link
Contributor Author

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

re: #28978 (review)

left a couple of improvements but agreed that iterating in future PRs is better.

Thanks for the close reading and suggestions. I implemented them for now in the combined PR #10102 commit ee4b913 and will split it out into another PR at some point.

- In the generated code, we have C++ client subclasses that inherit from the abstract classes in [`src/interfaces/`](../../src/interfaces/). These subclasses are the workhorses of the IPC mechanism.
- They implement all the methods of the interface, marshalling arguments into a structured format, sending them as requests to the IPC server via a UNIX socket, and handling the responses.
- These subclasses effectively mask the complexity of IPC, presenting a familiar C++ interface to developers.
- Internally, the client subclasses generated by the `mpgen` tool wrap [client classes generated by Cap'n Proto](https://capnproto.org/cxxrpc.html#clients), and use them to send IPC requests.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

Perhaps useful to elaborate on what the mpgen wrapping adds to the Cap'n Proto output?

Great suggestion, done in #10102. The main difference is mpgen clients subclasses have a high-level blocking interface, while capnp client subclasses require you to do asynchronous and pass arguments and return values in capnp message format.


An alternate approach could use custom [C++ Attributes](https://en.cppreference.com/w/cpp/language/attributes) embedded in interface declarations to automatically generate `.capnp` files from C++ headers. This has not been pursued because parsing C++ headers is more complicated than parsing Cap’n Proto interface definitions, especially portably on multiple platforms.

In the meantime, the developer guide [Internal interface guidelines](developer-notes.md#internal-interface-guidelines) can provide guidance on keeping interfaces consistent and functional and avoiding compile errors.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

dead link

Thanks, fixed in #10102

- Upon receiving the request, the Cap'n Proto dispatching code in the `bitcoin-node` process calls the `getBlockHash` method of the `Chain` [server class](#c-server-classes-in-generated-code).
- The server class is automatically generated by the `mpgen` tool from the [`chain.capnp`](https://github.com/ryanofsky/bitcoin/blob/pr/ipc/src/ipc/capnp/chain.capnp) file in [`src/ipc/capnp/`](../../src/ipc/capnp/).
- The `getBlockHash` method of the generated `Chain` server subclass in `bitcoin-wallet` receives a Cap’n Proto request object with the `height` parameter, and calls the `getBlockHash` method on its local `Chain` object with the provided `height`.
- When the call returns, it encapsulates the return value in a Cap’n Proto response, which it sends back to the `bitcoin-wallet` process,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

Thanks, fixed in #10102


- **Cap’n Proto struct**: A structured data format used in Cap’n Proto, similar to structs in C++, for organizing and transporting data across different processes.

- **client class (in generated code)**: A C++ class generated from a Cap’n Proto interface which inherits from a Bitcoin core abstract class, and implements each virtual method to send IPC requests to another process. (see also [components section](#c-client-subclasses-in-generated-code))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

nit

Thanks, fixed in #10102

```
cd <BITCOIN_SOURCE_DIRECTORY>
make -C depends NO_QT=1 MULTIPROCESS=1
CONFIG_SITE=$PWD/depends/x86_64-pc-linux-gnu/share/config.site ./configure
Copy link
Contributor Author

Choose a reason for hiding this comment

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

re: #28978 (comment)

nit: Perhaps useful to parameterize the host platform to highlight it's configurable? E.g.

Thanks I split it into a separate variable and clarified how it could be set in #10102.

willcl-ark pushed a commit to willcl-ark/bitcoin that referenced this pull request Apr 25, 2024
All suggested by stickies-v <stickies-v@protonmail.com>
bitcoin#28978 (review)

Co-authored-by: stickies-v <stickies-v@protonmail.com>
willcl-ark pushed a commit to willcl-ark/bitcoin that referenced this pull request May 1, 2024
All suggested by stickies-v <stickies-v@protonmail.com>
bitcoin#28978 (review)

Co-authored-by: stickies-v <stickies-v@protonmail.com>
willcl-ark pushed a commit to willcl-ark/bitcoin that referenced this pull request May 2, 2024
All suggested by stickies-v <stickies-v@protonmail.com>
bitcoin#28978 (review)

Co-authored-by: stickies-v <stickies-v@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants