* Fix #2393

* check both

* Fix shortLog(int64)
This commit is contained in:
Mamy Ratsimbazafy 2021-03-10 16:53:42 +01:00 committed by GitHub
parent 33c7f264bc
commit f7cddcc8ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 11 deletions

View File

@ -337,8 +337,8 @@ proc pruneBlocks*(
proc pruneAttestations*( proc pruneAttestations*(
db: SlashingProtectionDB, db: SlashingProtectionDB,
validator: ValidatorPubkey, validator: ValidatorPubkey,
newMinSourceEpoch: Epoch, newMinSourceEpoch: int64,
newMinTargetEpoch: Epoch) = newMinTargetEpoch: int64) =
## Prune all blocks from a validator before the specified newMinSlot ## Prune all blocks from a validator before the specified newMinSlot
## This is intended for interchange import to ensure ## This is intended for interchange import to ensure
## that in case of a gap, we don't allow signing in that gap. ## that in case of a gap, we don't allow signing in that gap.

View File

@ -117,7 +117,7 @@ type
# Pruning # Pruning
# -------------------------------------------- # --------------------------------------------
db.pruneBlocks(ValidatorPubKey, Slot) db.pruneBlocks(ValidatorPubKey, Slot)
db.pruneAttestations(ValidatorPubKey, Epoch, Epoch) db.pruneAttestations(ValidatorPubKey, int64, int64)
db.pruneAfterFinalization(Epoch) db.pruneAfterFinalization(Epoch)
# Interchange # Interchange
@ -446,4 +446,8 @@ proc importInterchangeV5Impl*(
# Now prune everything that predates # Now prune everything that predates
# this interchange file max slot # 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)

View File

@ -955,16 +955,19 @@ proc pruneBlocks*(db: SlashingProtectionDB_v1, validator: ValidatorPubkey, newMi
proc pruneAttestations*( proc pruneAttestations*(
db: SlashingProtectionDB_v1, db: SlashingProtectionDB_v1,
validator: ValidatorPubkey, validator: ValidatorPubkey,
newMinSourceEpoch: Epoch, newMinSourceEpoch: int64,
newMinTargetEpoch: Epoch) = newMinTargetEpoch: int64) =
## Prune all blocks from a validator before the specified newMinSlot ## Prune all blocks from a validator before the specified newMinSlot
## This is intended for interchange import. ## This is intended for interchange import.
## ##
## Note: the Database v1 does not support pruning. ## 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.", warn "Slashing DB pruning is not supported on the v1 of our database. Request ignored.",
validator = shortLog(validator), validator = shortLog(validator),
newMinSourceEpoch = shortLog(newMinSourceEpoch), newMinSourceEpoch = newMinSourceEpoch,
newMinTargetEpoch = shortLog(newMinTargetEpoch) newMinTargetEpoch = newMinTargetEpoch
proc pruneAfterFinalization*( proc pruneAfterFinalization*(
db: SlashingProtectionDB_v1, db: SlashingProtectionDB_v1,

View File

@ -1020,14 +1020,16 @@ proc pruneBlocks*(db: SlashingProtectionDB_v2, validator: ValidatorPubkey, newMi
proc pruneAttestations*( proc pruneAttestations*(
db: SlashingProtectionDB_v2, db: SlashingProtectionDB_v2,
validator: ValidatorPubkey, validator: ValidatorPubkey,
newMinSourceEpoch: Epoch, newMinSourceEpoch: int64,
newMinTargetEpoch: Epoch) = newMinTargetEpoch: int64) =
## Prune all blocks from a validator before the specified newMinSlot ## Prune all blocks from a validator before the specified newMinSlot
## This is intended for interchange import. ## 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 valID = db.getOrRegisterValidator(validator)
let status = db.sqlPruneValidatorAttestations.exec( let status = db.sqlPruneValidatorAttestations.exec(
(valID, int64 newMinSourceEpoch, int64 newMinTargetEpoch)) (valID, newMinSourceEpoch, newMinTargetEpoch))
doAssert status.isOk(), doAssert status.isOk(),
"SQLite error when pruning validator attestations: " & $status.error & "\n" & "SQLite error when pruning validator attestations: " & $status.error & "\n" &
"for validator: 0x" & validator.toHex() & "for validator: 0x" & validator.toHex() &