@@ -38,12 +38,12 @@ func (*DecryptionKeyHandler) MessagePrototypes() []p2pmsg.Message {
38
38
}
39
39
40
40
func (handler * DecryptionKeyHandler ) ValidateMessage (ctx context.Context , msg p2pmsg.Message ) (pubsub.ValidationResult , error ) {
41
- key := msg .(* p2pmsg.DecryptionKeys )
42
- if key .GetInstanceID () != handler .config .GetInstanceID () {
41
+ decryptionKeys := msg .(* p2pmsg.DecryptionKeys )
42
+ if decryptionKeys .GetInstanceID () != handler .config .GetInstanceID () {
43
43
return pubsub .ValidationReject ,
44
- errors .Errorf ("instance ID mismatch (want=%d, have=%d)" , handler .config .GetInstanceID (), key .GetInstanceID ())
44
+ errors .Errorf ("instance ID mismatch (want=%d, have=%d)" , handler .config .GetInstanceID (), decryptionKeys .GetInstanceID ())
45
45
}
46
- eon , err := medley .Uint64ToInt64Safe (key .Eon )
46
+ eon , err := medley .Uint64ToInt64Safe (decryptionKeys .Eon )
47
47
if err != nil {
48
48
return pubsub .ValidationReject , errors .Wrapf (err , "overflow error while converting eon to int64 %d" , eon )
49
49
}
@@ -54,7 +54,7 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
54
54
return pubsub .ValidationReject , err
55
55
}
56
56
if ! isKeyper {
57
- log .Debug ().Uint64 ("eon" , key .Eon ).Msg ("Ignoring decryptionKey for eon; we're not a Keyper" )
57
+ log .Debug ().Uint64 ("eon" , decryptionKeys .Eon ).Msg ("Ignoring decryptionKey for eon; we're not a Keyper" )
58
58
return pubsub .ValidationReject , nil
59
59
}
60
60
dkgResultDB , err := queries .GetDKGResultForKeyperConfigIndex (ctx , eon )
@@ -72,14 +72,14 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
72
72
return pubsub .ValidationReject , errors .Wrapf (err , "error while decoding pure DKG result for eon %d" , eon )
73
73
}
74
74
75
- if len (key .Keys ) == 0 {
75
+ if len (decryptionKeys .Keys ) == 0 {
76
76
return pubsub .ValidationReject , errors .New ("no keys in message" )
77
77
}
78
- if len (key .Keys ) > int (handler .config .GetMaxNumKeysPerMessage ()) {
79
- return pubsub .ValidationReject , errors .Errorf ("too many keys in message (%d > %d)" , len (key .Keys ), handler .config .GetMaxNumKeysPerMessage ())
78
+ if len (decryptionKeys .Keys ) > int (handler .config .GetMaxNumKeysPerMessage ()) {
79
+ return pubsub .ValidationReject , errors .Errorf ("too many keys in message (%d > %d)" , len (decryptionKeys .Keys ), handler .config .GetMaxNumKeysPerMessage ())
80
80
}
81
81
82
- for i , k := range key .Keys {
82
+ for i , k := range decryptionKeys .Keys {
83
83
epochSecretKey , err := k .GetEpochSecretKey ()
84
84
if err != nil {
85
85
return pubsub .ValidationReject , err
@@ -98,7 +98,7 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
98
98
if ! ok {
99
99
return pubsub .ValidationReject , errors .Errorf ("epoch secret key for identity %x is not valid" , k .Identity )
100
100
}
101
- if i > 0 && bytes .Compare (k .Identity , key .Keys [i - 1 ].Identity ) < 0 {
101
+ if i > 0 && bytes .Compare (k .Identity , decryptionKeys .Keys [i - 1 ].Identity ) < 0 {
102
102
return pubsub .ValidationReject , errors .Errorf ("keys not ordered" )
103
103
}
104
104
}
@@ -107,16 +107,16 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
107
107
108
108
func (handler * DecryptionKeyHandler ) HandleMessage (ctx context.Context , msg p2pmsg.Message ) ([]p2pmsg.Message , error ) {
109
109
metricsEpochKGDecryptionKeysReceived .Inc ()
110
- key := msg .(* p2pmsg.DecryptionKeys )
110
+ decryptionKeys := msg .(* p2pmsg.DecryptionKeys )
111
111
// We assume that it's valid as it already passed the libp2p validator.
112
112
// Insert the key into the cache.
113
- for _ , k := range key .Keys {
113
+ for _ , k := range decryptionKeys .Keys {
114
114
epochSecretKey , err := k .GetEpochSecretKey ()
115
115
if err != nil {
116
116
return nil , err
117
117
}
118
118
handler .cache .Add (* epochSecretKey , k .Identity )
119
119
}
120
120
// Insert the key into the db.
121
- return nil , database .New (handler .dbpool ).InsertDecryptionKeysMsg (ctx , key )
121
+ return nil , database .New (handler .dbpool ).InsertDecryptionKeysMsg (ctx , decryptionKeys )
122
122
}
0 commit comments