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

fix(iro): removed ibc filter for VFC creation #1302

Merged
merged 3 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion x/denommetadata/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ func (am AppModule) RegisterInvariants(ir sdk.InvariantRegistry) {
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, gs json.RawMessage) []abci.ValidatorUpdate {
am.bankKeeper.IterateAllDenomMetaData(ctx, func(metadata banktypes.Metadata) bool {
// run hooks for each denom metadata, thus `x/denommetadata` genesis init order must be after `x/bank` genesis init

err := am.keeper.GetHooks().AfterDenomMetadataCreation(ctx, metadata)
if err != nil {
panic(err) // error at genesis level should be reported by panic
Expand Down
14 changes: 4 additions & 10 deletions x/rollapp/genesisbridge/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,12 @@ func compareGenesisAccounts(raCommitted *types.GenesisAccounts, gbData []types.G
}

func (w IBCModule) registerDenomMetadata(ctx sdk.Context, rollappID, channelID string, m banktypes.Metadata) (string, error) {
// Set the trace for the ibc denom
trace := uibc.GetForeignDenomTrace(channelID, m.Base)
m.Base = trace.IBCDenom()

if w.denomKeeper.HasDenomMetadata(ctx, m.GetBase()) {
return "", fmt.Errorf("denom metadata already exists for base: %s", m.GetBase())
}

w.transferKeeper.SetDenomTrace(ctx, trace)

/*
Change the base to the ibc denom, and add an alias to the original
*/
// Change the base to the ibc denom, and add an alias to the original
m.Base = trace.IBCDenom()
m.Description = fmt.Sprintf("auto-generated ibc denom for rollapp: base: %s: rollapp: %s", m.GetBase(), rollappID)
for i, u := range m.DenomUnits {
if u.Exponent == 0 {
Expand All @@ -229,7 +223,7 @@ func (w IBCModule) registerDenomMetadata(ctx sdk.Context, rollappID, channelID s
return "", errorsmod.Wrap(errors.Join(gerrc.ErrInvalidArgument, err), "metadata validate")
}

// We go by the denom keeper instead of calling bank directly, as something might happen in-between
// We go by the denom keeper instead of calling bank directly, so denom creation hooks are called
err := w.denomKeeper.CreateDenomMetadata(ctx, m)
if err != nil {
return "", errorsmod.Wrap(err, "create denom metadata")
Expand Down
13 changes: 4 additions & 9 deletions x/vfc/hooks/denom_metadata_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package hooks

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand All @@ -12,8 +11,6 @@ import (

var _ denommetadatamoduletypes.DenomMetadataHooks = VirtualFrontierBankContractRegistrationHook{}

const ibcDenomPrefix = "ibc/"

type VirtualFrontierBankContractRegistrationHook struct {
evmKeeper evmkeeper.Keeper
}
Expand All @@ -25,13 +22,11 @@ func NewVirtualFrontierBankContractRegistrationHook(evmKeeper evmkeeper.Keeper)
}
}

// Deploy the virtual frontier bank contract for the denom.
// Error, if any, no state transition will be made.
mtsitrin marked this conversation as resolved.
Show resolved Hide resolved
func (v VirtualFrontierBankContractRegistrationHook) AfterDenomMetadataCreation(ctx sdk.Context, newDenomMetadata banktypes.Metadata) error {
if strings.HasPrefix(strings.ToLower(newDenomMetadata.Base), ibcDenomPrefix) { // only deploy for IBC denom.
// Deploy the virtual frontier bank contract for the new IBC denom.
// Error, if any, no state transition will be made.
if err := v.evmKeeper.DeployVirtualFrontierBankContractForBankDenomMetadataRecord(ctx, newDenomMetadata.Base); err != nil {
return fmt.Errorf("deploy virtual frontier bank contract for IBC denom %s: %w", newDenomMetadata.Base, err)
}
if err := v.evmKeeper.DeployVirtualFrontierBankContractForBankDenomMetadataRecord(ctx, newDenomMetadata.Base); err != nil {
return fmt.Errorf("deploy virtual frontier bank contract for IBC denom %s: %w", newDenomMetadata.Base, err)
}

return nil
Expand Down
10 changes: 6 additions & 4 deletions x/vfc/hooks/denom_metadata_hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ func (suite *HooksTestSuite) TestHookOperation_AfterDenomMetadataCreation() {
wantErr bool
}{
{
name: "ignored - Deploy for non-IBC",
name: "accepted - Deploy for non-IBC",
denomMetadata: denomAdym,
wantNotFound: []string{denomAdym.Base, denomWei.Base, denomIbcAtom.Base, denomIbcOsmo.Base, denomMixedCaseIbcTia.Base},
wantFound: []string{denomAdym.Base},
wantNotFound: []string{denomWei.Base, denomIbcAtom.Base, denomIbcOsmo.Base, denomMixedCaseIbcTia.Base},
},
{
name: "ignored - Only deploy the denom which passed into the hook (case non-IBC)",
name: "accepted - Only deploy the denom which passed into the hook (case non-IBC)",
denomMetadata: denomWei,
wantNotFound: []string{denomAdym.Base, denomWei.Base, denomIbcAtom.Base, denomIbcOsmo.Base, denomMixedCaseIbcTia.Base},
wantFound: []string{denomWei.Base},
wantNotFound: []string{denomAdym.Base, denomIbcAtom.Base, denomIbcOsmo.Base, denomMixedCaseIbcTia.Base},
},
{
name: "accepted - Only deploy the denom which passed into the hook (case IBC)",
Expand Down
Loading