refactor: route wallet mempool/block notifications through CMainSignals#3079
Open
PrestackI wants to merge 2 commits into
Open
refactor: route wallet mempool/block notifications through CMainSignals#3079PrestackI wants to merge 2 commits into
PrestackI wants to merge 2 commits into
Conversation
First step of issue gridcoin-community#3030 workstream B. Introduces a Bitcoin-Core-style validation-signal layer so that subscribers (the wallet in B2, the GUI and a future PeerManager later) can decouple from core block/tx processing. New src/validationinterface.{h,cpp}: - CValidationInterface, an abstract subscriber with the trimmed callback set UpdatedBlockTip / TransactionAddedToMempool / TransactionRemovedFromMempool / BlockConnected / BlockDisconnected. Method names follow the repo's modern convention (UpperCamelCase per doc/developer-notes.md); the parameter types match the wallet's existing callbacks so B2 can subscribe with minimal churn. - CMainSignals + GetMainSignals(), with RegisterValidationInterface / UnregisterValidationInterface, register/unregister of a background CScheduler, and FlushBackgroundCallbacks. Subscribers are tracked with boost::signals2 scoped connections (mirroring the existing ui_interface). Emission is SYNCHRONOUS for now: signals fire on the thread that triggered the event, preserving the canonical cs_main -> signals -> cs_wallet lock order and the EXCLUSIVE_LOCKS_REQUIRED(cs_main) contract of the wallet callbacks. The g_scheduler-backed SingleThreadedSchedulerClient is wired for CallFunctionInValidationInterfaceQueue and a future async migration. init.cpp: resolves the long-standing TODO by calling GetMainSignals().RegisterBackgroundSignalScheduler(*g_scheduler) once the scheduler thread is up, and flushes + unregisters it at shutdown after the scheduler thread is joined. Registered validationinterface.cpp in src/CMakeLists.txt (gridcoin_util). Pure additive scaffolding -- nothing emits or subscribes yet (that is B2), so there is no behavior change.
Second step of issue gridcoin-community#3030 workstream B. Makes CWallet a CValidationInterface subscriber and routes the validation/mempool notifications through the signal layer added in the previous commit, instead of the validation code iterating setpwalletRegistered directly. - CWallet now derives from CValidationInterface; its four callbacks are renamed to the UpperCamelCase virtuals they override (TransactionAddedToMempool, BlockConnected, TransactionRemovedFromMempool, BlockDisconnected) per doc/developer-notes.md. Bodies and lock annotations are unchanged. - The three active call sites now emit through GetMainSignals(): AcceptToMemoryPool -> TransactionAddedToMempool (main.cpp), ConnectBlock -> BlockConnected, DisconnectBlock -> BlockDisconnected (validation.cpp). Emission is synchronous under cs_main, so the canonical cs_main -> signals -> cs_wallet order and the wallet callbacks' EXCLUSIVE_LOCKS_REQUIRED(cs_main) contract are preserved. - init.cpp registers pwalletMain via RegisterValidationInterface once the background signal scheduler is wired, and unregisters it at shutdown. Scope note: setpwalletRegistered is intentionally retained. Its remaining wrappers (SetBestChain, EraseFromWallets, UpdatedTransaction, ResendWalletTransactions, Inventory/relay in net_processing, RPC) are not validation-interface callbacks; fully retiring setpwalletRegistered is a larger, separate cleanup. The wallet therefore stays registered in both mechanisms during the transition. No behavior change: the same callbacks fire on the same thread under the same locks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes
CWalletaCValidationInterfacesubscriber and routes the validation/mempoolnotifications through the signal layer (#3078) instead of the validation code iterating
setpwalletRegistereddirectly.CWallet : public CValidationInterface; its four callbacks renamed to theUpperCamelCase virtuals they override (
TransactionAddedToMempool,BlockConnected,TransactionRemovedFromMempool,BlockDisconnected). Bodies/lock annotations unchanged.GetMainSignals():AcceptToMemoryPool(main.cpp),
ConnectBlock/DisconnectBlock(validation.cpp). Synchronous emissionunder
cs_mainpreservescs_main → signals → cs_wallet.init.cppregisterspwalletMainonce the signal scheduler is wired, unregisters atshutdown.
Why
Second step of issue #3030 workstream B. Stacked on #3078 — until that merges, the
diff here also includes its commits.
Scope note
setpwalletRegisteredis intentionally retained: its remaining wrappers (SetBestChain,EraseFromWallets,UpdatedTransaction,ResendWalletTransactions, plus net_processingrelay and RPC) are not validation-interface callbacks, so fully retiring it is a larger,
separate cleanup. The wallet is registered in both mechanisms during the transition. No
behavior change — same callbacks fire on the same thread under the same locks.
Testing
Full CI matrix green on the source branch (incl. Clang thread-safety, which validates the
EXCLUSIVE_LOCKS_REQUIRED(cs_main)overrides).