Clean forked blocks from storage
Related to #1437
Currently when the chain reorganizes we do not discard the non-consolidated blocks, leading to a client ( and the wallet) being able to still query them
After PR #1663, this blocks are not marked as "confirmed", so a client is able to distinguish them, at least in theory.
However, these blocks are not needed anymore, so the node should delete them in order to save some space.
Possible implementation: we can detect when the node reverts, and delete the blocks and transactions from storage. We need to make sure that we don't accidentally delete valid blocks or valid transactions because of possible race conditions.
Another possible implementation is to add some worker that periodically checks the database for blocks that are not in the main chain and deletes them, but that sounds inefficient.
We should also clean the transactions from that block. But be careful, if the same transaction hash is also included in a later block, we must not delete it. In pseudocode:
for tx_hash in block:
tx_pointer = storage.get(tx_hash)
if tx_pointer.block_hash == block.hash():
storage.delete(tx_hash)