Skip to content

Commit

Permalink
Fix #2393 (#2395)
Browse files Browse the repository at this point in the history
* Fix #2393

* check both

* Fix shortLog(int64)
  • Loading branch information
mratsim authored Mar 10, 2021
1 parent 33c7f26 commit f7cddcc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions beacon_chain/validators/slashing_protection.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions beacon_chain/validators/slashing_protection_common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type
# Pruning
# --------------------------------------------
db.pruneBlocks(ValidatorPubKey, Slot)
db.pruneAttestations(ValidatorPubKey, Epoch, Epoch)
db.pruneAttestations(ValidatorPubKey, int64, int64)
db.pruneAfterFinalization(Epoch)

# Interchange
Expand Down Expand Up @@ -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)
11 changes: 7 additions & 4 deletions beacon_chain/validators/slashing_protection_v1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 5 additions & 3 deletions beacon_chain/validators/slashing_protection_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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() &
Expand Down

0 comments on commit f7cddcc

Please sign in to comment.