Skip to content

Commit

Permalink
chore: update skyway validator nonces (#1288)
Browse files Browse the repository at this point in the history
# Related Github tickets

- VolumeFi#2159

# Background

When a claim is set to observed, update all validator nonces if they
have a lower last observed nonce.

NOTE: This only takes effect when a claim is successfully attested to.
The validators currently stuck will remain on their current nonces until
a claim is processed. To get them unstuck, we need
VolumeFi#2160

# Testing completed

- [ ] test coverage exists or has been added/updated
- [x] tested in a private testnet

# Breaking changes

- [x] I have checked my code for breaking changes
- [x] If there are breaking changes, there is a supporting migration.
  • Loading branch information
maharifu authored Sep 11, 2024
1 parent 1f93b67 commit ef64f7a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions x/skyway/keeper/attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ func (k Keeper) TryAttestation(ctx context.Context, att *types.Attestation) erro
return err
}

// Update all validator nonces to the claim nonce that was just
// processed
err = k.updateValidatorNoncesIfHigher(ctx, claim.GetChainReferenceId(), claim.GetSkywayNonce())
if err != nil {
return err
}

break
}
}
Expand Down
28 changes: 28 additions & 0 deletions x/skyway/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,3 +480,31 @@ func (k Keeper) overrideNonce(ctx context.Context, chainReferenceId string, nonc
logger.Info("Updated last observed nonce successfully")
return nil
}

// updateValidatorNoncesIfHigher updates all validator nonces to `newNonce` only
// if it is higher than the current record
func (k Keeper) updateValidatorNoncesIfHigher(
ctx context.Context,
chainReferenceId string,
newNonce uint64,
) error {
logger := liblog.FromKeeper(ctx, k).WithComponent("update-validator-nonces-if-higher")

store := k.GetStore(ctx, chainReferenceId)
prefixStore := prefix.NewStore(store, types.LastEventNonceByValidatorKey)

err := k.IterateValidatorLastEventNonces(ctx, chainReferenceId, func(key []byte, nonce uint64) bool {
if newNonce > nonce {
prefixStore.Set(key, types.UInt64Bytes(newNonce))
}

return false
})
if err != nil {
logger.WithError(err).Warn("Failed to update validator skyway nonces")
return err
}

logger.Info("Updated validator nonces to highest successfully")
return nil
}

0 comments on commit ef64f7a

Please sign in to comment.