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

[Spike] feegrants as extension to xaccounts #22252

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

alpe
Copy link
Contributor

@alpe alpe commented Oct 14, 2024

Description

Another option to #22236 that works without composition or a new account type.
The feegrants are a handles as a cross cutting concern to all xaccount types.

As in the other spike, not implemented:

  • query example
  • use cached context on queries
  • legacy data migration
  • extension config updates
  • state export/import is done via xaccounts keeper. Not super readable as binary key/value pairs but will work
  • non conflicting store prefix
  • tests, doc, ...

Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

}
ext := NewExtensionExecuteAdapter()
for _, e := range extensions {
if err := ext.RegisterExtension(newDeps(), e); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here all the extensions are registered with their proto msg handlers collected

@@ -79,6 +95,10 @@ func newImplementation(schemaBuilder *collections.SchemaBuilder, account Account
if err != nil {
return Implementation{}, err
}
executeHandler, err = ext.ExtendHandlers(executeHandler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The xaccount handlers are decorated by the extension adapter

}

router.handlers[reqName] = func(ctx context.Context, executeRequest transaction.Msg) (executeResponse transaction.Msg, err error) {
fn := func(ctx context.Context, executeRequest transaction.Msg) (executeResponse transaction.Msg, err error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the error is returned in this helper. the registry takes care of the duplicate prevention and internal state

@@ -454,4 +456,7 @@ func registerToInterfaceRegistry(ir InterfaceRegistry, accMap map[string]impleme
ir.RegisterImplementations(msgInterfaceType, query.RequestSchema.New(), query.ResponseSchema.New())
}
}
for h := range extensions.HandlerSchemas() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here the protos for the extension are registered

if len(e.handlers) != 0 {
messageName := MessageName(msg)
handler, ok := e.handlers[messageName]
if ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when a matching extension handler exists, it is used. Otherwise, fall though to the account handlers

@alpe alpe force-pushed the alex/21747_feegrant_spike2 branch from dbc9908 to f3f1dda Compare October 14, 2024 10:24
}
implementation.RegisterExecuteHandler(reg, f.Init)
implementation.RegisterExecuteHandler(reg, f.GrantAllowance)
implementation.RegisterExecuteHandler(reg, f.UseGrantedFees)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

personal preference: I prefer all the wiring in the constructor. People would look here when doing copy paste for custom types. Methods can easily be missed when not required by an interface

@alpe alpe force-pushed the alex/21747_feegrant_spike2 branch from f3f1dda to 069ed78 Compare October 14, 2024 10:29
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
anypb "google.golang.org/protobuf/types/known/anypb"
io "io"
reflect "reflect"

Check notice

Code scanning / CodeQL

Sensitive package import Note

Certain system packages contain functions which may be a possible source of non-determinism
x.Allowance = value.Message().Interface().(*anypb.Any)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.extensions.feegrant.v1.Grant"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.accounts.extensions.feegrant.v1.Grant"))
}
panic(fmt.Errorf("message cosmos.accounts.extensions.feegrant.v1.Grant does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

// MigrateFromLegacy migrate data for the account from x/feegrant module
func (f *Feegrant) MigrateFromLegacy(ctx context.Context) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this method is called right after the account migration

@@ -61,6 +73,26 @@ func NewKeeper(env appmodule.Environment, cdc codec.BinaryCodec, addrCdc address

// GrantAllowance creates a new grant
func (k Keeper) GrantAllowance(ctx context.Context, granter, grantee sdk.AccAddress, feeAllowance feegrant.FeeAllowanceI) error {
migrated, err := k.isXAccount(ctx, granter)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a big downsite of migrating to xaccounts. Now we have to check for an existing xaccount all the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put the check on top as this was quicker to build but it would probably be more efficient to check state in the module first.
fyi: I also had a "migrated accounts" index in the beginning but accounts can be created in xaccounts without migration, so this did not work

x.Granter = value.Interface().(string)
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.feegrant.v1beta1.MsgMigrateAllowances"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.feegrant.v1beta1.MsgMigrateAllowances"))
}
panic(fmt.Errorf("message cosmos.feegrant.v1beta1.MsgMigrateAllowances does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
x.Grants = *clv.list
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.feegrant.v1beta1.MsgMigrateAllowancesResponse"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.feegrant.v1beta1.MsgMigrateAllowancesResponse"))
}
panic(fmt.Errorf("message cosmos.feegrant.v1beta1.MsgMigrateAllowancesResponse does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@julienrbrt
Copy link
Member

cc @testinginprod could you check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants