Closed heifner closed 8 months ago
Need to provide a wrapper around the two fork databases that is thread safe and can provide the interfaces needed by API calls, net_plugin, and controller.
Is it really necessary? I would not have thought so because:
fork_db<legacy>
-> fork_db<new>
while net_plugin and APIs still access fork_db<legacy>
, and then we have to make an atomic switch where maybe we freeze net_plugin
(maybe the same way as when we take a snapshot)?Oh wait, because there is a mutex in fork_db I think we might be fine without the wrapper. What about:
shared_ptr
to fork_db in controller (instead of the struct itself).fork_db<legacy>
fork_db<legacy>
-> fork_db<new>
, but keep a shared_ptr to fork_db<legacy>
so it stays alive. update controller to point to fork_db<new>
.fork_db<legacy>
. net_plugin and APIs would finish their work using the old fork_db, but that should be fine.That doesn't work without an atomic shared ptr. Boost has an atomic shared ptr we could use for this.
Without atomic shared ptr:
Net thread begins access of control->shared_ptr->fork_dbfork_db<legacy>
, does not stop net thread from accessing shared_ptr.
Main thread modifies shared_ptr while net thread is accessing it (not safe).
Resolved by #2113
Currently
fork_database
is thread safe via internal mutex. During the transition of dpos fork database to instant finality fork database threads from API calls andnet_plugin
can be running. Need to provide a wrapper around the two fork databases that is thread safe and can provide the interfaces needed by API calls,net_plugin
, and controller.Also handle
[greg todo]
leftover from https://github.com/AntelopeIO/leap/issues/1941 & #2045 in leap-util blocklog. Thefork_database
wrapper can examine file to determine which internal implementation is in use.