Skip to content

Commit

Permalink
Merge branch 'main' into dwedul/1789-exchange-commitments
Browse files Browse the repository at this point in the history
# Conflicts:
#	x/marker/keeper/keeper_test.go
  • Loading branch information
SpicyLemon committed Jan 26, 2024
2 parents ef043a4 + e7615d6 commit ccfba77
Show file tree
Hide file tree
Showing 12 changed files with 412 additions and 17 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ jobs:
echo " db-cache-path: [${{ needs.setup.outputs.db-cache-path }}]"
echo "go-cache-key-suffix: [${{ needs.setup.outputs.go-cache-key-suffix }}]"
echo " go-cache-path: [${{ needs.setup.outputs.go-cache-path }}]"
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load db cache
id: db-cache-setup
with:
key: ${{ runner.os }}-${{ needs.setup.outputs.db-cache-key-suffix }}
path: ${{ needs.setup.outputs.db-cache-path }}
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load go cache
id: go-cache-setup
with:
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load go cache
with:
key: ${{ runner.os }}-${{ needs.setup.outputs.go-cache-key-suffix }}
Expand Down Expand Up @@ -203,12 +203,12 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load db cache
with:
key: ${{ runner.os }}-${{ needs.setup.outputs.db-cache-key-suffix }}
path: ${{ needs.setup.outputs.db-cache-path }}
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load go cache
with:
key: ${{ runner.os }}-${{ needs.setup.outputs.go-cache-key-suffix }}
Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Load go cache
with:
key: ${{ runner.os }}-${{ needs.setup.outputs.go-cache-key-suffix }}
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Features

