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

kernel: Remove dependency on CScheduler #28960

Merged
merged 7 commits into from Mar 9, 2024

Conversation

TheCharlatan
Copy link
Contributor

@TheCharlatan TheCharlatan commented Nov 28, 2023

By defining a virtual interface class for the scheduler client, users of the kernel can now define their own event consuming infrastructure, without having to spawn threads or rely on the scheduler design.

Removing CScheduler also allows removing the thread and exception modules from the kernel library.

To make the CMainSignals class easier to use from a kernel library perspective, remove its global instantiation and adopt RAII practices.

Renames CMainSignals to ValidationSignals, which more accurately describes its purpose and scope.

Also make the ValidationSignals in the ChainstateManager and CTxMemPool` optional. This could be useful in the future for using or testing these classes without having to instantiate any form of signal handling.


This PR is part of the libbitcoinkernel project. It improves the kernel API and removes two modules from the kernel library.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 28, 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 ryanofsky, vasild, furszy, maflcko
Concept ACK dergoegge, darosior
Stale ACK jamesob

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:

  • #29538 (refactor: Improve naming of CBlock::GetHash() -> GetHeaderHash() by fjahr)
  • #29415 (Broadcast own transactions only via short-lived Tor or I2P connections by vasild)
  • #29278 (Wallet: Add maxfeerate wallet startup option by ismaelsadeeq)
  • #29242 (Mempool util: Add RBF diagram checks for single chunks against clusters of size 2 by instagibbs)
  • #29236 (log: Nuke error(...) by maflcko)
  • #29015 (kernel: Streamline util library by ryanofsky)
  • #28984 (Cluster size 2 package rbf by instagibbs)
  • #28830 ([refactor] Check CTxMemPool options in ctor by TheCharlatan)
  • #28676 ([WIP] Cluster mempool implementation by sdaftuar)
  • #28608 (assumeutxo state and locking cleanup by ryanofsky)
  • #28228 (kernel: Run sanity checks on context construction by TheCharlatan)
  • #28031 (Package Relay 1/3: Introduce TxDownloadManager and improve orphan-handling by glozow)
  • #27277 (Move log messages: tx enqueue to mempool, allocation to blockstorage by Sjors)

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.

@dergoegge
Copy link
Member

Concept ACK

src/bitcoin-chainstate.cpp Outdated Show resolved Hide resolved
@TheCharlatan TheCharlatan marked this pull request as ready for review December 2, 2023 22:12
TheCharlatan and others added 3 commits February 15, 2024 14:43
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | (grep -v "$3" || cat;) | xargs sed -i "s/$1/$2/g"; }

s 'SingleThreadedSchedulerClient'   'SerialTaskRunner'  ''
s 'SinglethreadedSchedulerClient'   'SerialTaskRunner'  ''
s 'm_schedulerClient'               'm_task_runner'     ''
s 'AddToProcessQueue'               'insert'            ''
s 'EmptyQueue'                      'flush'             ''
s 'CallbacksPending'                'size'              'validation'
sed -i '109s/CallbacksPending/size/' src/validationinterface.cpp
-END VERIFY SCRIPT-

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src | xargs sed -i "s/$1/$2/g"; }

s 'CMainSignals'    'ValidationSignals'
s 'MainSignalsImpl' 'ValidationSignalsImpl'
-END VERIFY SCRIPT-
@TheCharlatan
Copy link
Contributor Author

Thank you for the review @vasild,

Updated c02fd03 -> 4e270f3 (noGlobalSignals_15 -> noGlobalSignals_16, compare)

  • Addressed @vasild's comment, added const qualifier to m_signals pointer in CTxMemPool.

  • Addressed @vasild's comment, fixed naming in commit message.

  • Addressed @vasild's comment, added uint256::Zero as argument to waitForNotificationsIfTipChanged call.

  • Addressed @vasild's comment, rewording docstring for TaskRunnerInterface's insert method.

  • Addressed @vasild's comment, added @file qualifier to docstring for task_runner.h file.

  • Addressed @vasild's comment, removed unneeded return statement.

  • Addressed @vasild's comment, fixed re-naming issue in comment describing m_task_runner.

  • Added validation_signals helper in node/interfaces instead of reaching into a ChainstateManager member for accessing the ValidationSignals.

@TheCharlatan
Copy link
Contributor Author

Updated 4e270f3 -> 7593105 (noGlobalSignals_16 -> noGlobalSignals_17, compare)

  • Addressed @ryanofsky's comment, reverted previous comment change and instead moved the comment to describe m_callbacks_pending.

src/util/task_runner.h Outdated Show resolved Hide resolved
@TheCharlatan
Copy link
Contributor Author

Updated 7593105 -> 316c7c8 (noGlobalSignals_17 -> noGlobalSignals_18, compare)

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

ACK 316c7c8

src/util/task_runner.h Outdated Show resolved Hide resolved
"wallet_tests/importwallet_rescan" # validation.cpp: if (signals.CallbacksPending() > 10)
"wallet_tests/ListCoins" # validation.cpp: if (signals.CallbacksPending() > 10)
"wallet_tests/scan_for_wallet_transactions" # validation.cpp: if (signals.CallbacksPending() > 10)
"wallet_tests/wallet_disableprivkeys" # validation.cpp: if (signals.CallbacksPending() > 10)
Copy link
Member

Choose a reason for hiding this comment

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

Would be a nice follow-up to remove the non-deterministic scheduler from all tests, unless they are explicitly testing the scheduler.

cc @aureleoules , who was asking for a solution to this for the corecheck infra

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.

ACK 316c7c8 🔁

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 316c7c845036cbffa22b9e44f31dca8573ffb639 🔁
1vioJirfjv5T1d+KJlrtR+Bw8ftU7msPN3OGieSZu7FZDuBMu3u642FgGntJXux25f1uaFTvhCgjKjKJDYshCw==

src/util/task_runner.h Outdated Show resolved Hide resolved
By defining a virtual interface class for the scheduler client, users of
the kernel can now define their own event consuming infrastructure,
without having to spawn threads or rely on the scheduler design.

Removing CScheduler also allows removing the thread and
exception modules from the kernel library.
@TheCharlatan
Copy link
Contributor Author

Thank you for the comments,

Updated 316c7c8 -> d5228ef (noGlobalSignals_18 -> noGlobalSignals_19, compare)

Copy link
Contributor

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

Code review ACK d5228ef. Just comment change since last review.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK d5228ef

I would be happy to re-review if this is changed to use automatic memory management everywhere (#28960 (comment) and #28960 (comment)). Or at least add a comment next to the raw pointers/references like "this points to NodeContext::validation_signals and should not be used after that is destroyed".

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

diff ACK d5228ef

src/util/task_runner.h Outdated Show resolved Hide resolved
@maflcko
Copy link
Member

maflcko commented Feb 17, 2024

re-ACK d5228ef 🌄

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 d5228efb5391b31a9a0673019e43e7fa2cd4ac07 🌄
elAYAr1e+Thfz4bnEGxUZsIrgO73g1NOYOeuWO1064mJWFsjMzzTtufbMX7XQAPS5SAAfAflraHLO49Zr9MCBg==

@DrahtBot DrahtBot removed the request for review from maflcko February 17, 2024 11:46
@maflcko maflcko added this to the 28.0 milestone Feb 22, 2024
@maflcko
Copy link
Member

maflcko commented Feb 22, 2024

Added to 28.0, since it looks rfm, but is probably waiting on the branch-off?

@achow101 achow101 merged commit c07935b into bitcoin:master Mar 9, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done or Closed or Rethinking
Development

Successfully merging this pull request may close these issues.

None yet