AppLayerLabs / bdk-cpp

MIT License
6 stars 12 forks source link

Implement periodic saving for Storage and EventManager #27

Open jcarraror opened 1 year ago

jcarraror commented 1 year ago
Jean-Lessa commented 1 year ago

Branch 27-periodic-save (commit 99a6f35) contains a prototype for a possible implementation of Storage::periodicSaveToDB(). Heavy emphasis on prototype.

The thread is already set to start at the end of Storage's constructor and stop at the start of its destructor. It starts just fine and the cooldown is iterated upon as well (every 15 seconds), but for some reason I don't see the message about stopping the thread when I kill tmux. Unless I'm missing something here, that means the destructor is not being called at all, which also means the blockchain is never really being saved at all, independent of the periodic thread, and this actually concerns me since it practically means we have no idea if the destructor is actually working...? Either way, you can check this yourselves in debug.txt, filtering by "periodic".

Basic logic for the saving routine is as follows (subject to change, could use some input on the whole thing, including testing which was not done properly due to lack of feedback on how to properly test it):

How could this be properly tested? The routine only kicks in at 1000 blocks or 1M txs on cache (which is also weird because we should be checking the chain and I still don't get that, but I strictly followed the TODO instructions anyway), so we'd need to check the following steps: