From 61c2d0f7b0fb0e980b71d510fb4b07a15c82469c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 12:26:00 -0600 Subject: [PATCH] made it so that it always returned an event when cyclelist is rotated (#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 2754472ea9f6e967d73421fb2f68608ac7d3fed4) Co-authored-by: CJPotter10 <91627020+CJPotter10@users.noreply.github.com> --- x/oracle/keeper/cycle_list.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/x/oracle/keeper/cycle_list.go b/x/oracle/keeper/cycle_list.go index f63c98c9..afa96861 100644 --- a/x/oracle/keeper/cycle_list.go +++ b/x/oracle/keeper/cycle_list.go @@ -2,6 +2,7 @@ package keeper import ( "context" + "encoding/hex" "errors" "strconv" @@ -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) } @@ -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) } @@ -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 @@ -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)