Skip to content

Commit

Permalink
Merge branch 'extra/rest' of https://github.com/bandprotocol/chain in…
Browse files Browse the repository at this point in the history
…to extra/rest-tss-full-db
  • Loading branch information
nkitlabs committed Nov 27, 2024
2 parents 582491f + db104f1 commit d3bf63f
Show file tree
Hide file tree
Showing 32 changed files with 3,510 additions and 200 deletions.
1,714 changes: 1,689 additions & 25 deletions api/band/tunnel/v1beta1/route.pulsar.go

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import (
"github.com/bandprotocol/chain/v3/x/tss"
tsskeeper "github.com/bandprotocol/chain/v3/x/tss/keeper"
tsstypes "github.com/bandprotocol/chain/v3/x/tss/types"
"github.com/bandprotocol/chain/v3/x/tunnel"
tunnelkeeper "github.com/bandprotocol/chain/v3/x/tunnel/keeper"
tunneltypes "github.com/bandprotocol/chain/v3/x/tunnel/types"
)
Expand Down Expand Up @@ -137,6 +138,7 @@ type AppKeepers struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedOracleKeeper capabilitykeeper.ScopedKeeper
ScopedTunnelKeeper capabilitykeeper.ScopedKeeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -197,6 +199,7 @@ func NewAppKeeper(
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedOracleKeeper = appKeepers.CapabilityKeeper.ScopeToModule(oracletypes.ModuleName)
appKeepers.ScopedTunnelKeeper = appKeepers.CapabilityKeeper.ScopeToModule(tunneltypes.ModuleName)

// Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating
// their scoped modules in `NewApp` with `ScopeToModule`
Expand Down Expand Up @@ -498,6 +501,9 @@ func NewAppKeeper(
appKeepers.BankKeeper,
appKeepers.FeedsKeeper,
appKeepers.BandtssKeeper,
appKeepers.IBCFeeKeeper,
appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedTunnelKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down Expand Up @@ -534,9 +540,13 @@ func NewAppKeeper(
// Create Oracle Stack
var oracleStack porttypes.IBCModule = oracle.NewIBCModule(appKeepers.OracleKeeper)

// Create Tunnel Stack
var tunnelStack porttypes.IBCModule = tunnel.NewIBCModule(appKeepers.TunnelKeeper)

ibcRouter := porttypes.NewRouter().AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(oracletypes.ModuleName, oracleStack)
AddRoute(oracletypes.ModuleName, oracleStack).
AddRoute(tunneltypes.ModuleName, tunnelStack)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down
8 changes: 7 additions & 1 deletion grogu/signaller/signaller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package signaller

import (
"sort"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -199,9 +200,14 @@ func (s *SignallerTestSuite) TestGetNonPendingSignalIDs() {
// Update internal variables
s.TestUpdateInternalVariables()

expectedSignalIDs := []string{"signal1", "signal2"}

signalIDs = s.Signaller.getNonPendingSignalIDs()
s.Require().NotEmpty(signalIDs)
s.Require().Equal("signal1", signalIDs[0])

// sort signalIDs to compare
sort.Strings(signalIDs)
s.Require().Equal(expectedSignalIDs, signalIDs)
}

func (s *SignallerTestSuite) TestSignalPrices() {
Expand Down
30 changes: 30 additions & 0 deletions proto/band/tunnel/v1beta1/route.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package band.tunnel.v1beta1;
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

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

option go_package = "github.com/bandprotocol/chain/v3/x/tunnel/types";
option (gogoproto.equal_all) = true;

Expand All @@ -27,3 +29,31 @@ message TSSPacketReceipt {
(gogoproto.casttype) = "github.com/bandprotocol/chain/v3/x/bandtss/types.SigningID"
];
}

// IBCRoute is the type for an IBC route
message IBCRoute {
option (cosmos_proto.implements_interface) = "Route";

// channel_id is the IBC channel ID
string channel_id = 1 [(gogoproto.customname) = "ChannelID"];
}

// IBCPacketReceipt represents a receipt for a IBC packet and implements the PacketReceiptI interface.
message IBCPacketReceipt {
option (cosmos_proto.implements_interface) = "PacketContentI";

// sequence is representing the sequence of the IBC packet.
uint64 sequence = 1;
}

// TunnelPricesPacketData represents the IBC packet payload for the tunnel packet.
message TunnelPricesPacketData {
// tunnel_id is the tunnel ID
uint64 tunnel_id = 1 [(gogoproto.customname) = "TunnelID"];
// sequence is representing the sequence of the tunnel packet.
uint64 sequence = 2;
// prices is the list of prices information from feeds module.
repeated band.feeds.v1beta1.Price prices = 3 [(gogoproto.nullable) = false];
// created_at is the timestamp when the packet is created
int64 created_at = 4;
}
1 change: 1 addition & 0 deletions scripts/tunnel/create_ibc_tunnel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +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
5 changes: 5 additions & 0 deletions x/bandtss/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ func NewKeeper(
}
}

// GetAuthority returns the x/bandtss module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
}

// GetBandtssAccount returns the bandtss ModuleAccount
func (k Keeper) GetBandtssAccount(ctx sdk.Context) sdk.ModuleAccountI {
return k.authKeeper.GetModuleAccount(ctx, types.ModuleName)
Expand Down
38 changes: 19 additions & 19 deletions x/bandtss/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (k msgServer) TransitionGroup(
goCtx context.Context,
req *types.MsgTransitionGroup,
) (*types.MsgTransitionGroupResponse, error) {
if k.authority != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("expected %s got %s", k.authority, req.Authority)
if k.Keeper.GetAuthority() != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("expected %s got %s", k.Keeper.GetAuthority(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)

Expand All @@ -43,12 +43,12 @@ func (k msgServer) TransitionGroup(
}

// validate transition duration
if err := k.ValidateTransitionExecTime(ctx, req.ExecTime); err != nil {
if err := k.Keeper.ValidateTransitionExecTime(ctx, req.ExecTime); err != nil {
return nil, err
}

// validate if transition is in progress
if err := k.ValidateTransitionInProgress(ctx); err != nil {
if err := k.Keeper.ValidateTransitionInProgress(ctx); err != nil {
return nil, err
}

Expand All @@ -63,13 +63,13 @@ func (k msgServer) TransitionGroup(
}

// set new group transition
transition, err := k.SetNewGroupTransition(ctx, groupID, req.ExecTime, false)
transition, err := k.Keeper.SetNewGroupTransition(ctx, groupID, req.ExecTime, false)
if err != nil {
return nil, err
}

// emit an event for the group transition.
attrs := k.ExtractEventAttributesFromTransition(transition)
attrs := k.Keeper.ExtractEventAttributesFromTransition(transition)
ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeGroupTransition, attrs...))

return &types.MsgTransitionGroupResponse{}, nil
Expand All @@ -81,23 +81,23 @@ func (k msgServer) ForceTransitionGroup(
goCtx context.Context,
req *types.MsgForceTransitionGroup,
) (*types.MsgForceTransitionGroupResponse, error) {
if k.authority != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("expected %s got %s", k.authority, req.Authority)
if k.Keeper.GetAuthority() != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf("expected %s got %s", k.Keeper.GetAuthority(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)

// validate transition duration
if err := k.ValidateTransitionExecTime(ctx, req.ExecTime); err != nil {
if err := k.Keeper.ValidateTransitionExecTime(ctx, req.ExecTime); err != nil {
return nil, err
}

// validate if transition is in progress
if err := k.ValidateTransitionInProgress(ctx); err != nil {
if err := k.Keeper.ValidateTransitionInProgress(ctx); err != nil {
return nil, err
}

// validate incoming group
currentGroupID := k.GetCurrentGroup(ctx).GroupID
currentGroupID := k.Keeper.GetCurrentGroup(ctx).GroupID
if currentGroupID == req.IncomingGroupID {
return nil, types.ErrInvalidGroupID.Wrap("incoming group is the same as the current group")
}
Expand All @@ -111,18 +111,18 @@ func (k msgServer) ForceTransitionGroup(
}

// add members from new group.
if err := k.AddMembers(ctx, req.IncomingGroupID); err != nil {
if err := k.Keeper.AddMembers(ctx, req.IncomingGroupID); err != nil {
return nil, err
}

// set new group transition
transition, err := k.SetNewGroupTransition(ctx, req.IncomingGroupID, req.ExecTime, true)
transition, err := k.Keeper.SetNewGroupTransition(ctx, req.IncomingGroupID, req.ExecTime, true)
if err != nil {
return nil, err
}

// emit an event for the group transition.
attrs := k.ExtractEventAttributesFromTransition(transition)
attrs := k.Keeper.ExtractEventAttributesFromTransition(transition)
ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeGroupTransition, attrs...))

return &types.MsgForceTransitionGroupResponse{}, nil
Expand All @@ -149,7 +149,7 @@ func (k msgServer) RequestSignature(
}

// Execute the handler to process the request.
_, err = k.CreateDirectSigningRequest(ctx, content, req.Memo, feePayer, req.FeeLimit)
_, err = k.Keeper.CreateDirectSigningRequest(ctx, content, req.Memo, feePayer, req.FeeLimit)
if err != nil {
return nil, err
}
Expand All @@ -166,19 +166,19 @@ func (k msgServer) Activate(goCtx context.Context, msg *types.MsgActivate) (*typ
return nil, sdkerrors.ErrInvalidAddress.Wrapf("invalid sender address: %s", err)
}

if err = k.ActivateMember(ctx, sender, msg.GroupID); err != nil {
if err = k.Keeper.ActivateMember(ctx, sender, msg.GroupID); err != nil {
return nil, err
}

return &types.MsgActivateResponse{}, nil
}

// UpdateParams update the parameter of the module.
func (k Keeper) UpdateParams(
func (k msgServer) UpdateParams(
goCtx context.Context,
req *types.MsgUpdateParams,
) (*types.MsgUpdateParamsResponse, error) {
if k.authority != req.Authority {
if k.Keeper.GetAuthority() != req.Authority {
return nil, govtypes.ErrInvalidSigner.Wrapf(
"invalid authority; expected %s, got %s",
k.authority,
Expand All @@ -187,7 +187,7 @@ func (k Keeper) UpdateParams(
}

ctx := sdk.UnwrapSDKContext(goCtx)
if err := k.SetParams(ctx, req.Params); err != nil {
if err := k.Keeper.SetParams(ctx, req.Params); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit d3bf63f

Please sign in to comment.