RegisterValidationInterface()
takes a bare pointer, remembers it and other threads use it afterwards. This puts a burden on the caller to properly maintain the lifetime of the object which adds complexity and is a source of bugs (https://github.com/bitcoin/bitcoin/issues/25365, #26188 (review)).
shared_ptr
exists with the purpose of resolving that problem exactly. We already have RegisterSharedValidationInterface()
. I think it should be possible to replace all usages of RegisterValidationInterface()
with the “Shared” alternative. It is used in:
-
BaseIndex::Start()
passingthis
, is already suggested in #25365 (see last paragraph), #24230 “already does this”. -
AppInitMain()
passingg_zmq_notification_interface
which is a global raw ptr, can be changed to globalshared_ptr
. -
AppInitMain()
passingnode.peerman.get()
which isunique_ptr
. Extracting the raw pointer fromunique_ptr
, saving it somewhere else and using it from other threads defeats the purpose of usingunique_ptr
because we must now manually manage the lifetime of the object.NodeContext::peerman
should be changed fromunique_ptr
toshared_ptr
.
This should make it possible to remove RegisterValidationInterface()
and UnregisterValidationInterface()
(which is already deprecated).
Chasing concept ACK.