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

multiprocess compatibility updates #28721

Merged
merged 8 commits into from Nov 13, 2023
Merged

Conversation

ryanofsky
Copy link
Contributor

@ryanofsky ryanofsky commented Oct 24, 2023

This is a collection of small changes to interfaces and code which were needed as part of multiprocess PR #10102, but have been moved here to make that PR smaller.

All of these changes are refactoring changes which do not affect behavior of current code


This PR is part of the process separation project.

ryanofsky and others added 8 commits October 20, 2023 09:30
Needed to deserialize some types from spans like CScripts
…work across processes

Needed to fix new wallet_groups.py and wallet_resendwallettransactions.py tests
with multiprocess bitcoin-node executable.
… segfault

Coin serialize method segfaults if IsSpent condition is true. This caused
multiprocess code to segfault when serializing the Coin& output argument to of
the Node::getUnspentOutput method if the coin was not found. Segfault could be
triggered by double clicking and viewing transaction details in the GUI
transaction list.

Fix this by replacing Coin& output argument with optional<Coin> return value to
avoid trying to serializing spent coins.
Needed by multiprocess support code to pass parsed configuration to a spawned process.
Also add test to make sure this doesn't get broken in the future.

This was breaking vector<bool> serialization in multiprocess code because
template current deduction guides would make it appear like vector<bool> could
be converted to a span, but then the actual conversion to span would fail.
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 24, 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 achow101, naumenkogs, maflcko

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #10102 (Multiprocess bitcoin by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

I didn't review the Span commit yet.

ACK 28bddf9 🍍

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 28bddf90ccbb3a58d30210b6102220fa6253229f 🍍
5sCvwzO8Gj/WV/7QAif56fxTc3QT8+G/qXnBh/ZHH/rKxUb25SXW7I3/m26dnr0KfVVDVQGfar78kL1Yc4E5Dg==

{
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
pwallet->postInitProcess();
}

// Schedule periodic wallet flushes and tx rebroadcasts
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
scheduler.scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
context.scheduler->scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
Copy link
Member

Choose a reason for hiding this comment

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

nit in 62a0cea: Use 500ms while touching this?

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: #28721 (comment)

nit in 62a0cea: Use 500ms while touching this?

Thanks, updated

void flush() override { return FlushWallets(m_context); }
void stop() override { return StopWallets(m_context); }
void setMockTime(int64_t time) override { return SetMockTime(time); }
void schedulerMockForward(std::chrono::seconds delta) override { m_context.scheduler->MockForward(delta); }
Copy link
Member

Choose a reason for hiding this comment

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

nit in 62a0cea: Missing Assert() to turn UB into a crash?

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: #28721 (comment)

nit in 62a0cea: Missing Assert() to turn UB into a crash?

Thanks, updated

