Skip to content

Commit 6e9d00c

Browse files
committed
trigger oracle participant liveness check
1 parent 872ac87 commit 6e9d00c

File tree

9 files changed

+241
-98
lines changed

9 files changed

+241
-98
lines changed

api/side/dlc/params.pulsar.go

Lines changed: 86 additions & 24 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/dlc/params.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ message Params {
1515
repeated string allowed_oracle_participants = 4;
1616
uint32 oracle_participant_num = 5;
1717
uint32 oracle_participant_threshold = 6;
18+
int64 oracle_participant_liveness_check_interval = 7;
1819
}

x/dlc/keeper/params.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,8 @@ func (k Keeper) OracleParticipantNum(ctx sdk.Context) uint32 {
3737
func (k Keeper) OracleParticipantThreshold(ctx sdk.Context) uint32 {
3838
return k.GetParams(ctx).OracleParticipantThreshold
3939
}
40+
41+
// OracleParticipantLivenessCheckInterval gets the oracle participant liveness check interval
42+
func (k Keeper) OracleParticipantLivenessCheckInterval(ctx sdk.Context) int64 {
43+
return k.GetParams(ctx).OracleParticipantLivenessCheckInterval
44+
}

x/dlc/keeper/tss.go

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// DKGCompletionReceivedHandler is callback handler when the DKG completion received by TSS
1313
func (k Keeper) DKGCompletionReceivedHandler(ctx sdk.Context, id uint64, ty string, intent int32, participant string) error {
1414
switch ty {
15-
case types.DKG_TYPE_NONCE:
15+
case types.DKG_TYPE_NONCE, types.DKG_TYPE_LIVENESS_CHECK:
1616
k.SetOracleParticipantLiveness(ctx, &types.OracleParticipantLiveness{
1717
ConsensusPubkey: participant,
1818
IsAlive: true,
@@ -46,12 +46,14 @@ func (k Keeper) DKGCompletedHandler(ctx sdk.Context, id uint64, ty string, inten
4646
// DKGTimeoutHandler is callback handler when the DKG timed out in TSS
4747
func (k Keeper) DKGTimeoutHandler(ctx sdk.Context, id uint64, ty string, intent int32, absentParticipants []string) error {
4848
switch ty {
49-
case types.DKG_TYPE_NONCE:
49+
case types.DKG_TYPE_NONCE, types.DKG_TYPE_LIVENESS_CHECK:
5050
for _, participant := range absentParticipants {
51-
k.SetOracleParticipantLiveness(ctx, &types.OracleParticipantLiveness{
52-
ConsensusPubkey: participant,
53-
IsAlive: false,
54-
})
51+
if k.HasOracleParticipantLiveness(ctx, participant) {
52+
liveness := k.GetOracleParticipantLiveness(ctx, participant)
53+
liveness.IsAlive = false
54+
55+
k.SetOracleParticipantLiveness(ctx, liveness)
56+
}
5557
}
5658
}
5759

@@ -63,39 +65,28 @@ func (k Keeper) SigningCompletedHandler(ctx sdk.Context, sender string, id uint6
6365
return k.HandleAttestation(ctx, sender, types.FromScopedId(scopedId), signatures[0])
6466
}
6567

66-
// GetOracleParticipants gets oracle participants
68+
// GetOracleParticipants gets oracle participants randomly
6769
func (k Keeper) GetOracleParticipants(ctx sdk.Context) []string {
68-
// get alive participants
69-
aliveParticipants := k.GetAliveOracleParticipants(ctx)
70-
71-
// check the participant num
70+
baseParticipants := k.OracleParticipantBaseSet(ctx)
7271
participantNum := int(k.OracleParticipantNum(ctx))
73-
if len(aliveParticipants) < participantNum {
74-
return nil
75-
}
7672

77-
if len(aliveParticipants) == participantNum {
78-
return aliveParticipants
79-
}
80-
81-
participants := []string{}
73+
return k.SelectOracleParticipants(ctx, baseParticipants, participantNum)
74+
}
8275

83-
// select oracle participants randomly from the alive list based on the expected participant number
84-
rand := rand.New(rand.NewSource(ctx.BlockTime().Unix()))
85-
selectedIndices := rand.Perm(len(aliveParticipants))[0:participantNum]
86-
for _, index := range selectedIndices {
87-
participants = append(participants, aliveParticipants[index])
88-
}
76+
// GetAliveOracleParticipants gets alive oracle participants randomly
77+
func (k Keeper) GetAliveOracleParticipants(ctx sdk.Context) []string {
78+
aliveOracleParticipants := k.GetAllAliveOracleParticipants(ctx)
79+
participantNum := int(k.OracleParticipantNum(ctx))
8980

90-
return participants
81+
return k.SelectOracleParticipants(ctx, aliveOracleParticipants, participantNum)
9182
}
9283

93-
// GetAliveOracleParticipants gets alive oracle participants
94-
func (k Keeper) GetAliveOracleParticipants(ctx sdk.Context) []string {
84+
// GetAllAliveOracleParticipants gets all alive oracle participants
85+
func (k Keeper) GetAllAliveOracleParticipants(ctx sdk.Context) []string {
9586
// get base participants
9687
baseParticipants := k.OracleParticipantBaseSet(ctx)
9788

98-
// get alive participants
89+
// filter alive participants
9990
aliveParticipants := []string{}
10091
for _, participant := range baseParticipants {
10192
if k.IsOracleParticipantAlive(ctx, participant) {
@@ -105,3 +96,24 @@ func (k Keeper) GetAliveOracleParticipants(ctx sdk.Context) []string {
10596

10697
return aliveParticipants
10798
}
99+
100+
// SelectOracleParticipants selects oracle participants randomly from the base set based on the specified participant num
101+
func (k Keeper) SelectOracleParticipants(ctx sdk.Context, baseOracleParticipants []string, participantNum int) []string {
102+
if len(baseOracleParticipants) < participantNum {
103+
return nil
104+
}
105+
106+
if len(baseOracleParticipants) == participantNum {
107+
return baseOracleParticipants
108+
}
109+
110+
selectedParticipants := []string{}
111+
112+
rand := rand.New(rand.NewSource(ctx.BlockTime().Unix()))
113+
selectedIndices := rand.Perm(len(baseOracleParticipants))[0:participantNum]
114+
for _, index := range selectedIndices {
115+
selectedParticipants = append(selectedParticipants, baseOracleParticipants[index])
116+
}
117+
118+
return selectedParticipants
119+
}

0 commit comments

Comments
 (0)