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(rollapp): track registered rollapp denoms in separate store #1344

Merged
merged 6 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 5 additions & 6 deletions app/upgrades/v4/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,11 @@ func migrateIncentivesParams(ctx sdk.Context, ik *incentiveskeeper.Keeper) {

func ConvertOldRollappToNew(oldRollapp rollapptypes.Rollapp) rollapptypes.Rollapp {
keruch marked this conversation as resolved.
Show resolved Hide resolved
return rollapptypes.Rollapp{
RollappId: oldRollapp.RollappId,
Owner: oldRollapp.Owner,
GenesisState: oldRollapp.GenesisState,
ChannelId: oldRollapp.ChannelId,
Frozen: oldRollapp.Frozen,
RegisteredDenoms: oldRollapp.RegisteredDenoms,
RollappId: oldRollapp.RollappId,
Owner: oldRollapp.Owner,
GenesisState: oldRollapp.GenesisState,
ChannelId: oldRollapp.ChannelId,
Frozen: oldRollapp.Frozen,
// TODO: regarding missing data - https://github.com/dymensionxyz/dymension/issues/986
VmType: rollapptypes.Rollapp_EVM, // placeholder data
Metadata: &rollapptypes.RollappMetadata{
Expand Down
9 changes: 4 additions & 5 deletions app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ func (s *UpgradeTestSuite) seedRollapps(numRollapps int) []rollapptypes.Rollapp
for i := range numRollapps {
rollappID := rollappIDFromIdx(i)
rollapp := rollapptypes.Rollapp{
RollappId: rollappID,
Owner: sample.AccAddressFromSecret(rollappID),
GenesisState: rollapptypes.RollappGenesisState{},
ChannelId: fmt.Sprintf("channel-%d", i),
RegisteredDenoms: []string{"denom1", "denom2"},
RollappId: rollappID,
Owner: sample.AccAddressFromSecret(rollappID),
GenesisState: rollapptypes.RollappGenesisState{},
ChannelId: fmt.Sprintf("channel-%d", i),
}
rollapps[i] = rollapp
}
Expand Down
6 changes: 6 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ message GenesisState {
// LivenessEvents are scheduled upcoming liveness events
repeated LivenessEvent livenessEvents = 7 [(gogoproto.nullable) = false];
repeated App appList = 8 [(gogoproto.nullable) = false];
repeated RollappRegisteredDenoms registeredDenoms = 9 [(gogoproto.nullable) = false];
}

message RollappRegisteredDenoms {
string rollapp_id = 1;
repeated string denoms = 2 [(gogoproto.nullable) = false];
}
13 changes: 13 additions & 0 deletions proto/dymensionxyz/dymension/rollapp/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ service Query {
option (google.api.http).get =
"/dymensionxyz/dymension/rollapp/state_info/{rollappId}/{index}";
}

// Queries a list of registered denoms for the rollapp.
rpc RegisteredDenoms(QueryRegisteredDenomsRequest) returns (QueryRegisteredDenomsResponse) {
option (google.api.http).get = "/dymensionxyz/dymension/rollapp/registered_denoms";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
Expand Down Expand Up @@ -123,3 +128,11 @@ message QueryGetStateInfoRequest {
message QueryGetStateInfoResponse {
StateInfo stateInfo = 1 [ (gogoproto.nullable) = false ];
}

message QueryRegisteredDenomsRequest {
string rollappId = 1;
}

message QueryRegisteredDenomsResponse {
repeated string denoms = 1;
}
4 changes: 2 additions & 2 deletions proto/dymensionxyz/dymension/rollapp/rollapp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ message Rollapp {
string channel_id = 8;
// frozen is a boolean that indicates if the rollapp is frozen.
bool frozen = 9;
// registeredDenoms is a list of registered denom bases on this rollapp
repeated string registeredDenoms = 10;

reserved 10;
// metadata is the rollapp metadata
RollappMetadata metadata = 11;
// genesis_info keeps immutable rollapp fields
Expand Down
20 changes: 13 additions & 7 deletions x/denommetadata/ibc_middleware.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package denommetadata

import (
. "slices"

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -148,11 +146,15 @@ func (im IBCModule) OnAcknowledgementPacket(
return gerrc.ErrNotFound
}

if !Contains(rollapp.RegisteredDenoms, dm.Base) {
has, err := im.rollappKeeper.HasRegisteredDenom(ctx, rollapp.RollappId, dm.Base)
if err != nil {
return errorsmod.Wrapf(errortypes.ErrKeyNotFound, "check if rollapp has registered denom: %s", err.Error())
}
if !has {
// add the new token denom base to the list of rollapp's registered denoms
rollapp.RegisteredDenoms = append(rollapp.RegisteredDenoms, dm.Base)

im.rollappKeeper.SetRollapp(ctx, *rollapp)
if err = im.rollappKeeper.SetRegisteredDenom(ctx, rollapp.RollappId, dm.Base); err != nil {
return errorsmod.Wrapf(errortypes.ErrKeyNotFound, "set registered denom: %s", err.Error())
}
}

return im.IBCModule.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
Expand Down Expand Up @@ -229,7 +231,11 @@ func (m *ICS4Wrapper) SendPacket(
// 2. We parse the IBC denom trace into IBC denom hash and prepend it with "ibc/" to get the baseDenom
baseDenom := transfertypes.ParseDenomTrace(packet.Denom).IBCDenom()

if Contains(rollapp.RegisteredDenoms, baseDenom) {
has, err := m.rollappKeeper.HasRegisteredDenom(ctx, rollapp.RollappId, baseDenom)
if err != nil {
return 0, errorsmod.Wrapf(errortypes.ErrKeyNotFound, "check if rollapp has registered denom: %s", err.Error())
}
if has {
return m.ICS4Wrapper.SendPacket(ctx, chanCap, sourcePort, sourceChannel, timeoutHeight, timeoutTimestamp, data)
}

Expand Down
Loading
Loading