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

External feegrants #1338

merged 11 commits into from
Jan 29, 2024

Conversation

KyleMoser
Copy link
Contributor

  • Allows feegrants where relayer does not have the Granter private key/mnemonic
  • This means the grantees are authorized externally (someone else owns the Granter key)

Copy link
Member

@jtieri jtieri left a comment

Choose a reason for hiding this comment

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

i'm not intimately familiar with feegrant as a feature so i could be missing some context that would lead me to miss the validity of some implementation detail but I took a couple passes and everything looks mostly good besides for a few comments i had.

perhaps @boojamya, @vimystic or @agouin would care to take a pass as well?

}

// SetSDKContext sets the SDK config to the given bech32 prefixes
func SetSDKConfigContext(prefix string) func() {
Copy link
Member

Choose a reason for hiding this comment

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

if this helper method is not used elsewhere we could change it from exported to unexported.

cmd/feegrant.go Outdated
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?

Comment on lines +254 to +256
var granterAddr string
var granterAcc types.AccAddress
var err error
Copy link
Member

Choose a reason for hiding this comment

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

not necessary but this could just be

var (
    granterAddr string
    granterAcc types.AccAddress
    err error
)

fmt.Printf("Grant will be created on chain for granter %s and grantee %s\n", granterAddr, granteeAddr)
grantMsg, err := cc.getMsgGrantBasicAllowance(granterAcc, granteeAcc)
if err != nil {
return nil, err
}
msgs = append(msgs, grantMsg)
} else if !hasGrant {
fmt.Printf("WARN: External granter %s has no on-chain feegrant for grantee %s\n", granterAddr, granteeAddr)
Copy link
Member

Choose a reason for hiding this comment

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

It seems like we are going for level based logging here with the WARN, we should have access to the ChainProvider's zap.Logger here so you could use that to have a structured log at warn level.

We have a doc describing our logging conventions here. This could be used for all the logs being printed to stdout so that the logs are consistent looking in an operators terminal

@KyleMoser
Copy link
Contributor Author

i'm not intimately familiar with feegrant as a feature so i could be missing some context that would lead me to miss the validity of some implementation detail but I took a couple passes and everything looks mostly good besides for a few comments i had.

perhaps @boojamya, @vimystic or @agouin would care to take a pass as well?

Thanks for the feedback. Yeah, this is a minor update so everything should be the same functionality wise. But it's a very error-prone feature so I appreciate the review. I will fix the issues you suggested; did not mean to leave the Printfs in there, that was just debugging.

@ertemann
Copy link
Contributor

@KyleMoser did you happen to have time to finalise this PR? i dont have the skills really to finish this myself but we would love this feature to be implemented :)

@dylanschultzie
Copy link

dylanschultzie commented Jan 16, 2024

I can confirm this works.

relayer address: https://finder.kujira.network/kaiyo-1/address/kujira18xrruhq5r246mwk0yj9elnn3mte8xa9u3ae4pk

tx: https://finder.kujira.network/kaiyo-1/tx/52B8E62E0D1546DC79209DB85EAA233B95A2594FEFDE49594059BFC6DE55CFCE

feegrant config:

feegrants:
                granter: kujira1vkje22mayn72r0a7kna6agv0sqm6k94ry9k6dd
                external_granter: true
                grantees:
                    - default

json:

    {
      "type": "tx",
      "attributes": [
        {
          "key": "fee",
          "value": "3717ukuji",
          "index": true
        },
        {
          "key": "fee_payer",
          "value": "kujira1vkje22mayn72r0a7kna6agv0sqm6k94ry9k6dd",
          "index": true
        }
      ]
    },

@KyleMoser KyleMoser marked this pull request as ready for review January 22, 2024 19:11
Copy link
Member

@jtieri jtieri left a comment

Choose a reason for hiding this comment

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

Mostly just had a bunch of nit picks around logging and our style guide.

One question I do have though is if the race condition that is being detected in the test case is something within our control to fix?

cmd/feegrant.go Outdated
}

