66
77 errorsmod "cosmossdk.io/errors"
88 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
9+
10+ tsstypes "github.com/bitwaylabs/bitway/x/tss/types"
911)
1012
1113var (
2123 // default nonce generation timeout duration
2224 DefaultNonceGenerationTimeoutDuration = 24 * time .Hour // 24 hours
2325
24- // minimum oracle participant number
25- MinOracleParticipantNum = uint32 (3 )
26-
2726 // default oracle participant number
2827 DefaultOracleParticipantNum = uint32 (3 )
2928
@@ -71,19 +70,11 @@ func (p Params) Validate() error {
7170 return err
7271 }
7372
74- if len (p .AllowedOracleParticipants ) > 0 && p .OracleParticipantNum > uint32 (len (p .AllowedOracleParticipants )) {
75- return errorsmod .Wrapf (ErrInvalidParams , "oracle participant number cannot be greater than allowed oracle participant number %d" , len (p .AllowedOracleParticipants ))
76- }
77-
78- if p .OracleParticipantNum < MinOracleParticipantNum {
79- return errorsmod .Wrapf (ErrInvalidParams , "oracle participant number cannot be less than min oracle participant number %d" , MinOracleParticipantNum )
80- }
81-
82- if p .OracleParticipantThreshold == 0 || p .OracleParticipantThreshold > p .OracleParticipantNum {
83- return errorsmod .Wrapf (ErrInvalidParams , "invalid oracle participant threshold" )
73+ if err := validateOracleParticipantNum (p ); err != nil {
74+ return err
8475 }
8576
86- return nil
77+ return tsstypes . CheckDKGThreshold ( int ( p . OracleParticipantNum ), int ( p . OracleParticipantThreshold ))
8778}
8879
8980// validateOracleParticipants validates the given oracle participants
@@ -102,3 +93,16 @@ func validateOracleParticipants(participants []string) error {
10293
10394 return nil
10495}
96+
97+ // validateOracleParticipantNum validates the given oracle participant num
98+ func validateOracleParticipantNum (p Params ) error {
99+ if p .OracleParticipantNum < uint32 (tsstypes .MinDKGParticipantNum ) {
100+ return errorsmod .Wrapf (ErrInvalidParams , "oracle participant number cannot be less than min dkg participant number %d" , tsstypes .MinDKGParticipantNum )
101+ }
102+
103+ if len (p .AllowedOracleParticipants ) > 0 && p .OracleParticipantNum > uint32 (len (p .AllowedOracleParticipants )) {
104+ return errorsmod .Wrapf (ErrInvalidParams , "oracle participant number cannot be greater than allowed oracle participant number %d" , len (p .AllowedOracleParticipants ))
105+ }
106+
107+ return nil
108+ }
0 commit comments