Skip to content

Commit

Permalink
Merge pull request #918 from CosmWasm/sorting-fix
Browse files Browse the repository at this point in the history
Sorting fix
  • Loading branch information
ethanfrey authored Jul 29, 2022
2 parents f5804fc + 90a3781 commit 2886092
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.28.0...HEAD)

## [v0.27.0](https://github.com/CosmWasm/wasmd/tree/v0.28.0) (2022-07-29)
## [v0.28.0](https://github.com/CosmWasm/wasmd/tree/v0.28.0) (2022-07-29)

[Full Changelog](https://github.com/CosmWasm/wasmd/compare/v0.27.0...v0.28.0)

Expand All @@ -22,6 +22,7 @@ Migration notes:
The main issue here is likely "Custom" queries from a blockchain, which want to send info (eg. how many tokens were swapped).
Since those custom bindings are maintained by the chain, they can use the data field to pass any deterministic information
back to the contract. We recommend using JSON encoding there with some documented format the contracts can parse out easily.
* For possible non-determinism issues, we also sort all attributes in events. Better safe than sorry.

## [v0.27.0](https://github.com/CosmWasm/wasmd/tree/v0.27.0) (2022-05-19)

Expand Down
1 change: 1 addition & 0 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was
// prepare querier
querier := k.newQueryHandler(ctx, contractAddress)
gas := k.runtimeGasForContract(ctx)

res, gasUsed, execErr := k.wasmVM.Reply(codeInfo.CodeHash, env, reply, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization)
k.consumeRuntimeGas(ctx, gasUsed)
if execErr != nil {
Expand Down
9 changes: 9 additions & 0 deletions x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package keeper

import (
"bytes"
"fmt"
"sort"

wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -109,6 +111,13 @@ func (d MessageDispatcher) DispatchSubmessages(ctx sdk.Context, contractAddr sdk
ctx.EventManager().EmitEvents(filteredEvents)
if msg.Msg.Wasm == nil {
filteredEvents = []sdk.Event{}
} else {
for _, e := range filteredEvents {
attributes := e.Attributes
sort.SliceStable(attributes, func(i, j int) bool {
return bytes.Compare(attributes[i].Key, attributes[j].Key) < 0
})
}
}
} // on failure, revert state from sandbox, and ignore events (just skip doing the above)

Expand Down

0 comments on commit 2886092

Please sign in to comment.