Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/blobstream): remove unnecessary code #2799

Merged
merged 2 commits into from
Nov 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions x/blobstream/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,16 @@ func pruneAttestations(ctx sdk.Context, k keeper.Keeper) {
if !k.CheckLatestAttestationNonce(ctx) {
return
}
earliestAttestation, found, err := k.GetAttestationByNonce(ctx, k.GetEarliestAvailableAttestationNonce(ctx))
if err != nil {
ctx.Logger().Error("error getting earliest attestation for pruning", "err", err.Error())
return
}
if !found {
if !k.CheckEarliestAvailableAttestationNonce(ctx) {
ctx.Logger().Error("couldn't find earliest attestation for pruning")
return
}
if earliestAttestation == nil {
ctx.Logger().Error("nil earliest attestation")
return
}

currentBlockTime := ctx.BlockTime()
latestAttestationNonce := k.GetLatestAttestationNonce(ctx)
earliestNonce := k.GetEarliestAvailableAttestationNonce(ctx)
var newEarliestAvailableNonce uint64
for newEarliestAvailableNonce = earliestAttestation.GetNonce(); newEarliestAvailableNonce < latestAttestationNonce; newEarliestAvailableNonce++ {
for newEarliestAvailableNonce = earliestNonce; newEarliestAvailableNonce < latestAttestationNonce; newEarliestAvailableNonce++ {
newEarliestAttestation, found, err := k.GetAttestationByNonce(ctx, newEarliestAvailableNonce)
if err != nil {
ctx.Logger().Error("error getting attestation for pruning", "nonce", newEarliestAvailableNonce, "err", err.Error())
Expand All @@ -181,13 +174,13 @@ func pruneAttestations(ctx sdk.Context, k keeper.Keeper) {
}
k.DeleteAttestation(ctx, newEarliestAvailableNonce)
}
if newEarliestAvailableNonce > earliestAttestation.GetNonce() {
if newEarliestAvailableNonce > earliestNonce {
// some attestations were pruned and we need to update the state for it
k.SetEarliestAvailableAttestationNonce(ctx, newEarliestAvailableNonce)
ctx.Logger().Debug(
"pruned attestations from Blobstream store",
"count",
newEarliestAvailableNonce-earliestAttestation.GetNonce(),
newEarliestAvailableNonce-earliestNonce,
"new_earliest_available_nonce",
newEarliestAvailableNonce,
"latest_attestation_nonce",
Expand Down
Loading