if delete {
fmt.Printf("Deleting %s feegrant configuration\n", chain)
a.log.Info("deleting feegrant configuration", zap.String("chain", chain))
Copy link
Member

Choose a reason for hiding this comment

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

nit: logs should begin with an uppercase letter https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

cmd/feegrant.go Outdated
@@ -190,7 +205,7 @@ func feegrantBasicGrantsCmd(a *appState) *cobra.Command {

granterAcc, err := prov.AccountFromKeyOrAddress(keyNameOrAddress)
if err != nil {
fmt.Printf("Error retrieving account from key '%s'\n", keyNameOrAddress)
a.log.Error("unknown account", zap.String("key or address", keyNameOrAddress))
Copy link
Member

Choose a reason for hiding this comment

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

nit: logs should begin with an uppercase letter.

Also, should we log the returned error here as well?

if isValidGrant(feegrantAllowance.(*feegrant.BasicAllowance)) {
validGrants = append(validGrants, grant)
}
default:
fmt.Printf("Ignoring grant type %s for granter %s and grantee %s\n", grant.Allowance.TypeUrl, grant.Granter, grant.Grantee)
cc.log.Debug("ignoring grant",
Copy link
Member

Choose a reason for hiding this comment

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

nit: logs should begin with an uppercase letter

@@ -97,7 +99,10 @@ func (cc *CosmosProvider) GetGranteeValidBasicGrants(granteeKey string) ([]*feeg
validGrants = append(validGrants, grant)
}
default:
fmt.Printf("Ignoring grant type %s for granter %s and grantee %s\n", grant.Allowance.TypeUrl, grant.Granter, grant.Grantee)
cc.log.Debug("ignoring grant",
Copy link
Member

Choose a reason for hiding this comment

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

nit: logs should begin with an uppercase letter

grantMsg, err := cc.getMsgGrantBasicAllowance(granterAcc, granteeAcc)
if err != nil {
return nil, err
}
msgs = append(msgs, grantMsg)
} else if !hasGrant {
cc.log.Warn("Missing feegrant", zap.String("external granter", granterAddr), zap.String("grantee", granteeAddr))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

return nil, err
} else if txResp != nil && txResp.TxResponse != nil && txResp.TxResponse.Code != 0 {
fmt.Printf("Submitting grants for granter %s failed. Code: %d, TX hash: %s\n", granterKey, txResp.TxResponse.Code, txResp.TxResponse.TxHash)
cc.log.Warn("Feegrant TX failed", zap.String("TX hash", txResp.TxResponse.TxHash), zap.Uint32("code", txResp.TxResponse.Code))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

return nil, fmt.Errorf("could not configure feegrant for granter %s", granterKey)
}

fmt.Printf("TX succeeded, %d new grants configured, %d grants already in place. TX hash: %s\n", grantsNeeded, numGrantees-grantsNeeded, txResp.TxResponse.TxHash)
cc.log.Info("Feegrant succeeded", zap.Int("new grants", grantsNeeded), zap.Int("existing grants", numGrantees-grantsNeeded), zap.String("TX hash", txResp.TxResponse.TxHash))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

if granterKey == "" {
granterKey = cc.PCfg.Key
}
granterAddr, err := cc.GetKeyAddressForKey(granterKey)
if err != nil {
fmt.Printf("ChainClient FeeGranter misconfiguration: %s", err.Error())
cc.log.Error("Unknown granter", zap.String("key name", granterKey))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

if granterKey == "" {
granterKey = cc.PCfg.Key
}

granterAddr, err := cc.GetKeyAddressForKey(granterKey)
if err != nil {
fmt.Printf("ChainClient FeeGranter misconfiguration: %s", err.Error())
cc.log.Error("Unknown granter", zap.String("key name", granterKey))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

return err
}

for _, grantee := range cc.PCfg.FeeGrants.ManagedGrantees {
granteeAddr, err := cc.GetKeyAddressForKey(grantee)

if err != nil {
fmt.Printf("Misconfiguration for grantee %s. Error: %s\n", grantee, err.Error())
cc.log.Error("Unknown grantee", zap.String("key name", grantee))
Copy link
Member

Choose a reason for hiding this comment

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

nit: log field names should be snake_case https://github.com/cosmos/relayer/blob/main/docs/logging.md#usage

@KyleMoser
Copy link
Contributor Author

Mostly just had a bunch of nit picks around logging and our style guide.

One question I do have though is if the race condition that is being detected in the test case is something within our control to fix?

Thanks, I will fix those logs tonight. No, the race condition cannot be fixed without patching the SDK. Fortunately, the race condition only affects tests, it will not impact rly.

@jtieri
Copy link
Member

jtieri commented Jan 24, 2024

Mostly just had a bunch of nit picks around logging and our style guide.
One question I do have though is if the race condition that is being detected in the test case is something within our control to fix?

Thanks, I will fix those logs tonight. No, the race condition cannot be fixed without patching the SDK. Fortunately, the race condition only affects tests, it will not impact rly.

That's what i thought you had mentioned before but wasn't 100% sure, figured I would ask!

Since the remaining comments I had were all regarding logs I'll just approve this so you aren't blocked by me later when you make your changes.

Copy link
Member

@jtieri jtieri left a comment

Choose a reason for hiding this comment

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

🚢 🚢 🚢

@agouin agouin merged commit 7cb083c into cosmos:main Jan 29, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants