mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-20 05:14:35 +00:00
Implement slashing protection interchange format (#1544)
## Issue Addressed Implements support for importing and exporting the slashing protection DB interchange format described here: https://hackmd.io/@sproul/Bk0Y0qdGD Also closes #1584 ## Proposed Changes * [x] Support for serializing and deserializing the format * [x] Support for importing and exporting Lighthouse's database * [x] CLI commands to invoke import and export * [x] Export to minimal format (required when a minimal format has been previously imported) * [x] Tests for export to minimal (utilising mixed importing and attestation signing?) * [x] Tests for import/export of complete format, and import of minimal format * [x] ~~Prevent attestations with sources less than our max source (Danny's suggestion). Required for the fake attestation that we put in for the minimal format to block attestations from source 0.~~ * [x] Add the concept of a "low watermark" for compatibility with the minimal format Bonus! * [x] A fix to a potentially nasty bug involving validators getting re-registered each time the validator client ran! Thankfully, the ordering of keys meant that the validator IDs used for attestations and blocks remained stable -- otherwise we could have had some slashings on our hands! 😱 * [x] Tests to confirm that this bug is indeed vanquished
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
#![cfg(test)]
|
||||
|
||||
use crate::test_utils::*;
|
||||
use crate::*;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
fn double_register_validators() {
|
||||
let dir = tempdir().unwrap();
|
||||
let slashing_db_file = dir.path().join("slashing_protection.sqlite");
|
||||
let slashing_db = SlashingDatabase::create(&slashing_db_file).unwrap();
|
||||
|
||||
let num_validators = 100u32;
|
||||
let pubkeys = (0..num_validators as usize).map(pubkey).collect::<Vec<_>>();
|
||||
|
||||
let get_validator_ids = || {
|
||||
pubkeys
|
||||
.iter()
|
||||
.map(|pk| slashing_db.get_validator_id(pk).unwrap())
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
|
||||
assert_eq!(slashing_db.num_validator_rows().unwrap(), 0);
|
||||
|
||||
slashing_db.register_validators(pubkeys.iter()).unwrap();
|
||||
assert_eq!(slashing_db.num_validator_rows().unwrap(), num_validators);
|
||||
let validator_ids = get_validator_ids();
|
||||
|
||||
slashing_db.register_validators(pubkeys.iter()).unwrap();
|
||||
assert_eq!(slashing_db.num_validator_rows().unwrap(), num_validators);
|
||||
assert_eq!(validator_ids, get_validator_ids());
|
||||
}
|
||||
Reference in New Issue
Block a user