Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/not filter out feerefunder events #19

Open
wants to merge 9 commits into
base: neutron
Choose a base branch
from
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func NewWasmApp(
distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
upgrade.NewAppModule(app.upgradeKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.accountKeeper, app.bankKeeper),
evidence.NewAppModule(app.evidenceKeeper),
feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.bankKeeper, app.feeGrantKeeper, app.interfaceRegistry),
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry),
Expand Down Expand Up @@ -702,7 +702,7 @@ func NewWasmApp(
slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper),
params.NewAppModule(app.paramsKeeper),
evidence.NewAppModule(app.evidenceKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.bankKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.accountKeeper, app.bankKeeper),
ibc.NewAppModule(app.ibcKeeper),
transferModule,
)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestInitGenesis(t *testing.T) {
q2 := newData.module.LegacyQuerierHandler(nil)

// initialize new app with genstate
InitGenesis(newData.ctx, &newData.keeper, *genState, newData.stakingKeeper, newData.module.Route().Handler())
InitGenesis(newData.ctx, &newData.keeper, *genState, newData.module.Route().Handler())

// run same checks again on newdata, to make sure it was reinitialized correctly
assertCodeList(t, q2, newData.ctx, 1)
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type ValidatorSetSource interface {
// InitGenesis sets supply information for genesis.
//
// CONTRACT: all types of accounts must have been already initialized/created
func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, stakingKeeper ValidatorSetSource, msgHandler sdk.Handler) ([]abci.ValidatorUpdate, error) {
func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, msgHandler sdk.Handler) ([]abci.ValidatorUpdate, error) {
contractKeeper := NewGovPermissionKeeper(keeper)
keeper.SetParams(ctx, data.Params)
var maxCodeID uint64
Expand Down Expand Up @@ -78,7 +78,7 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki
return nil, sdkerrors.Wrap(err, "genesis")
}
}
return stakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx)
return []abci.ValidatorUpdate{}, nil
}

// ExportGenesis returns a GenesisState for a given context and keeper.
Expand Down
18 changes: 5 additions & 13 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/proto/tendermint/crypto"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"

