From 646edbef31b9b5eeff840be7d7f151ec3c75d1bb Mon Sep 17 00:00:00 2001 From: Puneet <59960662+puneet2019@users.noreply.github.com> Date: Fri, 26 Aug 2022 13:28:47 +0400 Subject: [PATCH] Puneet/epochevents (#2515) * add events from cachectx to main ctx events * add tests for events from hooks. * add entry to CHANGELOG.md (cherry picked from commit 1b5e970c46cbbf4b134ad791cd203ad5c56df8e7) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 13 +++++++++++++ x/epochs/types/hooks.go | 1 + x/epochs/types/hooks_test.go | 27 ++++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 276330608a3..d625c21aaaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,19 @@ This release contains minor CLI bug fixes. * [1759](https://github.com/osmosis-labs/osmosis/pull/1759) Fix pagination filter in incentives query. * [1698](https://github.com/osmosis-labs/osmosis/pull/1698) Register wasm snapshotter extension. * [1931](https://github.com/osmosis-labs/osmosis/pull/1931) Add explicit check for input denoms to `CalcJoinPoolShares` +<<<<<<< HEAD +======= +* [2011](https://github.com/osmosis-labs/osmosis/pull/2011) Fix bug in TokenFactory initGenesis, relating to denom creation fee param. +* [2186](https://github.com/osmosis-labs/osmosis/pull/2186) Remove liquidity event that was emitted twice per message. + +### Improvements +* [#2214](https://github.com/osmosis-labs/osmosis/pull/2214) Speedup epoch distribution, superfluid component +* [#2515](https://github.com/osmosis-labs/osmosis/pull/2515) Emit events from functions implementing epoch hooks' `panicCatchingEpochHook` cacheCtx + +### SDK Upgrades +* [#2245](https://github.com/osmosis-labs/osmosis/pull/2244) Upgrade SDK with the following major changes: + * Minimum deposit on proposer at submission time: https://github.com/osmosis-labs/cosmos-sdk/pull/296 +>>>>>>> 1b5e970c (Puneet/epochevents (#2515)) ## [v9.0.0 - Nitrogen](https://github.com/osmosis-labs/osmosis/releases/tag/v9.0.0) diff --git a/x/epochs/types/hooks.go b/x/epochs/types/hooks.go index b3d3adcf204..06339ddbbb2 100644 --- a/x/epochs/types/hooks.go +++ b/x/epochs/types/hooks.go @@ -50,4 +50,5 @@ func panicCatchingEpochHook( cacheCtx, write := ctx.CacheContext() hookFn(cacheCtx, epochIdentifier, epochNumber) write() + ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) } diff --git a/x/epochs/types/hooks_test.go b/x/epochs/types/hooks_test.go index 78394b8745c..ea796d280c6 100644 --- a/x/epochs/types/hooks_test.go +++ b/x/epochs/types/hooks_test.go @@ -1,6 +1,7 @@ package types_test import ( + "strconv" "testing" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,6 +27,22 @@ func (suite *KeeperTestSuite) SetupTest() { suite.queryClient = types.NewQueryClient(suite.QueryHelper) } +func dummyAfterEpochEndEvent(epochIdentifier string, epochNumber int64) sdk.Event { + return sdk.NewEvent( + "afterEpochEnd", + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ) +} + +func dummyBeforeEpochStartEvent(epochIdentifier string, epochNumber int64) sdk.Event { + return sdk.NewEvent( + "beforeEpochStart", + sdk.NewAttribute("epochIdentifier", epochIdentifier), + sdk.NewAttribute("epochNumber", strconv.FormatInt(epochNumber, 10)), + ) +} + // dummyEpochHook is a struct satisfying the epoch hook interface, // that maintains a counter for how many times its been succesfully called, // and a boolean for whether it should panic during its execution. @@ -39,6 +56,7 @@ func (hook *dummyEpochHook) AfterEpochEnd(ctx sdk.Context, epochIdentifier strin panic("dummyEpochHook is panicking") } hook.successCounter += 1 + ctx.EventManager().EmitEvent(dummyAfterEpochEndEvent(epochIdentifier, epochNumber)) } func (hook *dummyEpochHook) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochNumber int64) { @@ -46,6 +64,8 @@ func (hook *dummyEpochHook) BeforeEpochStart(ctx sdk.Context, epochIdentifier st panic("dummyEpochHook is panicking") } hook.successCounter += 1 + ctx.EventManager().EmitEvent(dummyBeforeEpochStartEvent(epochIdentifier, epochNumber)) + } func (hook *dummyEpochHook) Clone() *dummyEpochHook { @@ -55,7 +75,7 @@ func (hook *dummyEpochHook) Clone() *dummyEpochHook { var _ types.EpochHooks = &dummyEpochHook{} -func (suite *KeeperTestSuite) TestHooksPanicRecovery() { +func (suite *KeeperTestSuite) TestHooksPanicRecoveryAndEvents() { panicHook := dummyEpochHook{shouldPanic: true} noPanicHook := dummyEpochHook{shouldPanic: false} simpleHooks := []dummyEpochHook{panicHook, noPanicHook} @@ -81,8 +101,13 @@ func (suite *KeeperTestSuite) TestHooksPanicRecovery() { suite.NotPanics(func() { if epochActionSelector == 0 { hooks.BeforeEpochStart(suite.Ctx, "id", 0) + suite.Require().Equal(suite.Ctx.EventManager().Events(), sdk.Events{dummyBeforeEpochStartEvent("id", 0)}, + "test case index %d, before epoch event check", tcIndex) } else if epochActionSelector == 1 { hooks.AfterEpochEnd(suite.Ctx, "id", 0) + suite.Require().Equal(suite.Ctx.EventManager().Events(), sdk.Events{dummyAfterEpochEndEvent("id", 0)}, + "test case index %d, after epoch event check", tcIndex) + } })