ava-labs / firewood

Compaction-Less Database Optimized for Efficiently Storing Recent Merkleized Blockchain State
https://ava-labs.github.io/firewood/
Other
117 stars 10 forks source link

For NodeStoreHeader, use bytemuck not bincode #723

Closed rkuris closed 1 month ago

rkuris commented 1 month ago

Bytemuck will just write the bytes directly, not encode it. The header is pretty small and just contains contiguous bytes so we can take this shortcut. Added an endianness check and a version check to ensure that the database isn't opened on a machine with different endianness.

Note that it might have worked before, but probably was not tested. It is possible that you could create a migrator to fix the header and the database could be openable on a machine with different endianness...

Improves performance by about 3% for insert cases, and addresses a bug where the offset of the free list may not be as expected. This bug can only occur on a re-open of the database, as it incorrectly assumed the free lists are at offset_of!(header.freelists) when writing it.