* Add the ibcratelimit module [#1498](https://github.com/provenance-io/provenance/issues/1498).
* Add fix for NAV units to tourmaline upgrade handler [#1815](https://github.com/provenance-io/provenance/issues/1815).

### Improvements

* Add upgrade handler for 1.18 [#1756](https://github.com/provenance-io/provenance/pull/1756).
* Remove the rust upgrade handlers [PR 1774](https://github.com/provenance-io/provenance/pull/1774).
* Allow bypassing the config warning wait using an environment variable [PR 1810](https://github.com/provenance-io/provenance/pull/1810).
* Filter out empty distribution events from begin blocker [#1822](https://github.com/provenance-io/provenance/pull/1822).

### Bug Fixes

Expand All @@ -55,7 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Dependencies

- Bump `bufbuild/buf-setup-action` from 1.27.1 to 1.28.1 ([#1724](https://github.com/provenance-io/provenance/pull/1724), [#1744](https://github.com/provenance-io/provenance/pull/1744), [#1750](https://github.com/provenance-io/provenance/pull/1750))
- Bump `github.com/google/uuid` from 1.3.1 to 1.5.0 ([#1723](https://github.com/provenance-io/provenance/pull/1723), [#1781](https://github.com/provenance-io/provenance/pull/1781))
- Bump `github.com/google/uuid` from 1.3.1 to 1.6.0 ([#1723](https://github.com/provenance-io/provenance/pull/1723), [#1781](https://github.com/provenance-io/provenance/pull/1781), [#1819](https://github.com/provenance-io/provenance/pull/1819))
- Bump `github.com/gorilla/mux` from 1.8.0 to 1.8.1 ([#1734](https://github.com/provenance-io/provenance/pull/1734))
- Bump `golang.org/x/text` from 0.13.0 to 0.14.0 ([#1735](https://github.com/provenance-io/provenance/pull/1735))
- Bump `cosmossdk.io/math` from 1.1.2 to 1.2.0 ([#1739](https://github.com/provenance-io/provenance/pull/1739))
Expand All @@ -69,9 +71,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
- Bump `github/codeql-action` from 2 to 3 ([#1784](https://github.com/provenance-io/provenance/pull/1784))
- Bump `actions/download-artifact` from 3 to 4 ([#1785](https://github.com/provenance-io/provenance/pull/1785))
- Bump `actions/upload-artifact` from 3 to 4 ([#1785](https://github.com/provenance-io/provenance/pull/1785))
- Bump `google.golang.org/grpc` from 1.59.0 to 1.60.1 ([#1794](https://github.com/provenance-io/provenance/pull/1794))
- Bump `google.golang.org/grpc` from 1.59.0 to 1.61.0 ([#1794](https://github.com/provenance-io/provenance/pull/1794), [#1820](https://github.com/provenance-io/provenance/pull/1820))
- Bump `golang.org/x/crypto` from 0.14.0 to 0.17.0 ([#1788](https://github.com/provenance-io/provenance/pull/1788))
- Bump `cosmossdk.io/errors` from 1.0.0 to 1.0.1 ([#1806](https://github.com/provenance-io/provenance/pull/1806))
- Bump `actions/cache` from 3 to 4 ([#1817](https://github.com/provenance-io/provenance/pull/1817))

---

Expand Down
28 changes: 27 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,33 @@ func (app *App) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
return app.mm.BeginBlock(ctx, req)
responseBeginBlock := app.mm.BeginBlock(ctx, req)
responseBeginBlock.Events = filterBeginBlockerEvents(responseBeginBlock)
return responseBeginBlock
}

// filterBeginBlockerEvents filters out events from a given abci.ResponseBeginBlock according to the criteria defined in shouldFilterEvent.
func filterBeginBlockerEvents(responseBeginBlock abci.ResponseBeginBlock) []abci.Event {
filteredEvents := make([]abci.Event, 0)
for _, e := range responseBeginBlock.Events {
if shouldFilterEvent(e) {
continue
}
filteredEvents = append(filteredEvents, e)
}
return filteredEvents
}

// shouldFilterEvent checks if an abci.Event should be filtered based on its type and attributes.
func shouldFilterEvent(e abci.Event) bool {
if e.Type == distrtypes.EventTypeCommission || e.Type == distrtypes.EventTypeRewards || e.Type == distrtypes.EventTypeProposerReward || e.Type == banktypes.EventTypeTransfer || e.Type == banktypes.EventTypeCoinSpent || e.Type == banktypes.EventTypeCoinReceived {
for _, a := range e.Attributes {
if string(a.Key) == sdk.AttributeKeyAmount && len(a.Value) == 0 {
return true
}
}
}
return false
}

// EndBlocker application updates every end block
Expand Down
102 changes: 102 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
sdksim "github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -322,3 +324,103 @@ func assertAddrNotInAccounts(t *testing.T, addr sdk.AccAddress, addrName string,
}
return true
}

func createEvent(eventType string, attributes []abci.EventAttribute) abci.Event {
return abci.Event{
Type: eventType,
Attributes: attributes,
}
}

func TestShouldFilterEvent(t *testing.T) {
tests := []struct {
name string
event abci.Event
expect bool
}{
{"Empty commission event", createEvent(distrtypes.EventTypeCommission, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil commission event", createEvent(distrtypes.EventTypeCommission, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty commission event", createEvent(distrtypes.EventTypeCommission, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Empty rewards event", createEvent(distrtypes.EventTypeRewards, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil rewards event", createEvent(distrtypes.EventTypeRewards, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty rewards event", createEvent(distrtypes.EventTypeRewards, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Empty proposer_reward event", createEvent(distrtypes.EventTypeProposerReward, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil proposer_reward event", createEvent(distrtypes.EventTypeProposerReward, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty proposer_reward event", createEvent(distrtypes.EventTypeProposerReward, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Empty transfer event", createEvent(banktypes.EventTypeTransfer, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil transfer event", createEvent(banktypes.EventTypeTransfer, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty transfer event", createEvent(banktypes.EventTypeTransfer, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Empty coin_spent event", createEvent(banktypes.EventTypeCoinSpent, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil coin_spent event", createEvent(banktypes.EventTypeCoinSpent, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty coin_spent event", createEvent(banktypes.EventTypeCoinSpent, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Empty coin_received event", createEvent(banktypes.EventTypeCoinReceived, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), true},
{"Nil coin_received event", createEvent(banktypes.EventTypeCoinReceived, []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), true},
{"Non-empty coin_received event", createEvent(banktypes.EventTypeCoinReceived, []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},

{"Unhandled event type with empty amount", createEvent("unhandled_type", []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("")}}), false},
{"Unhandled event type with nil amount", createEvent("unhandled_type", []abci.EventAttribute{{Key: []byte("amount"), Value: nil}}), false},
{"Unhandled event type with non-empty amount", createEvent("unhandled_type", []abci.EventAttribute{{Key: []byte("amount"), Value: []byte("100")}}), false},
{"Event with no attributes", createEvent(distrtypes.EventTypeCommission, []abci.EventAttribute{}), false},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
result := shouldFilterEvent(tc.event)
assert.Equal(t, tc.expect, result, "Test %v failed: expected %v, got %v", tc.name, tc.expect, result)
})
}
}

func TestFilterBeginBlockerEvents(t *testing.T) {
tests := []struct {
name string
events []abci.Event
expected []abci.Event
}{
{
name: "Filter out events with empty amounts",
events: []abci.Event{
createEvent(distrtypes.EventTypeCommission, []abci.EventAttribute{{Key: []byte(sdk.AttributeKeyAmount), Value: []byte("")}}),
createEvent(distrtypes.EventTypeRewards, []abci.EventAttribute{{Key: []byte(sdk.AttributeKeyAmount), Value: []byte("100")}}),
},
expected: []abci.Event{
createEvent(distrtypes.EventTypeRewards, []abci.EventAttribute{{Key: []byte(sdk.AttributeKeyAmount), Value: []byte("100")}}),
},
},
{
name: "No filtering when all events are valid",
events: []abci.Event{
createEvent(banktypes.EventTypeTransfer, []abci.EventAttribute{{Key: []byte(sdk.AttributeKeyAmount), Value: []byte("100")}}),
},
expected: []abci.Event{
createEvent(banktypes.EventTypeTransfer, []abci.EventAttribute{{Key: []byte(sdk.AttributeKeyAmount), Value: []byte("100")}}),
},
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
responseBeginBlock := abci.ResponseBeginBlock{Events: tc.events}
actualEvents := filterBeginBlockerEvents(responseBeginBlock)
assert.Equal(t, len(tc.expected), len(actualEvents), "Number of events mismatch")

for i, expectedEvent := range tc.expected {
actualEvent := actualEvents[i]
assert.Equal(t, expectedEvent.Type, actualEvent.Type, "Event types mismatch")

assert.Equal(t, len(expectedEvent.Attributes), len(actualEvent.Attributes), "Number of attributes mismatch in event %v", expectedEvent.Type)

for j, expectedAttribute := range expectedEvent.Attributes {
actualAttribute := actualEvent.Attributes[j]
assert.Equal(t, expectedAttribute.Key, actualAttribute.Key, "Attribute keys mismatch in event %v", expectedEvent.Type)
assert.Equal(t, expectedAttribute.Value, actualAttribute.Value, "Attribute values mismatch in event %v", expectedEvent.Type)
}
}
})
}
}
26 changes: 26 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ var upgrades = map[string]appUpgrade{
}

removeInactiveValidatorDelegations(ctx, app)
convertNavUnits(ctx, app)

return vm, nil
},
Expand All @@ -141,6 +142,7 @@ var upgrades = map[string]appUpgrade{
}

removeInactiveValidatorDelegations(ctx, app)
convertNavUnits(ctx, app)

return vm, nil
},
Expand Down Expand Up @@ -349,3 +351,27 @@ func updateIbcMarkerDenomMetadata(ctx sdk.Context, app *App) {
})
ctx.Logger().Info("Done updating ibc marker denom metadata")
}

// convertNavUnits iterates all the net asset values and updates their units if they are using usd.
func convertNavUnits(ctx sdk.Context, app *App) {
ctx.Logger().Info("Converting NAV units")
err := app.MarkerKeeper.IterateAllNetAssetValues(ctx, func(markerAddr sdk.AccAddress, nav markertypes.NetAssetValue) (stop bool) {
if nav.Price.Denom == markertypes.UsdDenom {
nav.Price.Amount = nav.Price.Amount.Mul(math.NewInt(10))
marker, err := app.MarkerKeeper.GetMarker(ctx, markerAddr)
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to get marker for address: %s, error: %s", markerAddr, err))
return false
}
err = app.MarkerKeeper.SetNetAssetValue(ctx, marker, nav, "upgrade")
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to set net asset value for marker: %s, error: %s", markerAddr, err))
return false
}
}
return false
})
if err != nil {
ctx.Logger().Error(fmt.Sprintf("Unable to iterate all net asset values error: %s", err))
}
}
Loading

0 comments on commit ccfba77

Please sign in to comment.