From 01a3d5233c0cbf31234d96aea9c64b73846be8bd Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 21 Oct 2024 15:26:23 -0600 Subject: [PATCH 1/3] Create a no-op event manager and use that during the metadata module migration. --- internal/sdk/events.go | 46 ++++++++++++++++++++++++++++++ x/metadata/keeper/migrations_v4.go | 4 +++ 2 files changed, 50 insertions(+) create mode 100644 internal/sdk/events.go diff --git a/internal/sdk/events.go b/internal/sdk/events.go new file mode 100644 index 000000000..783ca3745 --- /dev/null +++ b/internal/sdk/events.go @@ -0,0 +1,46 @@ +package sdk + +import ( + abci "github.com/cometbft/cometbft/abci/types" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/gogoproto/proto" +) + +// NoOpEventManager is an event manager that satisfies the sdk.EventManagerI interface, but does nothing. +type NoOpEventManager struct{} + +var _ sdk.EventManagerI = (*NoOpEventManager)(nil) + +// NewNoOpEventManager returns a new event manager that does nothing. +func NewNoOpEventManager() *NoOpEventManager { + return &NoOpEventManager{} +} + +// Events returns sdk.EmptyEvents(). +func (x NoOpEventManager) Events() sdk.Events { + // Returning sdk.EmptyEvents() here (instead of nil) to match sdk.EventManager behavior. + return sdk.EmptyEvents() +} + +// ABCIEvents returns sdk.EmptyABCIEvents(). +func (x NoOpEventManager) ABCIEvents() []abci.Event { + // Returning sdk.EmptyABCIEvents() here (instead of nil) to match sdk.EventManager behavior. + return sdk.EmptyABCIEvents() +} + +// EmitTypedEvent ignores the provided argument, does nothing, and always returns nil. +func (x NoOpEventManager) EmitTypedEvent(_ proto.Message) error { + return nil +} + +// EmitTypedEvents ignores the provided arguments, does nothing, and always returns nil. +func (x NoOpEventManager) EmitTypedEvents(_ ...proto.Message) error { + return nil +} + +// EmitEvent ignores the provided event and does nothing. +func (x NoOpEventManager) EmitEvent(_ sdk.Event) {} + +// EmitEvents ignores the provided events and does nothing. +func (x NoOpEventManager) EmitEvents(_ sdk.Events) {} diff --git a/x/metadata/keeper/migrations_v4.go b/x/metadata/keeper/migrations_v4.go index a9b89ec25..046382e86 100644 --- a/x/metadata/keeper/migrations_v4.go +++ b/x/metadata/keeper/migrations_v4.go @@ -10,12 +10,16 @@ import ( "github.com/cosmos/cosmos-sdk/types/address" "github.com/cosmos/gogoproto/proto" + internalsdk "github.com/provenance-io/provenance/internal/sdk" markertypes "github.com/provenance-io/provenance/x/marker/types" "github.com/provenance-io/provenance/x/metadata/types" ) // Migrate3To4 will update the metadata store from version 3 to version 4. This should be part of the viridian upgrade. func (m Migrator) Migrate3To4(ctx sdk.Context) error { + // This migration emits too many events and can cause problems with nodes due to its size. + // So we'll just throw all of them away by swapping in a different event manager here. + ctx = ctx.WithEventManager(internalsdk.NewNoOpEventManager()) logger := m.keeper.Logger(ctx) logger.Info("Starting migration of x/metadata from 3 to 4.") if err := migrateValueOwners(ctx, newKeeper3To4(m.keeper)); err != nil { From a6c28d0b3dc917fc2412c7f2a519a00c1fb1f16b Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 21 Oct 2024 16:46:27 -0600 Subject: [PATCH 2/3] Do not suppress the events for a testnet upgrade since they were emitted when the migration ran on testnet. --- x/metadata/keeper/migrations_v4.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x/metadata/keeper/migrations_v4.go b/x/metadata/keeper/migrations_v4.go index 046382e86..36a1ae062 100644 --- a/x/metadata/keeper/migrations_v4.go +++ b/x/metadata/keeper/migrations_v4.go @@ -19,7 +19,11 @@ import ( func (m Migrator) Migrate3To4(ctx sdk.Context) error { // This migration emits too many events and can cause problems with nodes due to its size. // So we'll just throw all of them away by swapping in a different event manager here. - ctx = ctx.WithEventManager(internalsdk.NewNoOpEventManager()) + // But the testnet migration already ran using v1.20.0-rc2 which included all of the events in the block result. + // So, to keep v1.20.0-rc2 and v1.20.0 state compatible, we only throw out the events when not on a testnet. + if sdk.GetConfig().GetBech32AccountAddrPrefix() != "tp" { + ctx = ctx.WithEventManager(internalsdk.NewNoOpEventManager()) + } logger := m.keeper.Logger(ctx) logger.Info("Starting migration of x/metadata from 3 to 4.") if err := migrateValueOwners(ctx, newKeeper3To4(m.keeper)); err != nil { From 476152a129d386b267ce38bdbfddf8849d63008a Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Mon, 21 Oct 2024 16:48:22 -0600 Subject: [PATCH 3/3] Add changelog entry. --- .changelog/unreleased/improvements/2195-hide-md-mig-events.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 .changelog/unreleased/improvements/2195-hide-md-mig-events.md diff --git a/.changelog/unreleased/improvements/2195-hide-md-mig-events.md b/.changelog/unreleased/improvements/2195-hide-md-mig-events.md new file mode 100644 index 000000000..82965304d --- /dev/null +++ b/.changelog/unreleased/improvements/2195-hide-md-mig-events.md @@ -0,0 +1 @@ +* Suppress the events emitted during the metadata migration that changes how scope value owners are recorded [PR 2195](https://github.com/provenance-io/provenance/pull/2195).