@@ -45,23 +45,15 @@ export chronicles
4545
4646type
4747 SlashProtDBMode * = enum
48- kCompleteArchiveV1 # Complete Format V1 backend (saves all attestations)
49- kCompleteArchiveV2 # Complete Format V2 backend (saves all attestations)
50- kLowWatermarkV2 # Low-Watermark Format V2 backend (prunes attestations)
48+ kCompleteArchive # Complete Format V2 backend (saves all attestations)
49+ kLowWatermark # Low-Watermark Format V2 backend (prunes attestations)
5150
5251 SlashingProtectionDB * = ref object
5352 # # Database storing the blocks attested
5453 # # by validators attached to a beacon node
5554 # # or validator client.
5655 db_v2* : SlashingProtectionDB_v2
5756 modes: set [SlashProtDBMode ]
58- disagreementBehavior: DisagreementBehavior
59-
60- DisagreementBehavior * = enum
61- # # How to handle disagreement between DB versions
62- kCrash
63- kChooseV1
64- kChooseV2
6557
6658# DB Multiversioning
6759# -------------------------------------------------------------
@@ -78,20 +70,18 @@ proc init*(
7870 genesis_validators_root: Eth2Digest ,
7971 basePath, dbname: string ,
8072 modes: set [SlashProtDBMode ],
81- disagreementBehavior: DisagreementBehavior
8273 ): T =
8374 # # Initialize or load a slashing protection DB
8475 # # This is for Beacon Node usage
8576 # # Handles DB version migration
8677
8778 doAssert modes.card >= 1 , " No slashing protection mode chosen. Choose a v1, a v2 or v1 and v2 slashing DB mode."
8879 doAssert not (
89- kCompleteArchiveV2 in modes and
90- kLowWatermarkV2 in modes), " Mode(s): " & $ modes & " . Choose only one of V2 DB modes."
80+ kCompleteArchive in modes and
81+ kLowWatermark in modes), " Mode(s): " & $ modes & " . Choose only one of V2 DB modes."
9182
9283 new result
9384 result .modes = modes
94- result .disagreementBehavior = disagreementBehavior
9585
9686 let (db, requiresMigration) = SlashingProtectionDB_v2.initCompatV1 (
9787 genesis_validators_root,
@@ -142,8 +132,7 @@ proc init*(
142132 # # Does not handle migration
143133 init (
144134 T, genesis_validators_root, basePath, dbname,
145- modes = {kLowWatermarkV2},
146- disagreementBehavior = kChooseV2
135+ modes = {kLowWatermark}
147136 )
148137
149138proc loadUnchecked * (
@@ -158,15 +147,15 @@ proc loadUnchecked*(
158147 new result
159148
160149 result .modes = {}
161- result .disagreementBehavior = kCrash
162150
163151 try :
164152 result .db_v2 = SlashingProtectionDB_v2.loadUnchecked (
165153 basePath, dbname, readOnly
166154 )
167- result .modes.incl (kCompleteArchiveV2)
168- except :
169- result .disagreementBehavior = kChooseV1
155+ result .modes.incl (kCompleteArchive)
156+ except CatchableError as err:
157+ error " Failed to load the Slashing protection database" , err = err.msg
158+ quit 1
170159
171160proc close * (db: SlashingProtectionDB ) =
172161 # # Close a slashing protection database
@@ -280,10 +269,10 @@ proc pruneAfterFinalization*(
280269 # # This ensures that even if pruning is called with an incorrect epoch
281270 # # slashing protection can fallback to the minimal / high-watermark protection mode.
282271 # #
283- # # Pruning is only done if pruning is enabled (DB in kLowWatermarkV2 mode)
272+ # # Pruning is only done if pruning is enabled (DB in kLowWatermark mode)
284273 # # Pruning is only triggered on v2 database.
285274
286- if kLowWatermarkV2 in db.modes:
275+ if kLowWatermark in db.modes:
287276 db.db_v2.pruneAfterFinalization (finalizedEpoch)
288277
289278# The high-level import/export functions are
@@ -305,7 +294,7 @@ proc toSPDIR*(db: SlashingProtectionDB): SPDIR
305294proc exportSlashingInterchange * (
306295 db: SlashingProtectionDB ,
307296 path: string ,
308- validatorsWhiteList: seq [string ] = @ [],
297+ validatorsWhiteList: seq [PubKey0x ] = @ [],
309298 prettify = true ) {.raises : [Defect , IOError ].} =
310299 # # Export a database to the Slashing Protection Database Interchange Format
311300 # We could modify toSPDIR to do the filtering directly
@@ -317,7 +306,14 @@ proc exportSlashingInterchange*(
317306 # O(a log b) with b the number of validators to keep
318307 # and a the total number of validators in DB
319308 let validators = validatorsWhiteList.sorted ()
320- spdir.data.keepItIf (validators.binarySearch (" 0x" & it.pubkey.PubKeyBytes .toHex ()) != - 1 )
309+ spdir.data.keepItIf (validators.binarySearch (it.pubkey) != - 1 )
310+
311+ if spdir.data.len != validatorsWhiteList.len:
312+ let exportedKeys = spdir.data.mapIt (it.pubkey).sorted ()
313+ for v in validators:
314+ if exportedKeys.binarySearch (v) == - 1 :
315+ warn " Specified validator key not found in the slashing database" ,
316+ key = v.PubKeyBytes .toHex
321317
322318 Json .saveFile (path, spdir, prettify)
323319 echo " Exported slashing protection DB to '" , path, " '"
0 commit comments