Skip to content

Commit

Permalink
change bypass-min-fee-types parsing; change defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
MSalopek committed Jan 27, 2023
1 parent 983a9fe commit f7e198b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
25 changes: 23 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,21 @@ func NewGaiaApp(
app.MountTransientStores(app.GetTransientStoreKey())
app.MountMemoryStores(app.GetMemoryStoreKey())

bypassMinFeeMsgTypes := cast.ToStringSlice(appOpts.Get(gaiaappparams.BypassMinFeeMsgTypesKey))
if bypassMinFeeMsgTypes == nil {
var bypassMinFeeMsgTypes []string
bypassMinFeeMsgTypesOptions := appOpts.Get(gaiaappparams.BypassMinFeeMsgTypesKey)
if bypassMinFeeMsgTypesOptions == nil {
bypassMinFeeMsgTypes = GetDefaultBypassFeeMessages()
} else {
bypassMinFeeMsgTypes = cast.ToStringSlice(bypassMinFeeMsgTypesOptions)
}

if err := app.ValidateBypassFeeMsgTypes(bypassMinFeeMsgTypes); err != nil {
app.Logger().Error("invalid 'bypass-min-fee-msg-types' config option", "error", err)
panic(fmt.Sprintf("invalid 'bypass-min-fee-msg-types' config option: %s", err))
}

app.Logger().Info("min fee bypass activated for message types", "types", bypassMinFeeMsgTypes)

anteHandler, err := gaiaante.NewAnteHandler(
gaiaante.HandlerOptions{
HandlerOptions: ante.HandlerOptions{
Expand Down Expand Up @@ -235,6 +245,17 @@ func GetDefaultBypassFeeMessages() []string {
}
}

// ValidateBypassFeeMsgTypes checks that a proto message type exists for all MsgTypes in bypassMinFeeMsgTypes
// An error is returned for the first msgType that cannot be resolved
func (app *GaiaApp) ValidateBypassFeeMsgTypes(bypassMinFeeMsgTypes []string) error {
for _, msgType := range bypassMinFeeMsgTypes {
if _, err := app.interfaceRegistry.Resolve(msgType); err != nil {
return err
}
}
return nil
}

// Name returns the name of the App
func (app *GaiaApp) Name() string { return app.BaseApp.Name() }

Expand Down
11 changes: 10 additions & 1 deletion app/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ var (
###############################################################################
# bypass-min-fee-msg-types defines custom message types the operator may set that
# will bypass minimum fee checks during CheckTx.
# NOTE:
# bypass-min-fee-msg-types = [] will deactivate the bypass - no messages will be allowed to bypass the minimum fee check
# bypass-min-fee-msg-types = [<MsgType>...] will allow messages of specified type to bypass the minimum fee check
# removing bypass-min-fee-msg-types from the config file will apply the default values:
# ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", "/ibc.core.client.v1.MsgUpdateClient"]
#
# Example:
# ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", ...]
# bypass-min-fee-msg-types = ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", "/ibc.core.client.v1.MsgUpdateClient"]
bypass-min-fee-msg-types = [{{ range .BypassMinFeeMsgTypes }}{{ printf "%q, " . }}{{end}}]
`
)
Expand All @@ -42,5 +47,9 @@ type CustomAppConfig struct {

// BypassMinFeeMsgTypes defines custom message types the operator may set that
// will bypass minimum fee checks during CheckTx.
// NOTE:
// bypass-min-fee-msg-types = [] will deactivate the bypass - no messages will be allowed to bypass the minimum fee check
// bypass-min-fee-msg-types = [<some_msg_type>] will allow messages of specified type to bypass the minimum fee check
// omitting bypass-min-fee-msg-types from the config file will use the default values: ["/ibc.core.channel.v1.MsgRecvPacket", "/ibc.core.channel.v1.MsgAcknowledgement", "/ibc.core.client.v1.MsgUpdateClient"]
BypassMinFeeMsgTypes []string `mapstructure:"bypass-min-fee-msg-types"`
}
2 changes: 1 addition & 1 deletion cmd/gaiad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func initAppConfig() (string, interface{}) {

return params.CustomConfigTemplate(), params.CustomAppConfig{
Config: *srvCfg,
BypassMinFeeMsgTypes: gaia.GetDefaultBypassFeeMessages(),
BypassMinFeeMsgTypes: []string{},
}
}

Expand Down

0 comments on commit f7e198b

Please sign in to comment.