@@ -12,7 +12,7 @@ import (
1212// DKGCompletionReceivedHandler is callback handler when the DKG completion received by TSS
1313func (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
4747func (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
6769func (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