lighthouse icon indicating copy to clipboard operation
lighthouse copied to clipboard

Modularise slasher backend

Open michaelsproul opened this issue 3 years ago • 1 comments

Proposed Changes

Enable multiple database backends for the slasher, either MDBX (default) or LMDB. The backend can be selected using --slasher-backend={lmdb,mdbx}.

Additional Info

In order to abstract over the two library's different handling of database lifetimes I've used Box::leak to give the Environment type a 'static lifetime. This was the only way I could think of using 100% safe code to construct a self-referential struct SlasherDB, where the OpenDatabases refers to the Environment. I think this is OK, as the Environment is expected to live for the life of the program, and both database engines leave the database in a consistent state after each write. The memory claimed for memory-mapping will be freed by the OS and appropriately flushed regardless of whether the Environement is actually dropped.

We are depending on two sigp forks of libmdbx-rs and lmdb-rs, to give us greater control over MDBX OS support and LMDB's version.

michaelsproul avatar Aug 09 '22 03:08 michaelsproul

TODO

  • [x] Re-open https://github.com/sigp/lighthouse/issues/2342, which still isn't fixed in an LMDB release.
  • [x] Run slasher tests with LMDB on CI

michaelsproul avatar Aug 09 '22 07:08 michaelsproul

I've marked this ready for review. I haven't updated the LMDB version because I don't have time to test on Windows right now. I figure we can come back for that in a subsequent update. Windows users can use MDBX in the meantime.

michaelsproul avatar Aug 11 '22 00:08 michaelsproul

I've been running both backends on mainnet for 5 days (since Aug 10 00:00 UTC) and the current stats are as follows:

  • MDBX
    • Database size: 22 GiB
    • Current time per batch: 1.3s
  • LMDB
    • Database size: 27 GiB
    • Current time per batch: 1.2s

So LMDB is definitely still viable (and even a bit faster!). At this rate MDBX will use around 80 GiB for the full history of 4096 epochs and LMDB will use 100 GiB, around 25% more. The real test will begin once both DBs have surpassed 4096 epochs of history and MDBX's superior pruning kicks in.

michaelsproul avatar Aug 15 '22 01:08 michaelsproul

Pentasquerge! :rocket: :rocket: :rocket: :rocket: :rocket:

bors r+

paulhauner avatar Aug 15 '22 01:08 paulhauner