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

Optimizable isModuleAccount Implementation #775

Open
Hellobloc opened this issue Dec 2, 2024 · 1 comment
Open

Optimizable isModuleAccount Implementation #775

Hellobloc opened this issue Dec 2, 2024 · 1 comment

Comments

@Hellobloc
Copy link

The current implementation of isModuleAccount relie on iterating through knownModules to determine whether an address is a module account.

func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool {
for _, moduleName := range k.knownModules {
account := k.accountKeeper.GetModuleAccount(ctx, moduleName)
if account == nil {
continue
}
if account.GetAddress().Equals(addr) {
return true
}
}
return false
}

However, this approach has two notable drawbacks. First, the use of loop iteration for validation can be resource-intensive. Second, since knownModules is a configuration parameter initialized with the keeper, any updates introducing new modules might lead to omissions.

Given these considerations, it would be more efficient and reliable to determine whether an address is a module account by directly checking its account type.

func (k Keeper) isModuleAccount(ctx sdk.Context, addr sdk.AccAddress) bool {
	acc := k.authKeeper.GetAccount(ctx, addr)
	if acc == nil {
		return false
	}
	_, ok := acc.(authtypes.ModuleAccountI)
	return ok
}
@pr0n00gler
Copy link
Collaborator

Hey-hey, seems like it's a decent change. What do you think of opening a PR?

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

No branches or pull requests

2 participants