Skip to content

Commit f4e856c

Browse files
authored
[TSS] Fix transition state and msgServer (#204)
* fix transition state and msgServer * fix readme * fix comments
1 parent 397ed00 commit f4e856c

18 files changed

+348
-265
lines changed

proto/bandtss/v1beta1/bandtss.proto

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ message Signing {
5151

5252
// GroupTransition defines the group transition information of the current group and incoming group.
5353
message GroupTransition {
54-
// signing_id is a tss signing ID of the replacing group signing request.
54+
// signing_id is a tss signing ID of group transition signing request.
5555
uint64 signing_id = 1 [
5656
(gogoproto.customname) = "SigningID",
5757
(gogoproto.casttype) = "github.com/bandprotocol/chain/v2/pkg/tss.SigningID"
@@ -61,7 +61,7 @@ message GroupTransition {
6161
(gogoproto.customname) = "CurrentGroupID",
6262
(gogoproto.casttype) = "github.com/bandprotocol/chain/v2/pkg/tss.GroupID"
6363
];
64-
// current_group_pub_key is the public key pair that used for sign & verify replace group msg.
64+
// current_group_pub_key is the public key pair that used for sign & verify transition group msg.
6565
bytes current_group_pub_key = 3 [(gogoproto.casttype) = "github.com/bandprotocol/chain/v2/pkg/tss.Point"];
6666
// new_group_id is the ID of the new group that be a new key candidate.
6767
uint64 incoming_group_id = 4 [
@@ -74,6 +74,9 @@ message GroupTransition {
7474
TransitionStatus status = 6;
7575
// exec_time is the time when the transition will be executed.
7676
google.protobuf.Timestamp exec_time = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
77+
// is_force_transition is a flag to indicate whether the current group signs the transition message
78+
// before the transition is executed or not.
79+
bool is_force_transition = 8;
7780
}
7881

7982
// TransitionStatus is an enumeration of the possible statuses of a group transition process.
@@ -89,7 +92,7 @@ enum TransitionStatus {
8992
// a current group to sign the transition message.
9093
TRANSITION_STATUS_WAITING_SIGN = 2;
9194
// TRANSITION_STATUS_WAITING_EXECUTION is the status of a group transition that
92-
// a transition process is completed, either from a forceReplace or having a current-group
95+
// a transition process is completed, either from a forceTransition or having a current-group
9396
// signature on a transition message, but waits for the execution time.
9497
TRANSITION_STATUS_WAITING_EXECUTION = 3;
9598
}

proto/bandtss/v1beta1/tx.proto

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ service Msg {
3030
// TransitionGroup creates a request for creating a new group and replacing current group.
3131
rpc TransitionGroup(MsgTransitionGroup) returns (MsgTransitionGroupResponse);
3232

33-
// ForceReplaceGroup sets the given group to the incoming group without the signature of a transition
33+
// ForceTransitionGroup sets the given group to the incoming group without the signature of a transition
3434
// message from a current group.
35-
rpc ForceReplaceGroup(MsgForceReplaceGroup) returns (MsgForceReplaceGroupResponse);
35+
rpc ForceTransitionGroup(MsgForceTransitionGroup) returns (MsgForceTransitionGroupResponse);
3636
}
3737

3838
// MsgRequestSignature is a request message used for initiating the signing process.
@@ -117,12 +117,12 @@ message MsgTransitionGroup {
117117
// MsgTransitionGroupResponse is the Msg/TransitionGroup response type.
118118
message MsgTransitionGroupResponse {}
119119

120-
// MsgForceReplaceGroup is the Msg/ForceReplaceGroup request type.
121-
message MsgForceReplaceGroup {
120+
// MsgForceTransitionGroup is the Msg/ForceTransitionGroup request type.
121+
message MsgForceTransitionGroup {
122122
option (cosmos.msg.v1.signer) = "authority";
123-
option (amino.name) = "bandtss/ForceReplaceGroup";
123+
option (amino.name) = "bandtss/ForceTransitionGroup";
124124

125-
// incoming_group_id is the ID of the group that want to replace.
125+
// incoming_group_id is the ID of the group that the module want to transition to.
126126
uint64 incoming_group_id = 1 [
127127
(gogoproto.customname) = "IncomingGroupID",
128128
(gogoproto.casttype) = "github.com/bandprotocol/chain/v2/pkg/tss.GroupID"
@@ -133,5 +133,5 @@ message MsgForceReplaceGroup {
133133
string authority = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];
134134
}
135135

136-
// MsgForceReplaceGroupResponse is the Msg/ForceReplaceGroup response type.
137-
message MsgForceReplaceGroupResponse {}
136+
// MsgForceTransitionGroupResponse is the Msg/ForceTransitionGroup response type.
137+
message MsgForceTransitionGroupResponse {}

scripts/bandtss/force_replace_group.sh renamed to scripts/bandtss/force_transition_group.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export WALLET_NAME=validator
55
BASEDIR=$(dirname "$0")
66

77
# Submit force_replace_group proposal
8-
bandd tx gov submit-proposal $BASEDIR/proposal_force_replace_group.json \
8+
bandd tx gov submit-proposal $BASEDIR/proposal_force_transition_group.json \
99
--from $WALLET_NAME \
1010
-y --keyring-backend test --gas-prices 0.0025uband -b sync
1111

scripts/bandtss/proposal_force_replace_group.json

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"messages": [
3+
{
4+
"@type": "/bandtss.v1beta1.MsgForceTransitionGroup",
5+
"incoming_group_id": "1",
6+
"exec_time": "2024-09-02T07:40:00+00:00",
7+
"authority": "band10d07y265gmmuvt4z0w9aw880jnsr700jrdn8wm"
8+
}
9+
],
10+
"metadata": "ipfs://",
11+
"deposit": "1000000000uband",
12+
"title": "Force transition group",
13+
"summary": "This proposal is to force transition a group"
14+
}

scripts/bandtss/proposal_transition_group.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"band1nx0xkpnytk35wvflsg7gszf9smw3vaeauk248q"
99
],
1010
"threshold": "2",
11-
"exec_time": "2024-07-15T10:10:00+00:00",
11+
"exec_time": "2024-09-02T07:30:00+00:00",
1212
"authority": "band10d07y265gmmuvt4z0w9aw880jnsr700jrdn8wm"
1313
}
1414
],
1515
"metadata": "ipfs://",
1616
"deposit": "1000000000uband",
17-
"title": "Create group",
18-
"summary": "This proposal is to create a group"
17+
"title": "Transition group",
18+
"summary": "This proposal is to transition a group"
1919
}

x/bandtss/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The module is configured to charge a fee for each signing request, a cost that i
2828
- [Params](#params)
2929
- [Msg Service](#msg-service)
3030
- [Msg/TransitionGroup](#msgtransitiongroup)
31-
- [Msg/ForceReplaceGroup](#msgforcereplacegroup)
31+
- [Msg/ForceTransitionGroup](#msgforcetransitiongroup)
3232
- [Msg/RequestSignature](#msgrequestsignature)
3333
- [Msg/Activate](#msgactivate)
3434
- [Msg/Heartbeat](#msgheartbeat)
@@ -121,6 +121,7 @@ type GroupTransition struct {
121121
IncomingGroupPubKey github_com_bandprotocol_chain_v2_pkg_tss.Point
122122
Status TransitionStatus
123123
ExecTime time.Time
124+
IsForceTransition bool
124125
}
125126
```
126127

@@ -179,7 +180,7 @@ message MsgTransitionGroup {
179180
}
180181
```
181182

182-
### Msg/ForceReplaceGroup
183+
### Msg/ForceTransitionGroup
183184

184185
A current group can be replaced by an incoming group without needing a signing request (transition message) from the current group.
185186

@@ -190,11 +191,11 @@ It's expected to fail if:
190191
- The execution time is before the current time or beyond the maximum transition duration.
191192

192193
```protobuf
193-
message MsgForceReplaceGroup {
194+
message MsgForceTransitionGroup {
194195
option (cosmos.msg.v1.signer) = "authority";
195-
option (amino.name) = "bandtss/ForceReplaceGroup";
196+
option (amino.name) = "bandtss/ForceTransitionGroup";
196197
197-
// incoming_group_id is the ID of the group that want to replace.
198+
// incoming_group_id is the ID of the group that the module want to transition to.
198199
uint64 incoming_group_id = 1 [
199200
(gogoproto.customname) = "IncomingGroupID",
200201
(gogoproto.casttype) = "github.com/bandprotocol/chain/v2/pkg/tss.GroupID"

x/bandtss/keeper/msg_server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func (k msgServer) TransitionGroup(
7676
return &types.MsgTransitionGroupResponse{}, nil
7777
}
7878

79-
// ForceReplaceGroup handles the group transition without waiting a current group to
79+
// ForceTransitionGroup handles the group transition without requesting a current group to
8080
// sign a transition message.
81-
func (k msgServer) ForceReplaceGroup(
81+
func (k msgServer) ForceTransitionGroup(
8282
goCtx context.Context,
83-
req *types.MsgForceReplaceGroup,
84-
) (*types.MsgForceReplaceGroupResponse, error) {
83+
req *types.MsgForceTransitionGroup,
84+
) (*types.MsgForceTransitionGroupResponse, error) {
8585
if k.authority != req.Authority {
8686
return nil, govtypes.ErrInvalidSigner.Wrapf("expected %s got %s", k.authority, req.Authority)
8787
}
@@ -126,7 +126,7 @@ func (k msgServer) ForceReplaceGroup(
126126
attrs := k.ExtractEventAttributesFromTransition(transition)
127127
ctx.EventManager().EmitEvent(sdk.NewEvent(types.EventTypeGroupTransition, attrs...))
128128

129-
return &types.MsgForceReplaceGroupResponse{}, nil
129+
return &types.MsgForceTransitionGroupResponse{}, nil
130130
}
131131

132132
// RequestSignature initiates the signing process by requesting signatures from assigned members.

x/bandtss/keeper/msg_server_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (s *AppTestSuite) TestFailTransitionGroup() {
163163
}
164164
}
165165

166-
func (s *AppTestSuite) TestFailForceReplaceGroupInvalidExecTime() {
166+
func (s *AppTestSuite) TestFailForceTransitionGroupInvalidExecTime() {
167167
ctx, msgSrvr, _ := s.ctx, s.msgSrvr, s.app.TSSKeeper
168168

169169
_ = s.SetupNewGroup(5, 3)
@@ -173,15 +173,15 @@ func (s *AppTestSuite) TestFailForceReplaceGroupInvalidExecTime() {
173173
maxTransitionDuration := s.app.BandtssKeeper.GetParams(ctx).MaxTransitionDuration
174174
execTime := ctx.BlockTime().Add(10 * time.Minute).Add(maxTransitionDuration)
175175

176-
_, err = msgSrvr.ForceReplaceGroup(ctx, &types.MsgForceReplaceGroup{
176+
_, err = msgSrvr.ForceTransitionGroup(ctx, &types.MsgForceTransitionGroup{
177177
IncomingGroupID: group2Ctx.GroupID,
178178
ExecTime: execTime,
179179
Authority: s.authority.String(),
180180
})
181181
s.Require().ErrorIs(err, types.ErrInvalidExecTime)
182182
}
183183

184-
func (s *AppTestSuite) TestFailForceReplaceGroupInvalidGroupStatus() {
184+
func (s *AppTestSuite) TestFailForceTransitionGroupInvalidGroupStatus() {
185185
ctx, msgSrvr, _ := s.ctx, s.msgSrvr, s.app.TSSKeeper
186186

187187
_ = s.SetupNewGroup(5, 3)
@@ -194,27 +194,27 @@ func (s *AppTestSuite) TestFailForceReplaceGroupInvalidGroupStatus() {
194194

195195
s.app.BandtssKeeper.DeleteGroupTransition(ctx)
196196

197-
_, err = msgSrvr.ForceReplaceGroup(ctx, &types.MsgForceReplaceGroup{
197+
_, err = msgSrvr.ForceTransitionGroup(ctx, &types.MsgForceTransitionGroup{
198198
IncomingGroupID: group2Ctx.GroupID,
199199
ExecTime: ctx.BlockTime().Add(10 * time.Minute),
200200
Authority: s.authority.String(),
201201
})
202202
s.Require().ErrorIs(err, types.ErrInvalidIncomingGroup)
203203
}
204204

205-
func (s *AppTestSuite) TestFailForceReplaceGroupInvalidGroupID() {
205+
func (s *AppTestSuite) TestFailForceTransitionGroupInvalidGroupID() {
206206
ctx, msgSrvr, _ := s.ctx, s.msgSrvr, s.app.TSSKeeper
207207

208208
group1Ctx := s.SetupNewGroup(5, 3)
209-
_, err := msgSrvr.ForceReplaceGroup(ctx, &types.MsgForceReplaceGroup{
209+
_, err := msgSrvr.ForceTransitionGroup(ctx, &types.MsgForceTransitionGroup{
210210
IncomingGroupID: group1Ctx.GroupID,
211211
ExecTime: ctx.BlockTime().Add(10 * time.Minute),
212212
Authority: s.authority.String(),
213213
})
214214
s.Require().ErrorIs(err, types.ErrInvalidIncomingGroup)
215215
}
216216

217-
func (s *AppTestSuite) TestFailForceReplaceGroupFromApprovedWaitingReplaceStatus() {
217+
func (s *AppTestSuite) TestFailForceTransitionGroupFromWaitingExecutionStatus() {
218218
ctx, msgSrvr, _ := s.ctx, s.msgSrvr, s.app.TSSKeeper
219219

220220
group1Ctx := s.SetupNewGroup(5, 3)
@@ -232,7 +232,7 @@ func (s *AppTestSuite) TestFailForceReplaceGroupFromApprovedWaitingReplaceStatus
232232
s.Require().True(found)
233233
s.Require().Equal(types.TRANSITION_STATUS_WAITING_EXECUTION, transition.Status)
234234

235-
_, err = msgSrvr.ForceReplaceGroup(ctx, &types.MsgForceReplaceGroup{
235+
_, err = msgSrvr.ForceTransitionGroup(ctx, &types.MsgForceTransitionGroup{
236236
IncomingGroupID: group2Ctx.GroupID,
237237
ExecTime: ctx.BlockTime().Add(10 * time.Minute),
238238
Authority: s.authority.String(),
@@ -272,7 +272,7 @@ func (s *AppTestSuite) TestFailForceReplaceGroupFromApprovedWaitingReplaceStatus
272272
}
273273
}
274274

275-
func (s *AppTestSuite) TestSuccessForceReplaceGroupFromFallenStatus() {
275+
func (s *AppTestSuite) TestSuccessForceTransitionGroupFromFallenStatus() {
276276
ctx, msgSrvr, _ := s.ctx, s.msgSrvr, s.app.TSSKeeper
277277

278278
group1Ctx := s.SetupNewGroup(5, 3)
@@ -286,7 +286,7 @@ func (s *AppTestSuite) TestSuccessForceReplaceGroupFromFallenStatus() {
286286

287287
s.app.BandtssKeeper.DeleteGroupTransition(ctx)
288288

289-
_, err = msgSrvr.ForceReplaceGroup(ctx, &types.MsgForceReplaceGroup{
289+
_, err = msgSrvr.ForceTransitionGroup(ctx, &types.MsgForceTransitionGroup{
290290
IncomingGroupID: group2Ctx.GroupID,
291291
ExecTime: ctx.BlockTime().Add(10 * time.Minute),
292292
Authority: s.authority.String(),
@@ -305,6 +305,7 @@ func (s *AppTestSuite) TestSuccessForceReplaceGroupFromFallenStatus() {
305305
IncomingGroupPubKey: g2.PubKey,
306306
ExecTime: ctx.BlockTime().Add(10 * time.Minute),
307307
SigningID: tss.SigningID(0),
308+
IsForceTransition: true,
308309
}
309310
s.Require().True(found)
310311
s.Require().Equal(expectedTransition, transition)

x/bandtss/keeper/transition.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ func (k Keeper) SetNewGroupTransition(
3737
ctx sdk.Context,
3838
incomingGroupID tss.GroupID,
3939
execTime time.Time,
40-
isForceReplace bool,
40+
isForceTransition bool,
4141
) (types.GroupTransition, error) {
4242
status := types.TRANSITION_STATUS_CREATING_GROUP
43-
if isForceReplace {
43+
if isForceTransition {
4444
status = types.TRANSITION_STATUS_WAITING_EXECUTION
4545
}
4646

@@ -57,22 +57,24 @@ func (k Keeper) SetNewGroupTransition(
5757

5858
// get incoming group and its public key.
5959
var incomingGroupPubKey tss.Point
60-
if isForceReplace {
60+
if isForceTransition {
6161
incomingGroup, err := k.tssKeeper.GetGroup(ctx, incomingGroupID)
6262
if err != nil {
6363
return types.GroupTransition{}, err
6464
}
6565
incomingGroupPubKey = incomingGroup.PubKey
6666
}
6767

68-
transition := types.GroupTransition{
69-
CurrentGroupID: currentGroupID,
70-
CurrentGroupPubKey: currentGroupPubKey,
71-
IncomingGroupID: incomingGroupID,
72-
IncomingGroupPubKey: incomingGroupPubKey,
73-
Status: status,
74-
ExecTime: execTime,
75-
}
68+
transition := types.NewGroupTransition(
69+
tss.SigningID(0),
70+
currentGroupID,
71+
incomingGroupID,
72+
currentGroupPubKey,
73+
incomingGroupPubKey,
74+
status,
75+
execTime,
76+
isForceTransition,
77+
)
7678
k.SetGroupTransition(ctx, transition)
7779

7880
return transition, nil
@@ -145,7 +147,7 @@ func (k Keeper) ValidateTransitionInProgress(ctx sdk.Context) error {
145147
}
146148

147149
// GetIncomingGroupID returns the incoming group ID from transition state. If the status is not
148-
// either ApprovedWaitingReplace or ForcedWaitingReplace, it returns 0.
150+
// WaitingExecution, it returns 0.
149151
func (k Keeper) GetIncomingGroupID(ctx sdk.Context) tss.GroupID {
150152
transition, found := k.GetGroupTransition(ctx)
151153
if !found || transition.Status != types.TRANSITION_STATUS_WAITING_EXECUTION {

0 commit comments

Comments
 (0)