Skip to content

refactor: route wallet mempool/block notifications through CMainSignals#3079

Open
PrestackI wants to merge 2 commits into
gridcoin-community:developmentfrom
PrestackI:wallet/validationinterface-subscriber
Open

refactor: route wallet mempool/block notifications through CMainSignals#3079
PrestackI wants to merge 2 commits into
gridcoin-community:developmentfrom
PrestackI:wallet/validationinterface-subscriber

Conversation

@PrestackI

Copy link
Copy Markdown
Contributor

What

Makes CWallet a CValidationInterface subscriber and routes the validation/mempool
notifications through the signal layer (#3078) instead of the validation code iterating
setpwalletRegistered directly.

  • CWallet : public CValidationInterface; its four callbacks renamed to the
    UpperCamelCase virtuals they override (TransactionAddedToMempool, BlockConnected,
    TransactionRemovedFromMempool, BlockDisconnected). Bodies/lock annotations unchanged.
  • The three active call sites now emit via GetMainSignals(): AcceptToMemoryPool
    (main.cpp), ConnectBlock / DisconnectBlock (validation.cpp). Synchronous emission
    under cs_main preserves cs_main → signals → cs_wallet.
  • init.cpp registers pwalletMain once the signal scheduler is wired, unregisters at
    shutdown.

Why

Second step of issue #3030 workstream B. Stacked on #3078 — until that merges, the
diff here also includes its commits.

Scope note

setpwalletRegistered is intentionally retained: its remaining wrappers (SetBestChain,
EraseFromWallets, UpdatedTransaction, ResendWalletTransactions, plus net_processing
relay 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).

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

1 participant