Skip to content

Commit

Permalink
chore: remove Trace type from protos, replace with Hop (#6728)
Browse files Browse the repository at this point in the history
* chore: remove Trace type from protos, replace with Hop

* nit: remove trace file and move functionality to denom.
  • Loading branch information
DimitrisJim authored Jul 1, 2024
1 parent ccd32c5 commit 589cdd4
Show file tree
Hide file tree
Showing 27 changed files with 403 additions and 672 deletions.
4 changes: 2 additions & 2 deletions e2e/tests/transfer/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (s *TransferForwardingTestSuite) TestForwarding_WithLastChainBeingICS20v1_S

t.Run("packets are relayed from A to B to C", func(t *testing.T) {
chainCDenom := transfertypes.NewDenom(chainADenom,
transfertypes.NewTrace(channelBtoC.Counterparty.PortID, channelBtoC.Counterparty.ChannelID),
transfertypes.NewTrace(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID),
transfertypes.NewHop(channelBtoC.Counterparty.PortID, channelBtoC.Counterparty.ChannelID),
transfertypes.NewHop(channelAtoB.Counterparty.PortID, channelAtoB.Counterparty.ChannelID),
)

s.AssertPacketRelayed(ctx, chainA, channelAtoB.PortID, channelAtoB.ChannelID, 1)
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/wasm/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (s *GrandpaTestSuite) TestMsgTransfer_Succeeds_GrandpaContract() {
s.Require().True(cosmosUserStakeBal.Equal(finalStakeBal))

// Verify cosmos user's final "unit" balance
denom := transfertypes.NewDenom("UNIT", transfertypes.NewTrace("transfer", "channel-0"))
denom := transfertypes.NewDenom("UNIT", transfertypes.NewHop("transfer", "channel-0"))
cosmosUserUnitBal, err := cosmosChain.GetBalance(ctx, cosmosUser.FormattedAddress(), denom.IBCDenom())
s.Require().NoError(err)
s.Require().True(cosmosUserUnitBal.Equal(amountUnits))
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/callbacks/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (s *CallbacksTestSuite) TestTransferRecvPacketReplayProtection() {
}

// save initial balance of receiver
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
initialBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom())

// execute the transfer
Expand Down Expand Up @@ -319,7 +319,7 @@ func (s *CallbacksTestSuite) ExecuteFailedTransfer(memo string) {
// record the balance of the escrow address before the transfer
escrowBalance := GetSimApp(s.chainA).BankKeeper.GetBalance(s.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom)
// record the balance of the receiving address before the transfer
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
receiverBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom())

amount := ibctesting.TestCoin
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/callbacks/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func (s *CallbacksTestSuite) ExecuteTransfer(memo string) {
// record the balance of the escrow address before the transfer
escrowBalance := GetSimApp(s.chainA).BankKeeper.GetBalance(s.chainA.GetContext(), escrowAddress, sdk.DefaultBondDenom)
// record the balance of the receiving address before the transfer
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
denom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID))
receiverBalance := GetSimApp(s.chainB).BankKeeper.GetBalance(s.chainB.GetContext(), s.chainB.SenderAccount.GetAddress(), denom.IBCDenom())

amount := ibctesting.TestCoin
Expand Down
6 changes: 3 additions & 3 deletions modules/apps/transfer/ibc_module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
initialPacketData = types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")),
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: ibctesting.TestCoin.Amount.String(),
},
},
Expand Down Expand Up @@ -850,7 +850,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {
initialPacketData = types.FungibleTokenPacketDataV2{
Tokens: []types.Token{
{
Denom: types.NewDenom(ibctesting.TestCoin.Denom, []types.Trace{{}}...),
Denom: types.NewDenom(ibctesting.TestCoin.Denom, []types.Hop{{}}...),
Amount: ibctesting.TestCoin.Amount.String(),
},
},
Expand All @@ -861,7 +861,7 @@ func (suite *TransferTestSuite) TestPacketDataUnmarshalerInterface() {

data = initialPacketData.(types.FungibleTokenPacketDataV2).GetBytes()
},
errors.New("invalid token denom: invalid trace: invalid portID: identifier cannot be blank: invalid identifier"),
errors.New("invalid token denom: invalid trace: invalid hop source port ID : identifier cannot be blank: invalid identifier"),
},
{
"failure: invalid packet data",
Expand Down
14 changes: 7 additions & 7 deletions modules/apps/transfer/internal/packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestUnmarshalPacketData(t *testing.T) {
packetData := types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")),
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, "sender", "receiver", "", emptyForwardingPacketData)
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0")),
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand All @@ -115,7 +115,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom/withslash", types.NewTrace("transfer", "channel-0")),
Denom: types.NewDenom("atom/withslash", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand All @@ -127,7 +127,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom/", types.NewTrace("transfer", "channel-0")),
Denom: types.NewDenom("atom/", types.NewHop("transfer", "channel-0")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand All @@ -139,7 +139,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom/pool", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1")),
Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand All @@ -151,7 +151,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer-custom", "channel-2")),
Denom: types.NewDenom("atom", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand All @@ -163,7 +163,7 @@ func TestPacketV1ToPacketV2(t *testing.T) {
types.NewFungibleTokenPacketDataV2(
[]types.Token{
{
Denom: types.NewDenom("atom/pool", types.NewTrace("transfer", "channel-0"), types.NewTrace("transfer", "channel-1"), types.NewTrace("transfer-custom", "channel-2")),
Denom: types.NewDenom("atom/pool", types.NewHop("transfer", "channel-0"), types.NewHop("transfer", "channel-1"), types.NewHop("transfer-custom", "channel-2")),
Amount: "1000",
},
}, sender, receiver, "", emptyForwardingPacketData),
Expand Down
16 changes: 8 additions & 8 deletions modules/apps/transfer/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (
)

func (suite *KeeperTestSuite) TestGenesis() {
getTrace := func(index uint) types.Trace {
return types.NewTrace("transfer", fmt.Sprintf("channelToChain%d", index))
getHop := func(index uint) types.Hop {
return types.NewHop("transfer", fmt.Sprintf("channelToChain%d", index))
}

var (
denoms types.Denoms
escrows sdk.Coins
traceAndEscrowAmounts = []struct {
trace []types.Trace
trace []types.Hop
escrow string
}{
{[]types.Trace{getTrace(0)}, "10"},
{[]types.Trace{getTrace(1), getTrace(0)}, "100000"},
{[]types.Trace{getTrace(2), getTrace(1), getTrace(0)}, "10000000000"},
{[]types.Trace{getTrace(3), getTrace(2), getTrace(1), getTrace(0)}, "1000000000000000"},
{[]types.Trace{getTrace(4), getTrace(3), getTrace(2), getTrace(1), getTrace(0)}, "100000000000000000000"},
{[]types.Hop{getHop(0)}, "10"},
{[]types.Hop{getHop(1), getHop(0)}, "100000"},
{[]types.Hop{getHop(2), getHop(1), getHop(0)}, "10000000000"},
{[]types.Hop{getHop(3), getHop(2), getHop(1), getHop(0)}, "1000000000000000"},
{[]types.Hop{getHop(4), getHop(3), getHop(2), getHop(1), getHop(0)}, "100000000000000000000"},
}
)

Expand Down
28 changes: 14 additions & 14 deletions modules/apps/transfer/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() {
"success: correct ibc denom",
func() {
expDenom = types.NewDenom(
"uatom", //nolint:goconst
types.NewTrace("transfer", "channelToA"), //nolint:goconst
types.NewTrace("transfer", "channelToB"), //nolint:goconst
"uatom", //nolint:goconst
types.NewHop("transfer", "channelToA"), //nolint:goconst
types.NewHop("transfer", "channelToB"), //nolint:goconst
)
suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), expDenom)

Expand All @@ -43,9 +43,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() {
"success: correct hex hash",
func() {
expDenom = types.NewDenom(
"uatom", //nolint:goconst
types.NewTrace("transfer", "channelToA"), //nolint:goconst
types.NewTrace("transfer", "channelToB"), //nolint:goconst
"uatom", //nolint:goconst
types.NewHop("transfer", "channelToA"), //nolint:goconst
types.NewHop("transfer", "channelToB"), //nolint:goconst
)
suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), expDenom)

Expand All @@ -68,9 +68,9 @@ func (suite *KeeperTestSuite) TestQueryDenom() {
"failure: not found denom trace",
func() {
expDenom = types.NewDenom(
"uatom", //nolint:goconst
types.NewTrace("transfer", "channelToA"), //nolint:goconst
types.NewTrace("transfer", "channelToB"), //nolint:goconst
"uatom", //nolint:goconst
types.NewHop("transfer", "channelToA"), //nolint:goconst
types.NewHop("transfer", "channelToB"), //nolint:goconst
)

req = &types.QueryDenomRequest{
Expand Down Expand Up @@ -124,8 +124,8 @@ func (suite *KeeperTestSuite) TestQueryDenoms() {
"success",
func() {
expDenoms = append(expDenoms, types.NewDenom("uatom"))
expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewTrace("transfer", "channelToB")))
expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewTrace("transfer", "channelToA"), types.NewTrace("transfer", "channelToB")))
expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewHop("transfer", "channelToB")))
expDenoms = append(expDenoms, types.NewDenom("uatom", types.NewHop("transfer", "channelToA"), types.NewHop("transfer", "channelToB")))

for _, trace := range expDenoms {
suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), trace)
Expand Down Expand Up @@ -171,7 +171,7 @@ func (suite *KeeperTestSuite) TestQueryParams() {
}

func (suite *KeeperTestSuite) TestQueryDenomHash() {
reqDenom := types.NewDenom("uatom", types.NewTrace("transfer", "channelToA"), types.NewTrace("transfer", "channelToB"))
reqDenom := types.NewDenom("uatom", types.NewHop("transfer", "channelToA"), types.NewHop("transfer", "channelToB"))

var (
req *types.QueryDenomHashRequest
Expand Down Expand Up @@ -333,7 +333,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() {
{
"valid ibc denom with escrow amount > 2^63",
func() {
denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace("transfer", "channel-0"))
denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop("transfer", "channel-0"))

suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), denom)
expEscrowAmount, ok := sdkmath.NewIntFromString("100000000000000000000")
Expand All @@ -349,7 +349,7 @@ func (suite *KeeperTestSuite) TestTotalEscrowForDenom() {
{
"valid ibc denom treated as native denom",
func() {
denom := types.NewDenom(sdk.DefaultBondDenom, types.NewTrace("transfer", "channel-0"))
denom := types.NewDenom(sdk.DefaultBondDenom, types.NewHop("transfer", "channel-0"))

req = &types.QueryTotalEscrowForDenomRequest{
Denom: denom.IBCDenom(),
Expand Down
20 changes: 10 additions & 10 deletions modules/apps/transfer/keeper/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49")),
transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49")),
},
},
{
Expand All @@ -91,7 +91,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49"), transfertypes.NewTrace("transfer", "channel-32"), transfertypes.NewTrace("transfer", "channel-2")),
transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49"), transfertypes.NewHop("transfer", "channel-32"), transfertypes.NewHop("transfer", "channel-2")),
},
},
{
Expand Down Expand Up @@ -119,10 +119,10 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("apple", transfertypes.NewTrace("transfer", "channel-0")),
transfertypes.NewDenom("cucumber", transfertypes.NewTrace("transfer", "channel-102"), transfertypes.NewTrace("transfer", "channel-0")),
transfertypes.NewDenom("pineapple", transfertypes.NewTrace("transfer", "channel-0")),
transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-49")),
transfertypes.NewDenom("apple", transfertypes.NewHop("transfer", "channel-0")),
transfertypes.NewDenom("cucumber", transfertypes.NewHop("transfer", "channel-102"), transfertypes.NewHop("transfer", "channel-0")),
transfertypes.NewDenom("pineapple", transfertypes.NewHop("transfer", "channel-0")),
transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-49")),
},
},

Expand All @@ -136,7 +136,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("gamm/pool/1", transfertypes.NewTrace("transfer", "channel-0")),
transfertypes.NewDenom("gamm/pool/1", transfertypes.NewHop("transfer", "channel-0")),
},
},
{
Expand All @@ -149,7 +149,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("erc/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", transfertypes.NewTrace("transfer", "channel-149")),
transfertypes.NewDenom("erc/0x85bcBCd7e79Ec36f4fBBDc54F90C643d921151AA", transfertypes.NewHop("transfer", "channel-149")),
},
},
{
Expand All @@ -162,7 +162,7 @@ func (suite *KeeperTestSuite) TestMigratorMigrateDenomTraceToDenom() {
})
},
transfertypes.Denoms{
transfertypes.NewDenom("uatom", transfertypes.NewTrace("transfer", "channel-0"), transfertypes.NewTrace("customport", "channel-7")),
transfertypes.NewDenom("uatom", transfertypes.NewHop("transfer", "channel-0"), transfertypes.NewHop("customport", "channel-7")),
},
},
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func (suite *KeeperTestSuite) TestMigrateTotalEscrowForDenom() {
"success: valid ibc denom escrowed in one channel",
func() {
escrowAddress := transfertypes.GetEscrowAddress(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID)
voucherDenom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewTrace(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
voucherDenom := transfertypes.NewDenom(sdk.DefaultBondDenom, transfertypes.NewHop(path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID))
coin := sdk.NewCoin(voucherDenom.IBCDenom(), sdkmath.NewInt(100))
denom = voucherDenom.IBCDenom()

Expand Down
6 changes: 2 additions & 4 deletions modules/apps/transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ func (k Keeper) unwindHops(ctx sdk.Context, msg *types.MsgTransfer) (*types.MsgT
if token.Denom.IsNative() {
return nil, errorsmod.Wrap(types.ErrInvalidForwarding, "cannot unwind a native token")
}
var unwindHops []types.Hop

// remove the first hop in denom as it is the current port/channel on this chain
for _, trace := range token.Denom.Trace[1:] {
unwindHops = append(unwindHops, types.NewHop(trace.PortId, trace.ChannelId)) //nolint: gosimple
}
unwindHops := token.Denom.Trace[1:]

// Update message fields.
msg.SourcePort, msg.SourceChannel = token.Denom.Trace[0].PortId, token.Denom.Trace[0].ChannelId
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/transfer/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (suite *KeeperTestSuite) TestUpdateParams() {
func (suite *KeeperTestSuite) TestUnwindHops() {
var msg *types.MsgTransfer
var path *ibctesting.Path
denom := types.NewDenom(ibctesting.TestCoin.Denom, types.NewTrace(ibctesting.MockPort, "channel-0"), types.NewTrace(ibctesting.MockPort, "channel-1"))
denom := types.NewDenom(ibctesting.TestCoin.Denom, types.NewHop(ibctesting.MockPort, "channel-0"), types.NewHop(ibctesting.MockPort, "channel-1"))
coins := sdk.NewCoins(sdk.NewCoin(denom.IBCDenom(), ibctesting.TestCoin.Amount))
testCases := []struct {
name string
Expand All @@ -275,7 +275,7 @@ func (suite *KeeperTestSuite) TestUnwindHops() {
{
"success: multiple unwind hops",
func() {
denom.Trace = append(denom.Trace, types.NewTrace(ibctesting.MockPort, "channel-2"), types.NewTrace(ibctesting.MockPort, "channel-3"))
denom.Trace = append(denom.Trace, types.NewHop(ibctesting.MockPort, "channel-2"), types.NewHop(ibctesting.MockPort, "channel-3"))
coins = sdk.NewCoins(sdk.NewCoin(denom.IBCDenom(), ibctesting.TestCoin.Amount))
suite.chainA.GetSimApp().TransferKeeper.SetDenom(suite.chainA.GetContext(), denom)
msg.Tokens = coins
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (k Keeper) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, data t
// sender chain is the source, mint vouchers

// since SendPacket did not prefix the denomination, we must add the destination port and channel to the trace
trace := []types.Trace{types.NewTrace(packet.DestinationPort, packet.DestinationChannel)}
trace := []types.Hop{types.NewHop(packet.DestinationPort, packet.DestinationChannel)}
token.Denom.Trace = append(trace, token.Denom.Trace...)

if !k.HasDenom(ctx, token.Denom.Hash()) {
Expand Down
Loading

0 comments on commit 589cdd4

Please sign in to comment.