@@ -360,12 +360,11 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
{
COutPoint prevout = txin.prevout;

Coin prev;
if(node.getUnspentOutput(prevout, prev))
if (auto prev{node.getUnspentOutput(prevout)})
{
Copy link
Member

Choose a reason for hiding this comment

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

nit in 22edd79: Move to the above line while touching? (clang-format)

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: #28721 (comment)

nit in 22edd79: Move to the above line while touching? (clang-format)

Thanks, updated

{
{
strHTML += "<li>";
const CTxOut &vout = prev.out;
const CTxOut &vout = prev->out;
Copy link
Member

Choose a reason for hiding this comment

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

nit in 22edd79: Clang-format while touching this line?

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: #28721 (comment)

nit in 22edd79: Clang-format while touching this line?

Thanks, updated

// https://stackoverflow.com/questions/68759148/sfinae-to-detect-the-explicitness-of-a-ctad-deduction-guide
// https://stackoverflow.com/questions/16568986/what-happens-when-you-call-data-on-a-stdvectorbool
template<typename T>
using DataResult = std::remove_pointer_t<decltype(std::declval<T&>().data())>;
Copy link
Member

Choose a reason for hiding this comment

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

1fba885: I wonder if it is easier to just delete the content of this file and replace it with using Span = std::span?

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: #28721 (comment)

1fba885: I wonder if it is easier to just delete the content of this file and replace it with using Span = std::span?

Switching from Span to std::span might work, but it's a bigger change and I'd expect it to require other fixes and not just be a drop-in replacement.

If replacing span gets implemented and merged first, that's great and this commit can be dropped. But otherwise the actual code change here is small. I wouldn't want multiprocess code to depend on replacing span when there is a direct fix here which is 3 lines and is just adding two !std::is_void_v checks.

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.

Appreciate the review

Updated 28bddf9 -> 3b70f7b (pr/ipcfix.2 -> pr/ipcfix.3, compare) with review suggestions.

// https://stackoverflow.com/questions/68759148/sfinae-to-detect-the-explicitness-of-a-ctad-deduction-guide
// https://stackoverflow.com/questions/16568986/what-happens-when-you-call-data-on-a-stdvectorbool
template<typename T>
using DataResult = std::remove_pointer_t<decltype(std::declval<T&>().data())>;
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: #28721 (comment)

1fba885: I wonder if it is easier to just delete the content of this file and replace it with using Span = std::span?

Switching from Span to std::span might work, but it's a bigger change and I'd expect it to require other fixes and not just be a drop-in replacement.

If replacing span gets implemented and merged first, that's great and this commit can be dropped. But otherwise the actual code change here is small. I wouldn't want multiprocess code to depend on replacing span when there is a direct fix here which is 3 lines and is just adding two !std::is_void_v checks.

@@ -360,12 +360,11 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
{
COutPoint prevout = txin.prevout;

Coin prev;
if(node.getUnspentOutput(prevout, prev))
if (auto prev{node.getUnspentOutput(prevout)})
{
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: #28721 (comment)

nit in 22edd79: Move to the above line while touching? (clang-format)

Thanks, updated

{
{
strHTML += "<li>";
const CTxOut &vout = prev.out;
const CTxOut &vout = prev->out;
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: #28721 (comment)

nit in 22edd79: Clang-format while touching this line?

Thanks, updated

void flush() override { return FlushWallets(m_context); }
void stop() override { return StopWallets(m_context); }
void setMockTime(int64_t time) override { return SetMockTime(time); }
void schedulerMockForward(std::chrono::seconds delta) override { m_context.scheduler->MockForward(delta); }
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: #28721 (comment)

nit in 62a0cea: Missing Assert() to turn UB into a crash?

Thanks, updated

{
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
pwallet->postInitProcess();
}

// Schedule periodic wallet flushes and tx rebroadcasts
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
scheduler.scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
context.scheduler->scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
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: #28721 (comment)

nit in 62a0cea: Use 500ms while touching this?

Thanks, updated

@achow101 achow101 requested a review from maflcko November 7, 2023 21:09
@achow101
Copy link
Member

achow101 commented Nov 7, 2023

ACK 3b70f7b

1 similar comment
@naumenkogs
Copy link
Member

ACK 3b70f7b

@maflcko
Copy link
Member

maflcko commented Nov 9, 2023

re-ACK 3b70f7b 🎆

Show signature

Signature:

untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: re-ACK 3b70f7b6156cb110c47a6e482791cf337bb6ad6d  🎆
4vrBaTA+bS9c7lucywAakQWMvizh66HrffzpcXOPgLDVDBI4wkCQUPE94XqhE6S6GuepGDGFjHp5tecIYIoABA==

@DrahtBot DrahtBot removed the request for review from maflcko November 9, 2023 18:51
@fanquake fanquake merged commit 29c2c90 into bitcoin:master Nov 13, 2023
16 checks passed
@ryanofsky
Copy link
Contributor Author

Thanks for the reviews! I'll rebase #10102 now that this is merged, and create a new PR with the next set of changes from #10102

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

Successfully merging this pull request may close these issues.

None yet

6 participants