-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: main
Are you sure you want to change the base?
Conversation
} | ||
ext := NewExtensionExecuteAdapter() | ||
for _, e := range extensions { | ||
if err := ext.RegisterExtension(newDeps(), e); err != nil { |
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.
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) |
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.
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) { |
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.
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() { |
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.
here the protos for the extension are registered
if len(e.handlers) != 0 { | ||
messageName := MessageName(msg) | ||
handler, ok := e.handlers[messageName] | ||
if ok { |
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.
when a matching extension handler exists, it is used. Otherwise, fall though to the account handlers
dbc9908
to
f3f1dda
Compare
} | ||
implementation.RegisterExecuteHandler(reg, f.Init) | ||
implementation.RegisterExecuteHandler(reg, f.GrantAllowance) | ||
implementation.RegisterExecuteHandler(reg, f.UseGrantedFees) |
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.
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
f3f1dda
to
069ed78
Compare
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
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
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
} | ||
|
||
// MigrateFromLegacy migrate data for the account from x/feegrant module | ||
func (f *Feegrant) MigrateFromLegacy(ctx context.Context) 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.
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) |
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 is a big downsite of migrating to xaccounts. Now we have to check for an existing xaccount all the time.
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 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
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
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
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
cc @testinginprod could you check? |
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:
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...
!
in the type prefix if API or client breaking changeCHANGELOG.md
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...