Skip to content

Commit

Permalink
made it so that it always returned an event when cyclelist is rotated (
Browse files Browse the repository at this point in the history
…#442) (#446)

* made it so that it always returned an event when cyclelist is rotated

* used encoding/hex instead of just string() for the queryIDs in event so that they are readable

(cherry picked from commit 2754472)

Co-authored-by: CJPotter10 <[email protected]>
  • Loading branch information
github-actions[bot] and CJPotter10 authored Nov 22, 2024
1 parent 5eb58ae commit 61c2d0f
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions x/oracle/keeper/cycle_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"encoding/hex"
"errors"
"strconv"

Expand Down Expand Up @@ -79,6 +80,7 @@ func (k Keeper) RotateQueries(ctx context.Context) error {
}
querymeta.CycleList = true
querymeta.Expiration = uint64(blockHeight) + querymeta.RegistrySpecBlockWindow
emitRotateQueriesEvent(sdkCtx, hex.EncodeToString(queryId), strconv.Itoa(int(querymeta.Id)))
return k.Query.Set(ctx, collections.Join(queryId, querymeta.Id), querymeta)

}
Expand All @@ -89,6 +91,7 @@ func (k Keeper) RotateQueries(ctx context.Context) error {
if querymeta.Expiration <= uint64(blockHeight) && !querymeta.HasRevealedReports { // wrong, shouldn't use same query if expired
querymeta.Expiration = uint64(blockHeight) + querymeta.RegistrySpecBlockWindow
}
emitRotateQueriesEvent(sdkCtx, hex.EncodeToString(queryId), strconv.Itoa(int(querymeta.Id)))

return k.Query.Set(ctx, collections.Join(queryId, querymeta.Id), querymeta)
}
Expand All @@ -97,14 +100,7 @@ func (k Keeper) RotateQueries(ctx context.Context) error {
if err != nil {
return err
}
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"rotating-cyclelist-with-existing-nontipped-query",
sdk.NewAttribute("query_id", string(queryId)),
sdk.NewAttribute("Old QueryMeta Id", strconv.Itoa(int(querymeta.Id))),
sdk.NewAttribute("New QueryMeta Id", strconv.Itoa(int(nextId))),
),
})
emitRotateQueriesEvent(sdkCtx, hex.EncodeToString(queryId), strconv.Itoa(int(nextId)))
querymeta.Id = nextId
querymeta.Expiration = uint64(blockHeight) + querymeta.RegistrySpecBlockWindow
querymeta.HasRevealedReports = false
Expand All @@ -113,6 +109,16 @@ func (k Keeper) RotateQueries(ctx context.Context) error {
return k.Query.Set(ctx, collections.Join(queryId, querymeta.Id), querymeta)
}

func emitRotateQueriesEvent(sdkCtx sdk.Context, queryId, nextId string) {
sdkCtx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
"rotating-cyclelist-with-next-query",
sdk.NewAttribute("query_id", queryId),
sdk.NewAttribute("New QueryMeta Id", nextId),
),
})
}

func (k Keeper) ClearOldqueries(ctx context.Context, queryId []byte) error {
rng := collections.NewPrefixedPairRange[[]byte, uint64](queryId)

Expand Down

0 comments on commit 61c2d0f

Please sign in to comment.