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

External feegrants #1338

Merged
merged 11 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions cmd/feegrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,24 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
if len(args) > 1 {
granterKeyOrAddr = args[1]
} else if prov.PCfg.FeeGrants != nil {
granterKeyOrAddr = prov.PCfg.FeeGrants.GranterKey
granterKeyOrAddr = prov.PCfg.FeeGrants.GranterKeyOrAddr
} else {
granterKeyOrAddr = prov.PCfg.Key
}

externalGranter := false

granterKey, err := prov.KeyFromKeyOrAddress(granterKeyOrAddr)
if err != nil {
return fmt.Errorf("could not get granter key from '%s'", granterKeyOrAddr)
fmt.Printf("could not get granter key from '%s'", granterKeyOrAddr)
externalGranter = true
}

if externalGranter {
_, err := prov.DecodeBech32AccAddr(granterKeyOrAddr)
if err != nil {
return fmt.Errorf("an unknown granter was specified: '%s' is not a valid bech32 address", granterKeyOrAddr)
}
}

if delete {
Expand All @@ -75,11 +85,12 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
return nil
}

if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKey && !update {
return fmt.Errorf("you specified granter '%s' which is different than configured feegranter '%s', but you did not specify the --overwrite-granter flag", granterKeyOrAddr, prov.PCfg.FeeGrants.GranterKey)
} else if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKey && update {
if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKeyOrAddr && !update {
return fmt.Errorf("you specified granter '%s' which is different than configured feegranter '%s', but you did not specify the --overwrite-granter flag", granterKeyOrAddr, prov.PCfg.FeeGrants.GranterKeyOrAddr)
} else if prov.PCfg.FeeGrants != nil && granterKey != prov.PCfg.FeeGrants.GranterKeyOrAddr && update {
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error {
prov.PCfg.FeeGrants.GranterKey = granterKey
prov.PCfg.FeeGrants.GranterKeyOrAddr = granterKey
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter
return nil
})
cobra.CheckErr(cfgErr)
Expand All @@ -88,11 +99,17 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
if prov.PCfg.FeeGrants == nil || updateGrantees || len(grantees) > 0 {
var feegrantErr error

//No list of grantees was provided, so we will use the default naming convention "grantee1, ... granteeN"
// No list of grantees was provided, so we will use the default naming convention "grantee1, ... granteeN"
if grantees == nil {
if externalGranter {
return fmt.Errorf("external granter %s was specified, pre-authorized grantees must also be specified", granterKeyOrAddr)
}
feegrantErr = prov.ConfigureFeegrants(numGrantees, granterKey)
} else {
} else if !externalGranter {
feegrantErr = prov.ConfigureWithGrantees(grantees, granterKey)
} else {
fmt.Println("!! ConfigureWithExternalGranter !!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it may be debug output?

feegrantErr = prov.ConfigureWithExternalGranter(grantees, granterKeyOrAddr)
}

if feegrantErr != nil {
Expand All @@ -102,6 +119,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error {
chain := a.config.Chains[chain]
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider)
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants
return nil
})
Expand All @@ -119,8 +137,8 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
return fmt.Errorf("error writing grants on chain: '%s'", err.Error())
}

//Get latest height from the chain, mark feegrant configuration as verified up to that height.
//This means we've verified feegranting is enabled on-chain and TXs can be sent with a feegranter.
// Get latest height from the chain, mark feegrant configuration as verified up to that height.
// This means we've verified feegranting is enabled on-chain and TXs can be sent with a feegranter.
if prov.PCfg.FeeGrants != nil {
fmt.Printf("Querying latest chain height to mark FeeGrant height... \n")
h, err := prov.QueryLatestHeight(ctx)
Expand All @@ -129,6 +147,7 @@ func feegrantConfigureBasicCmd(a *appState) *cobra.Command {
cfgErr := a.performConfigLockingOperation(cmd.Context(), func() error {
chain := a.config.Chains[chain]
oldProv := chain.ChainProvider.(*cosmos.CosmosProvider)
prov.PCfg.FeeGrants.IsExternalGranter = externalGranter
oldProv.PCfg.FeeGrants = prov.PCfg.FeeGrants
oldProv.PCfg.FeeGrants.BlockHeightVerified = h
fmt.Printf("Feegrant chain height marked: %d\n", h)
Expand Down Expand Up @@ -169,18 +188,6 @@ func feegrantBasicGrantsCmd(a *appState) *cobra.Command {
return errors.New("only CosmosProvider can be feegranted")
}

// TODO fix pagination
// pageReq, err := client.ReadPageRequest(cmd.Flags())
// if err != nil {
// return err
// }

//TODO fix height
// height, err := lensCmd.ReadHeight(cmd.Flags())
// if err != nil {
// return err
// }

keyNameOrAddress := ""
if len(args) == 0 {
keyNameOrAddress = prov.PCfg.Key
Expand Down
Loading
Loading