put sorting fix next to event filtering

This commit is contained in:
Ethan Frey
2022-07-29 08:42:47 +02:00
parent a697c70650
commit c25550d775
2 changed files with 9 additions and 10 deletions

View File

@@ -7,7 +7,6 @@ import (
"fmt"
"math"
"path/filepath"
"sort"
"strconv"
"strings"
"time"
@@ -501,15 +500,6 @@ func (k Keeper) reply(ctx sdk.Context, contractAddress sdk.AccAddress, reply was
// prepare querier
querier := k.newQueryHandler(ctx, contractAddress)
gas := k.runtimeGasForContract(ctx)
if reply.Result.Ok != nil {
events := reply.Result.Ok.Events
for _, e := range events {
attributes := e.Attributes
sort.SliceStable(attributes, func(i, j int) bool {
return attributes[i].Key < attributes[j].Key
})
}
}
res, gasUsed, execErr := k.wasmVM.Reply(codeInfo.CodeHash, env, reply, prefixStore, cosmwasmAPI, querier, k.gasMeter(ctx), gas, costJSONDeserialization)
k.consumeRuntimeGas(ctx, gasUsed)

View File

@@ -1,7 +1,9 @@
package keeper
import (
"bytes"
"fmt"
"sort"
wasmvmtypes "github.com/CosmWasm/wasmvm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -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)