Modularise slasher backend
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.
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
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.
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.
Pentasquerge! :rocket: :rocket: :rocket: :rocket: :rocket:
bors r+
Pull request successfully merged into unstable.
Build succeeded:
- arbitrary-check
- beacon-chain-tests
- cargo-audit
- cargo-fmt
- cargo-udeps
- cargo-vendor
- check-benchmarks
- check-consensus
- check-msrv
- clippy
- debug-tests-ubuntu
- dockerfile-ubuntu
- doppelganger-protection-test
- ef-tests-ubuntu
- eth1-simulator-ubuntu
- execution-engine-integration-ubuntu
- merge-transition-ubuntu
- no-eth1-simulator-ubuntu
- op-pool-tests
- release-tests-ubuntu
- release-tests-windows
- state-transition-vectors-ubuntu