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

[Tunnel] move encoder to tss route #505

Merged
merged 10 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
169 changes: 116 additions & 53 deletions api/band/tunnel/v1beta1/route.pulsar.go

Large diffs are not rendered by default.

444 changes: 191 additions & 253 deletions api/band/tunnel/v1beta1/tunnel.pulsar.go

Large diffs are not rendered by default.

535 changes: 235 additions & 300 deletions api/band/tunnel/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions benchmark/tunnel_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func testBenchmarkTunnel(numTunnels, numSignals, maxSignals int, encoder feedsty
signalDeviations = append(signalDeviations, globalSignalDeviations[signalIdx[j]])
}

err := createNewTunnel(ba, &types.TSSRoute{}, signalDeviations, 1000, encoder)
err := createNewTunnel(ba, &types.TSSRoute{Encoder: encoder}, signalDeviations, 1000)
require.NoError(b, err)
}

Expand Down Expand Up @@ -123,11 +123,10 @@ func createNewTunnel(
route types.RouteI,
signalDeviations []types.SignalDeviation,
interval uint64,
encoder feedstypes.Encoder,
) error {
creator := bandtesting.Alice.Address
tunnel, err := ba.TunnelKeeper.AddTunnel(
ba.Ctx, route, encoder, signalDeviations, interval, creator,
ba.Ctx, route, signalDeviations, interval, creator,
)
if err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions proto/band/tunnel/v1beta1/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ message TSSRoute {
string destination_chain_id = 1 [(gogoproto.customname) = "DestinationChainID"];
// destination_contract_address is the destination contract address
string destination_contract_address = 2;
// encoder is the mode of encoding price data.
band.feeds.v1beta1.Encoder encoder = 3;
}

// TSSPacketReceipt represents a receipt for a TSS packet and implements the PacketReceiptI interface.
Expand Down
16 changes: 7 additions & 9 deletions proto/band/tunnel/v1beta1/tunnel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@ message Tunnel {
uint64 sequence = 2;
// route is the route for delivering the signal prices
google.protobuf.Any route = 3 [(cosmos_proto.accepts_interface) = "RouteI"];
// encoder is the mode of encoding price signal data.
band.feeds.v1beta1.Encoder encoder = 4;
// fee_payer is the address of the fee payer
string fee_payer = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string fee_payer = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// signal_deviations is the list of signal deviations
repeated SignalDeviation signal_deviations = 6 [(gogoproto.nullable) = false];
repeated SignalDeviation signal_deviations = 5 [(gogoproto.nullable) = false];
// interval is the interval for delivering the signal prices
uint64 interval = 7;
uint64 interval = 6;
// total_deposit is the total deposit on the tunnel.
repeated cosmos.base.v1beta1.Coin total_deposit = 8 [
repeated cosmos.base.v1beta1.Coin total_deposit = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(amino.dont_omitempty) = true
];
// is_active is the flag to indicate if the tunnel is active
bool is_active = 9;
bool is_active = 8;
// created_at is the timestamp when the tunnel is created
int64 created_at = 10;
int64 created_at = 9;
// creator is the address of the creator
string creator = 11 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string creator = 10 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// LatestPrices is the type for prices that tunnel produces
Expand Down
7 changes: 2 additions & 5 deletions proto/band/tunnel/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";

import "band/feeds/v1beta1/feeds.proto";
import "band/tunnel/v1beta1/params.proto";
import "band/tunnel/v1beta1/tunnel.proto";

Expand Down Expand Up @@ -54,16 +53,14 @@ message MsgCreateTunnel {
uint64 interval = 2;
// route is the route for delivering the signal prices
google.protobuf.Any route = 3 [(cosmos_proto.accepts_interface) = "Route"];
// encoder is the mode of encoding price signal data.
band.feeds.v1beta1.Encoder encoder = 4;
// initial_deposit is the deposit value that must be paid at tunnel creation.
repeated cosmos.base.v1beta1.Coin initial_deposit = 5 [
repeated cosmos.base.v1beta1.Coin initial_deposit = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(amino.dont_omitempty) = true
];
// creator is the address of the creator.
string creator = 6 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string creator = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}

// MsgCreateTunnelResponse is the response type for the Msg/CreateTunnel RPC method.
Expand Down
2 changes: 1 addition & 1 deletion scripts/tunnel/create_ibc_tunnel.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bandd tx tunnel create-tunnel ibc channel-0 1 1uband 120 ./scripts/tunnel/signal_deviations.json --from requester --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain
bandd tx tunnel create-tunnel ibc channel-0 1uband 120 ./scripts/tunnel/signal_deviations.json --from requester --keyring-backend test --gas-prices 0.0025uband -y --chain-id bandchain
16 changes: 5 additions & 11 deletions x/tunnel/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,26 @@ func GetTxCmdCreateTSSTunnel() *cobra.Command {

func GetTxCmdCreateIBCTunnel() *cobra.Command {
cmd := &cobra.Command{
Use: "ibc [channel-id] [encoder] [initial-deposit] [interval] [signalInfos-json-file]",
Use: "ibc [channel-id] [initial-deposit] [interval] [signalInfos-json-file]",
Short: "Create a new IBC tunnel",
Args: cobra.ExactArgs(5),
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

encoder, err := strconv.ParseInt(args[1], 10, 32)
initialDeposit, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}

initialDeposit, err := sdk.ParseCoinsNormalized(args[2])
interval, err := strconv.ParseUint(args[2], 10, 64)
if err != nil {
return err
}

interval, err := strconv.ParseUint(args[3], 10, 64)
if err != nil {
return err
}

signalInfos, err := parseSignalDeviations(args[4])
signalInfos, err := parseSignalDeviations(args[3])
if err != nil {
return err
}
Expand All @@ -146,7 +141,6 @@ func GetTxCmdCreateIBCTunnel() *cobra.Command {
signalInfos.ToSignalDeviations(),
interval,
args[0],
feedstypes.Encoder(encoder),
initialDeposit,
clientCtx.GetFromAddress(),
)
Expand Down
1 change: 0 additions & 1 deletion x/tunnel/keeper/keeper_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func (k Keeper) SendPacket(ctx sdk.Context, packet types.Packet) (err error) {
ctx,
r,
packet,
tunnel.Encoder,
sdk.MustAccAddressFromBech32(tunnel.FeePayer),
)
case *types.IBCRoute:
Expand Down
4 changes: 1 addition & 3 deletions x/tunnel/keeper/keeper_packet_tss.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper
import (
sdk "github.com/cosmos/cosmos-sdk/types"

feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types"
"github.com/bandprotocol/chain/v3/x/tunnel/types"
)

Expand All @@ -12,14 +11,13 @@ func (k Keeper) SendTSSPacket(
ctx sdk.Context,
route *types.TSSRoute,
packet types.Packet,
encoder feedstypes.Encoder,
feePayer sdk.AccAddress,
) (receipt types.PacketReceiptI, err error) {
content := types.NewTunnelSignatureOrder(
packet.Sequence,
packet.Prices,
packet.CreatedAt,
encoder,
route.Encoder,
)

// try signing TSS packet, if success, write the context.
Expand Down
2 changes: 1 addition & 1 deletion x/tunnel/keeper/keeper_packet_tss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (s *KeeperTestSuite) TestSendTSSPacket() {
route := types.TSSRoute{
DestinationChainID: "chain-1",
DestinationContractAddress: "0x1234567890abcdef",
Encoder: feedstypes.ENCODER_FIXED_POINT_ABI,
}
packet := types.NewPacket(
1, // tunnelID
Expand All @@ -47,7 +48,6 @@ func (s *KeeperTestSuite) TestSendTSSPacket() {
ctx,
&route,
packet,
feedstypes.ENCODER_FIXED_POINT_ABI,
bandtesting.Alice.Address,
)
s.Require().NoError(err)
Expand Down
2 changes: 1 addition & 1 deletion x/tunnel/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ func (s *KeeperTestSuite) AddSampleTunnel(isActive bool) {
route := &types.TSSRoute{
DestinationChainID: "chain-1",
DestinationContractAddress: "0x1234567890abcdef",
Encoder: feedstypes.ENCODER_FIXED_POINT_ABI,
}

tunnel, err := k.AddTunnel(
ctx,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
signalDeviations,
10,
sdk.AccAddress([]byte("creator_address")),
Expand Down
3 changes: 0 additions & 3 deletions x/tunnel/keeper/keeper_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
func (k Keeper) AddTunnel(
ctx sdk.Context,
route types.RouteI,
encoder feedstypes.Encoder,
signalDeviations []types.SignalDeviation,
interval uint64,
creator sdk.AccAddress,
Expand All @@ -38,7 +37,6 @@ func (k Keeper) AddTunnel(
newID,
0,
route,
encoder,
feePayer.String(),
signalDeviations,
interval,
Expand All @@ -61,7 +59,6 @@ func (k Keeper) AddTunnel(
sdk.NewAttribute(types.AttributeKeyTunnelID, fmt.Sprintf("%d", tunnel.ID)),
sdk.NewAttribute(types.AttributeKeyInterval, fmt.Sprintf("%d", tunnel.Interval)),
sdk.NewAttribute(types.AttributeKeyRoute, tunnel.Route.String()),
sdk.NewAttribute(types.AttributeKeyEncoder, tunnel.Encoder.String()),
sdk.NewAttribute(types.AttributeKeyFeePayer, tunnel.FeePayer),
sdk.NewAttribute(types.AttributeKeyIsActive, fmt.Sprintf("%t", tunnel.IsActive)),
sdk.NewAttribute(types.AttributeKeyCreatedAt, fmt.Sprintf("%d", tunnel.CreatedAt)),
Expand Down
9 changes: 1 addition & 8 deletions x/tunnel/keeper/keeper_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (s *KeeperTestSuite) TestAddTunnel() {
expectedTunnel := types.Tunnel{
ID: 1,
Route: any,
Encoder: feedstypes.ENCODER_FIXED_POINT_ABI,
FeePayer: "band1mdnfc2ehu7vkkg5nttc8tuvwpa9f3dxskf75yxfr7zwhevvcj62q2yggu0",
Creator: creator.String(),
Interval: interval,
Expand All @@ -51,7 +50,7 @@ func (s *KeeperTestSuite) TestAddTunnel() {
s.accountKeeper.EXPECT().NewAccount(ctx, gomock.Any()).Times(1)
s.accountKeeper.EXPECT().SetAccount(ctx, gomock.Any()).Times(1)

tunnel, err := k.AddTunnel(ctx, route, feedstypes.ENCODER_FIXED_POINT_ABI, signalDeviations, interval, creator)
tunnel, err := k.AddTunnel(ctx, route, signalDeviations, interval, creator)
s.Require().NoError(err)
s.Require().Equal(expectedTunnel, *tunnel)

Expand All @@ -69,7 +68,6 @@ func (s *KeeperTestSuite) TestUpdateAndResetTunnel() {
ctx, k := s.ctx, s.keeper

initialRoute := &types.TSSRoute{}
initialEncoder := feedstypes.ENCODER_FIXED_POINT_ABI
initialSignalDeviations := []types.SignalDeviation{
{SignalID: "BTC", SoftDeviationBPS: 1000, HardDeviationBPS: 1000},
{SignalID: "ETH", SoftDeviationBPS: 1000, HardDeviationBPS: 1000},
Expand All @@ -86,7 +84,6 @@ func (s *KeeperTestSuite) TestUpdateAndResetTunnel() {
initialTunnel, err := k.AddTunnel(
ctx,
initialRoute,
initialEncoder,
initialSignalDeviations,
initialInterval,
creator,
Expand Down Expand Up @@ -171,7 +168,6 @@ func (s *KeeperTestSuite) TestActivateTunnel() {

tunnelID := uint64(1)
route := &codectypes.Any{}
encoder := feedstypes.ENCODER_FIXED_POINT_ABI
signalDeviations := []types.SignalDeviation{
{SignalID: "BTC"},
{SignalID: "ETH"},
Expand All @@ -182,7 +178,6 @@ func (s *KeeperTestSuite) TestActivateTunnel() {
tunnel := types.Tunnel{
ID: tunnelID,
Route: route,
Encoder: encoder,
SignalDeviations: signalDeviations,
Interval: interval,
TotalDeposit: k.GetParams(ctx).MinDeposit,
Expand Down Expand Up @@ -211,7 +206,6 @@ func (s *KeeperTestSuite) TestDeactivateTunnel() {

tunnelID := uint64(1)
route := &codectypes.Any{}
encoder := feedstypes.ENCODER_FIXED_POINT_ABI
signalDeviations := []types.SignalDeviation{
{SignalID: "BTC"},
{SignalID: "ETH"},
Expand All @@ -223,7 +217,6 @@ func (s *KeeperTestSuite) TestDeactivateTunnel() {
tunnel := types.Tunnel{
ID: tunnelID,
Route: route,
Encoder: encoder,
SignalDeviations: signalDeviations,
Interval: interval,
Creator: creator,
Expand Down
1 change: 0 additions & 1 deletion x/tunnel/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (k msgServer) CreateTunnel(
tunnel, err := k.Keeper.AddTunnel(
ctx,
route,
msg.Encoder,
msg.SignalDeviations,
msg.Interval,
creator,
Expand Down
6 changes: 1 addition & 5 deletions x/tunnel/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
route := &types.TSSRoute{
DestinationChainID: "chain-1",
DestinationContractAddress: "0x1234567890abcdef",
Encoder: feedstypes.ENCODER_FIXED_POINT_ABI,
}

cases := map[string]struct {
Expand All @@ -46,7 +47,6 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
signalDeviations,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(100))),
sdk.AccAddress([]byte("creator_address")),
)
Expand All @@ -65,7 +65,6 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
signalDeviations,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(100))),
sdk.AccAddress([]byte("creator_address")),
)
Expand All @@ -83,7 +82,6 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
signalDeviations,
1,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(sdk.NewCoin("uband", sdkmath.NewInt(100))),
sdk.AccAddress([]byte("creator_address")),
)
Expand All @@ -103,7 +101,6 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
signalDeviations,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
sdk.NewCoins(),
sdk.AccAddress([]byte("creator_address")),
)
Expand All @@ -129,7 +126,6 @@ func (s *KeeperTestSuite) TestMsgCreateTunnel() {
signalDeviations,
60,
route,
feedstypes.ENCODER_FIXED_POINT_ABI,
depositAmount,
depositor,
)
Expand Down
14 changes: 3 additions & 11 deletions x/tunnel/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func NewMsgCreateTunnel(
signalDeviations []SignalDeviation,
interval uint64,
route RouteI,
encoder feedstypes.Encoder,
initialDeposit sdk.Coins,
creator sdk.AccAddress,
) (*MsgCreateTunnel, error) {
Expand All @@ -38,7 +37,6 @@ func NewMsgCreateTunnel(
SignalDeviations: signalDeviations,
Interval: interval,
Route: any,
Encoder: encoder,
InitialDeposit: initialDeposit,
Creator: creator.String(),
}, nil
Expand All @@ -54,8 +52,8 @@ func NewMsgCreateTSSTunnel(
initialDeposit sdk.Coins,
creator sdk.AccAddress,
) (*MsgCreateTunnel, error) {
r := NewTSSRoute(destinationChainID, destinationContractAddress)
m, err := NewMsgCreateTunnel(signalDeviations, interval, &r, encoder, initialDeposit, creator)
r := NewTSSRoute(destinationChainID, destinationContractAddress, encoder)
m, err := NewMsgCreateTunnel(signalDeviations, interval, &r, initialDeposit, creator)
if err != nil {
return nil, err
}
Expand All @@ -68,12 +66,11 @@ func NewMsgCreateIBCTunnel(
signalDeviations []SignalDeviation,
interval uint64,
channelID string,
encoder feedstypes.Encoder,
deposit sdk.Coins,
creator sdk.AccAddress,
) (*MsgCreateTunnel, error) {
r := NewIBCRoute(channelID)
m, err := NewMsgCreateTunnel(signalDeviations, interval, r, encoder, deposit, creator)
m, err := NewMsgCreateTunnel(signalDeviations, interval, r, deposit, creator)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -115,11 +112,6 @@ func (m MsgCreateTunnel) ValidateBasic() error {
return err
}

// encoder must be valid
if err := feedstypes.ValidateEncoder(m.Encoder); err != nil {
return err
}

// initial deposit must be valid
if !m.InitialDeposit.IsValid() {
return sdkerrors.ErrInvalidCoins.Wrapf("invalid initial deposit: %s", m.InitialDeposit)
Expand Down
Loading
Loading