diff --git a/beacon_chain/validators/slashing_protection.nim b/beacon_chain/validators/slashing_protection.nim index 43b58e3e8..0a6153eda 100644 --- a/beacon_chain/validators/slashing_protection.nim +++ b/beacon_chain/validators/slashing_protection.nim @@ -337,8 +337,8 @@ proc pruneBlocks*( proc pruneAttestations*( db: SlashingProtectionDB, validator: ValidatorPubkey, - newMinSourceEpoch: Epoch, - newMinTargetEpoch: Epoch) = + newMinSourceEpoch: int64, + newMinTargetEpoch: int64) = ## Prune all blocks from a validator before the specified newMinSlot ## This is intended for interchange import to ensure ## that in case of a gap, we don't allow signing in that gap. diff --git a/beacon_chain/validators/slashing_protection_common.nim b/beacon_chain/validators/slashing_protection_common.nim index 387e13252..3f3d25558 100644 --- a/beacon_chain/validators/slashing_protection_common.nim +++ b/beacon_chain/validators/slashing_protection_common.nim @@ -117,7 +117,7 @@ type # Pruning # -------------------------------------------- db.pruneBlocks(ValidatorPubKey, Slot) - db.pruneAttestations(ValidatorPubKey, Epoch, Epoch) + db.pruneAttestations(ValidatorPubKey, int64, int64) db.pruneAfterFinalization(Epoch) # Interchange @@ -446,4 +446,8 @@ proc importInterchangeV5Impl*( # Now prune everything that predates # this interchange file max slot - db.pruneAttestations(parsedKey, Epoch maxValidSourceEpochSeen, Epoch maxValidTargetEpochSeen) + if maxValidSourceEpochSeen < 0 or maxValidTargetEpochSeen < 0: + doAssert maxValidSourceEpochSeen == -1 and maxValidTargetEpochSeen == -1 + notice "No attestation found in slashing interchange file" + return + db.pruneAttestations(parsedKey, maxValidSourceEpochSeen, maxValidTargetEpochSeen) diff --git a/beacon_chain/validators/slashing_protection_v1.nim b/beacon_chain/validators/slashing_protection_v1.nim index 920ee909c..d35987d79 100644 --- a/beacon_chain/validators/slashing_protection_v1.nim +++ b/beacon_chain/validators/slashing_protection_v1.nim @@ -955,16 +955,19 @@ proc pruneBlocks*(db: SlashingProtectionDB_v1, validator: ValidatorPubkey, newMi proc pruneAttestations*( db: SlashingProtectionDB_v1, validator: ValidatorPubkey, - newMinSourceEpoch: Epoch, - newMinTargetEpoch: Epoch) = + newMinSourceEpoch: int64, + newMinTargetEpoch: int64) = ## Prune all blocks from a validator before the specified newMinSlot ## This is intended for interchange import. ## ## Note: the Database v1 does not support pruning. + ## + ## Negative source/target epoch of -1 can be received if no attestation was imported + ## In that case nothing is done warn "Slashing DB pruning is not supported on the v1 of our database. Request ignored.", validator = shortLog(validator), - newMinSourceEpoch = shortLog(newMinSourceEpoch), - newMinTargetEpoch = shortLog(newMinTargetEpoch) + newMinSourceEpoch = newMinSourceEpoch, + newMinTargetEpoch = newMinTargetEpoch proc pruneAfterFinalization*( db: SlashingProtectionDB_v1, diff --git a/beacon_chain/validators/slashing_protection_v2.nim b/beacon_chain/validators/slashing_protection_v2.nim index 9d3337a7c..337523a6f 100644 --- a/beacon_chain/validators/slashing_protection_v2.nim +++ b/beacon_chain/validators/slashing_protection_v2.nim @@ -1020,14 +1020,16 @@ proc pruneBlocks*(db: SlashingProtectionDB_v2, validator: ValidatorPubkey, newMi proc pruneAttestations*( db: SlashingProtectionDB_v2, validator: ValidatorPubkey, - newMinSourceEpoch: Epoch, - newMinTargetEpoch: Epoch) = + newMinSourceEpoch: int64, + newMinTargetEpoch: int64) = ## Prune all blocks from a validator before the specified newMinSlot ## This is intended for interchange import. + ## Negative source/target epoch of -1 can be received if no attestation was imported + ## In that case nothing is done (since we used signed int in SQLite) let valID = db.getOrRegisterValidator(validator) let status = db.sqlPruneValidatorAttestations.exec( - (valID, int64 newMinSourceEpoch, int64 newMinTargetEpoch)) + (valID, newMinSourceEpoch, newMinTargetEpoch)) doAssert status.isOk(), "SQLite error when pruning validator attestations: " & $status.error & "\n" & "for validator: 0x" & validator.toHex() &