Expand Down Expand Up @@ -130,7 +129,7 @@ func TestGenesisExportImport(t *testing.T) {
var importState wasmTypes.GenesisState
err = dstKeeper.cdc.UnmarshalJSON(exportedGenesis, &importState)
require.NoError(t, err)
InitGenesis(dstCtx, dstKeeper, importState, &StakingKeeperMock{}, TestHandler(contractKeeper))
InitGenesis(dstCtx, dstKeeper, importState, TestHandler(contractKeeper))

// compare whole DB
for j := range srcStoreKeys {
Expand Down Expand Up @@ -411,14 +410,7 @@ func TestGenesisInit(t *testing.T) {
},
Params: types.DefaultParams(),
},
stakingMock: StakingKeeperMock{expCalls: 1, validatorUpdate: []abci.ValidatorUpdate{
{
PubKey: crypto.PublicKey{Sum: &crypto.PublicKey_Ed25519{
Ed25519: []byte("a valid key"),
}},
Power: 100,
},
}},
stakingMock: StakingKeeperMock{expCalls: 0, validatorUpdate: []abci.ValidatorUpdate{}},
msgHandlerMock: MockMsgHandler{expCalls: 1, expMsg: types.MsgStoreCodeFixture()},
expSuccess: true,
},
Expand All @@ -440,7 +432,7 @@ func TestGenesisInit(t *testing.T) {
keeper, ctx, _ := setupKeeper(t)

require.NoError(t, types.ValidateGenesis(spec.src))
gotValidatorSet, gotErr := InitGenesis(ctx, keeper, spec.src, &spec.stakingMock, spec.msgHandlerMock.Handle)
gotValidatorSet, gotErr := InitGenesis(ctx, keeper, spec.src, spec.msgHandlerMock.Handle)
if !spec.expSuccess {
require.Error(t, gotErr)
return
Expand Down Expand Up @@ -513,7 +505,7 @@ func TestImportContractWithCodeHistoryReset(t *testing.T) {
ctx = ctx.WithBlockHeight(0).WithGasMeter(sdk.NewInfiniteGasMeter())

// when
_, err = InitGenesis(ctx, keeper, importState, &StakingKeeperMock{}, TestHandler(contractKeeper))
_, err = InitGenesis(ctx, keeper, importState, TestHandler(contractKeeper))
require.NoError(t, err)

// verify wasm code
Expand Down Expand Up @@ -615,7 +607,7 @@ func TestSupportedGenMsgTypes(t *testing.T) {
keepers.Faucet.Fund(ctx, myAddress, sdk.NewCoin(denom, sdk.NewInt(100)))

// when
_, err = InitGenesis(ctx, keeper, importState, &StakingKeeperMock{}, TestHandler(keepers.ContractKeeper))
_, err = InitGenesis(ctx, keeper, importState, TestHandler(keepers.ContractKeeper))
require.NoError(t, err)

// verify code stored
Expand Down
26 changes: 25 additions & 1 deletion x/wasm/keeper/msg_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,35 @@ func redactError(err error) error {
return fmt.Errorf("codespace: %s, code: %d", codespace, code)
}

func isIBCEvent(event sdk.Event) bool {
for _, attr := range event.Attributes {
// Hermes ibc-rs subscribes on such events, so we need to keep them to have the ibc-rs working properly
// https://github.com/informalsystems/ibc-rs/blob/ed4dd8c8b4ebd695730de2a1c69f3011cb179352/relayer/src/event/monitor.rs#L134
if bytes.HasPrefix(attr.Value, []byte("ibc_")) {
return true
}
}
return false
}

func isFeerefunderEvent(event sdk.Event) bool {
for _, attr := range event.Attributes {
// During contracts execution there are fee being locked and feerefunder module emits lock_fees event
if bytes.Equal(attr.Key, []byte("module")) && bytes.Equal(attr.Value, []byte("feerefunder")) {
return true
}
}
return false
}

func filterEvents(events []sdk.Event) []sdk.Event {
// pre-allocate space for efficiency
res := make([]sdk.Event, 0, len(events))
for _, ev := range events {
if ev.Type != "message" {
// we filter out all 'message' type events but
// 1. ibc events (we must keep them for the IBC relayer (hermes particularly))
// 2. feerefunder events
if ev.Type != "message" || isIBCEvent(ev) || isFeerefunderEvent(ev) {
res = append(res, ev)
}
}
Expand Down
8 changes: 6 additions & 2 deletions x/wasm/keeper/msg_dispatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ func TestDispatchSubmessages(t *testing.T) {
return nil, fmt.Errorf("event count: %#v", res.Events)
}
if res.Events[0].Type != "execute" {
return nil, fmt.Errorf("event0: %#v", res.Events[0])
return nil, fmt.Errorf("event1: %#v", res.Events[1])
}
if res.Events[1].Type != "wasm" {
return nil, fmt.Errorf("event1: %#v", res.Events[1])
return nil, fmt.Errorf("event2: %#v", res.Events[2])
}

// let's add a custom event here and see if it makes it out
Expand Down Expand Up @@ -374,6 +374,8 @@ func TestDispatchSubmessages(t *testing.T) {
sdk.NewEvent("message", sdk.NewAttribute("stargate", "something-something")),
// we still emit this to the client, but not the contract
sdk.NewEvent("non-determinstic"),
sdk.NewEvent("message", sdk.NewAttribute("module", "ibc_channel")),
sdk.NewEvent("message", sdk.NewAttribute("module", "feerefunder")),
}
return events, [][]byte{[]byte("subData")}, nil
},
Expand All @@ -382,6 +384,8 @@ func TestDispatchSubmessages(t *testing.T) {
expCommits: []bool{true},
expEvents: []sdk.Event{
sdk.NewEvent("non-determinstic"),
sdk.NewEvent("message", sdk.NewAttribute("module", "ibc_channel")),
sdk.NewEvent("message", sdk.NewAttribute("module", "feerefunder")),
// the event from reply is also exposed
sdk.NewEvent("stargate-reply"),
},
Expand Down
23 changes: 10 additions & 13 deletions x/wasm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ func (b AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)
// AppModule implements an application module for the wasm module.
type AppModule struct {
AppModuleBasic
cdc codec.Codec
keeper *Keeper
validatorSetSource keeper.ValidatorSetSource
accountKeeper types.AccountKeeper // for simulation
bankKeeper simulation.BankKeeper
cdc codec.Codec
keeper *Keeper
accountKeeper types.AccountKeeper // for simulation
bankKeeper simulation.BankKeeper
}

// ConsensusVersion is a sequence number for state-breaking change of the
Expand All @@ -117,17 +116,15 @@ func (AppModule) ConsensusVersion() uint64 { return 1 }
func NewAppModule(
cdc codec.Codec,
keeper *Keeper,
validatorSetSource keeper.ValidatorSetSource,
ak types.AccountKeeper,
bk simulation.BankKeeper,
) AppModule {
return AppModule{
AppModuleBasic: AppModuleBasic{},
cdc: cdc,
keeper: keeper,
validatorSetSource: validatorSetSource,
accountKeeper: ak,
bankKeeper: bk,
AppModuleBasic: AppModuleBasic{},
cdc: cdc,
keeper: keeper,
accountKeeper: ak,
bankKeeper: bk,
}
}

Expand Down Expand Up @@ -158,7 +155,7 @@ func (AppModule) QuerierRoute() string {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
var genesisState GenesisState
cdc.MustUnmarshalJSON(data, &genesisState)
validators, err := InitGenesis(ctx, am.keeper, genesisState, am.validatorSetSource, am.Route().Handler())
validators, err := InitGenesis(ctx, am.keeper, genesisState, am.Route().Handler())
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func setupTest(t *testing.T) testData {
ctx, keepers := CreateTestInput(t, false, "iterator,staking,stargate")
cdc := keeper.MakeTestCodec(t)
data := testData{
module: NewAppModule(cdc, keepers.WasmKeeper, keepers.StakingKeeper, keepers.AccountKeeper, keepers.BankKeeper),
module: NewAppModule(cdc, keepers.WasmKeeper, keepers.AccountKeeper, keepers.BankKeeper),
ctx: ctx,
acctKeeper: keepers.AccountKeeper,
keeper: *keepers.WasmKeeper,
Expand Down