Juanan7676 / netcoin

A cryptocurrency written in lua for Minecraft mod OpenComputers.
10 stars 6 forks source link

Out of memory error when downloading a large blockchain for the first time #5

Open Juanan7676 opened 2 years ago

Juanan7676 commented 2 years ago

Context: Right now, when the client downloads a block which contains a "previous" block that is not known by the client, it keeps requesting them until he finds a block he knows, or he arrives to the genesis block. All these blocks are stored in a table in-memory, and the UTXO list is reconstructed using this table.

The problem: For very large blockchains, the size of this table will exceed the computer RAM and the program will crash.

Proposed solution: A solution is to store the blocks on disk and access them using the usual methods on storage.lua. We only keep the uuids of the blocks to verify on the in-memory table (Will this solve the memory problem...?). If something goes wrong, then using the storage.deleteBlock(uuid) function we can clear the blocks and discard the UTXO we have calculated until that moment.