-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
External feegrants #1338
Conversation
KyleMoser
commented
Nov 20, 2023
- 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)
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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 !!") |
There was a problem hiding this comment.
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?
var granterAddr string | ||
var granterAcc types.AccAddress | ||
var err error |
There was a problem hiding this comment.
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
)
relayer/chains/cosmos/feegrant.go
Outdated
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) |
There was a problem hiding this comment.
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
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. |
@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 :) |
I can confirm this works. relayer address: https://finder.kujira.network/kaiyo-1/address/kujira18xrruhq5r246mwk0yj9elnn3mte8xa9u3ae4pk 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
}
]
}, |
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
relayer/chains/cosmos/feegrant.go
Outdated
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", |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
@@ -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", |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
relayer/chains/cosmos/feegrant.go
Outdated
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)) |
There was a problem hiding this comment.
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢 🚢 🚢