Skip to content

Commit de6557f

Browse files
committed
adjust key refreshing
1 parent 3a5c148 commit de6557f

13 files changed

Lines changed: 570 additions & 538 deletions

File tree

api/side/tss/tss.pulsar.go

Lines changed: 96 additions & 173 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/side/tss/tx.pulsar.go

Lines changed: 202 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/static/openapi.yml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

proto/side/tss/tss.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ message RefreshingRequest {
130130
uint64 dkg_id = 2;
131131
// removed participant set
132132
repeated string removed_participants = 3;
133-
// new participant set
134-
repeated string new_participants = 4;
133+
// new threshold
134+
uint32 threshold = 4;
135135
// expiration time
136136
google.protobuf.Timestamp expiration_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
137137
// status

proto/side/tss/tx.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ message MsgRefresh {
7272
repeated uint64 dkg_ids = 2;
7373
// removed participant set
7474
repeated string removed_participants = 3;
75-
// new participant set
76-
repeated string new_participants = 4;
77-
// timeout duration
75+
// new threshold set corresponding to the DKGs
76+
repeated uint32 thresholds = 4;
77+
// timeout duration per DKG refreshing
7878
google.protobuf.Duration timeout_duration = 5 [(gogoproto.nullable) = false, (gogoproto.stdduration) = true];
7979
}
8080

x/tss/keeper/msg_server.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,32 @@ func (m msgServer) Refresh(goCtx context.Context, msg *types.MsgRefresh) (*types
8888

8989
ctx := sdk.UnwrapSDKContext(goCtx)
9090

91-
for _, dkgId := range msg.DkgIds {
91+
for i, dkgId := range msg.DkgIds {
9292
if !m.HasDKGRequest(ctx, dkgId) {
93-
return nil, errorsmod.Wrapf(types.ErrDKGRequestDoesNotExist, "%d", dkgId)
93+
return nil, errorsmod.Wrapf(types.ErrDKGRequestDoesNotExist, "dkg %d", dkgId)
9494
}
9595

9696
dkgRequest := m.GetDKGRequest(ctx, dkgId)
9797
if dkgRequest.Status != types.DKGStatus_DKG_STATUS_COMPLETED {
9898
return nil, errorsmod.Wrapf(types.ErrInvalidDKGStatus, "dkg %d not completed", dkgId)
9999
}
100100

101+
remainingParticipantNum := len(dkgRequest.Participants) - len(msg.RemovedParticipants)
102+
if remainingParticipantNum < types.MinDKGParticipantNum {
103+
return nil, errorsmod.Wrapf(types.ErrInvalidParticipants, "remaining participants %d cannot be less than min participants %d", remainingParticipantNum, types.MinDKGParticipantNum)
104+
}
105+
101106
for _, p := range msg.RemovedParticipants {
102107
if !slices.Contains(dkgRequest.Participants, p) {
103108
return nil, errorsmod.Wrapf(types.ErrInvalidParticipants, "participant %s does not exist for dkg %d", p, dkgId)
104109
}
105110
}
106111

107-
m.InitiateRefreshingRequest(ctx, dkgId, msg.RemovedParticipants, msg.NewParticipants, msg.TimeoutDuration)
112+
if msg.Thresholds[i] > uint32(remainingParticipantNum) {
113+
return nil, errorsmod.Wrapf(types.ErrInvalidThresholds, "threshold %d cannot be greater than participants %d for dkg %d", msg.Thresholds[i], remainingParticipantNum, dkgId)
114+
}
115+
116+
m.InitiateRefreshingRequest(ctx, dkgId, msg.RemovedParticipants, msg.Thresholds[i], msg.TimeoutDuration)
108117
}
109118

110119
return &types.MsgRefreshResponse{}, nil

x/tss/keeper/refreshing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (k Keeper) GetRefreshingParticipants(ctx sdk.Context, refreshingRequest *ty
7070
}
7171
}
7272

73-
return append(participants, refreshingRequest.NewParticipants...)
73+
return participants
7474
}
7575

7676
// GetRefreshingRequests gets the refreshing requests by the given status
@@ -165,12 +165,12 @@ func (k Keeper) IterateRefreshingCompletions(ctx sdk.Context, id uint64, cb func
165165
}
166166

167167
// InitiateRefreshingRequest initiates the refreshing request with the specified params
168-
func (k Keeper) InitiateRefreshingRequest(ctx sdk.Context, dkgId uint64, removedParticipants []string, newParticipants []string, timeoutDuration time.Duration) *types.RefreshingRequest {
168+
func (k Keeper) InitiateRefreshingRequest(ctx sdk.Context, dkgId uint64, removedParticipants []string, threshold uint32, timeoutDuration time.Duration) *types.RefreshingRequest {
169169
req := &types.RefreshingRequest{
170170
Id: k.IncrementRefreshingRequestId(ctx),
171171
DkgId: dkgId,
172172
RemovedParticipants: removedParticipants,
173-
NewParticipants: newParticipants,
173+
Threshold: threshold,
174174
ExpirationTime: types.GetExpirationTime(ctx.BlockTime(), timeoutDuration),
175175
Status: types.RefreshingStatus_REFRESHING_STATUS_PENDING,
176176
}
@@ -183,7 +183,7 @@ func (k Keeper) InitiateRefreshingRequest(ctx sdk.Context, dkgId uint64, removed
183183
sdk.NewAttribute(types.AttributeKeyId, fmt.Sprintf("%d", req.Id)),
184184
sdk.NewAttribute(types.AttributeKeyDKGId, fmt.Sprintf("%d", dkgId)),
185185
sdk.NewAttribute(types.AttributeKeyRemovedParticipants, strings.Join(removedParticipants, types.AttributeValueSeparator)),
186-
sdk.NewAttribute(types.AttributeKeyNewParticipants, strings.Join(newParticipants, types.AttributeValueSeparator)),
186+
sdk.NewAttribute(types.AttributeKeyThreshold, fmt.Sprintf("%d", threshold)),
187187
sdk.NewAttribute(types.AttributeKeyExpirationTime, req.ExpirationTime.String()),
188188
),
189189
)

x/tss/module/abci.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ func handleRefreshingRequests(ctx sdk.Context, k keeper.Keeper) {
8181
req.Status = types.RefreshingStatus_REFRESHING_STATUS_COMPLETED
8282
k.SetRefreshingRequest(ctx, req)
8383

84+
// update DKG participants and threshold
85+
dkgRequest := k.GetDKGRequest(ctx, req.DkgId)
86+
dkgRequest.Participants = k.GetRefreshingParticipants(ctx, req)
87+
dkgRequest.Threshold = req.Threshold
88+
k.SetDKGRequest(ctx, dkgRequest)
89+
8490
// Emit events
8591
ctx.EventManager().EmitEvent(
8692
sdk.NewEvent(

x/tss/types/errors.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ var (
2525

2626
ErrInvalidDKGs = errorsmod.Register(ModuleName, 4000, "invalid dkgs")
2727
ErrInvalidParticipants = errorsmod.Register(ModuleName, 4001, "invalid participants")
28-
ErrInvalidTimeoutDuration = errorsmod.Register(ModuleName, 4002, "invalid timeout duration")
29-
ErrRefreshingRequestDoesNotExist = errorsmod.Register(ModuleName, 4003, "refreshing request does not exist")
30-
ErrInvalidRefreshingStatus = errorsmod.Register(ModuleName, 4004, "invalid refreshing status")
31-
ErrRefreshingRequestExpired = errorsmod.Register(ModuleName, 4005, "refreshing request expired")
32-
ErrRefreshingCompletionAlreadyExists = errorsmod.Register(ModuleName, 4006, "refreshing completion already exists")
28+
ErrInvalidThresholds = errorsmod.Register(ModuleName, 4002, "invalid thresholds")
29+
ErrInvalidTimeoutDuration = errorsmod.Register(ModuleName, 4003, "invalid timeout duration")
30+
ErrRefreshingRequestDoesNotExist = errorsmod.Register(ModuleName, 4004, "refreshing request does not exist")
31+
ErrInvalidRefreshingStatus = errorsmod.Register(ModuleName, 4005, "invalid refreshing status")
32+
ErrRefreshingRequestExpired = errorsmod.Register(ModuleName, 4006, "refreshing request expired")
33+
ErrRefreshingCompletionAlreadyExists = errorsmod.Register(ModuleName, 4007, "refreshing completion already exists")
3334

3435
ErrInvalidParams = errorsmod.Register(ModuleName, 5000, "invalid params")
3536
)

x/tss/types/events.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ const (
3131

3232
AttributeKeyDKGId = "dkg_id"
3333
AttributeKeyRemovedParticipants = "removed_participants"
34-
AttributeKeyNewParticipants = "new_participants"
3534
)
3635

3736
const (

0 commit comments

Comments
 (0)