Skip to content

Commit

Permalink
fix: clean up market map hooks (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Johnson committed Dec 11, 2024
1 parent 9eb4eeb commit 2341cdd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
4 changes: 4 additions & 0 deletions x/marketmap/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ func (ms msgServer) RemoveMarkets(
ctx.Logger().Info(fmt.Sprintf("deleted market %s", market))
deletedMarkets = append(deletedMarkets, market)
}

if err := ms.k.hooks.AfterMarketRemoved(ctx, market); err != nil {
return nil, fmt.Errorf("unable to run market removal hook: %w", err)
}

Check warning on line 289 in x/marketmap/keeper/msg_server.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/keeper/msg_server.go#L288-L289

Added lines #L288 - L289 were not covered by tests
}

// check if the resulting state is valid: it may not be valid if the removed market is used as a normalization pair
Expand Down
8 changes: 4 additions & 4 deletions x/marketmap/types/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type MarketMapHooks interface {
AfterMarketGenesis(ctx sdk.Context, tickers map[string]Market) error

// AfterMarketRemoved is called after a market is removed.
AfterMarketRemoved(ctx sdk.Context, market Market) error
AfterMarketRemoved(ctx sdk.Context, key string) error
}

var _ MarketMapHooks = &MultiMarketMapHooks{}
Expand Down Expand Up @@ -58,9 +58,9 @@ func (mh MultiMarketMapHooks) AfterMarketGenesis(ctx sdk.Context, markets map[st
}

// AfterMarketRemoved calls all AfterMarketRemoved hooks registered to the MultiMarketMapHooks.
func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, market Market) error {
func (mh MultiMarketMapHooks) AfterMarketRemoved(ctx sdk.Context, key string) error {

Check warning on line 61 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L61

Added line #L61 was not covered by tests
for i := range mh {
if err := mh[i].AfterMarketRemoved(ctx, market); err != nil {
if err := mh[i].AfterMarketRemoved(ctx, key); err != nil {

Check warning on line 63 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L63

Added line #L63 was not covered by tests
return err
}
}
Expand Down Expand Up @@ -88,6 +88,6 @@ func (n *NoopMarketMapHooks) AfterMarketGenesis(_ sdk.Context, _ map[string]Mark
return nil
}

func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ Market) error {
func (n *NoopMarketMapHooks) AfterMarketRemoved(_ sdk.Context, _ string) error {

Check warning on line 91 in x/marketmap/types/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/marketmap/types/hooks.go#L91

Added line #L91 was not covered by tests
return nil
}
10 changes: 5 additions & 5 deletions x/marketmap/types/mocks/MarketMapHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions x/oracle/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func (h Hooks) AfterMarketGenesis(ctx sdk.Context, markets map[string]marketmapt

// AfterMarketRemoved is the marketmap hook for x/oracle that is run after a market is removed in
// the marketmap.
func (h Hooks) AfterMarketRemoved(ctx sdk.Context, market marketmaptypes.Market) error {
ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", market.Ticker.String()))
func (h Hooks) AfterMarketRemoved(ctx sdk.Context, key string) error {
ctx.Logger().Info(fmt.Sprintf("market %s removed. retaining x/oracle state if it exists", key))

Check warning on line 54 in x/oracle/keeper/hooks.go

View check run for this annotation

Codecov / codecov/patch

x/oracle/keeper/hooks.go#L52-L54

Added lines #L52 - L54 were not covered by tests
return nil
}

0 comments on commit 2341cdd

Please sign in to comment.