Skip to content

Commit 6daefbb

Browse files
committed
improve naming of variable key
1 parent 87d7347 commit 6daefbb

File tree

1 file changed

+13
-13
lines changed
  • rolling-shutter/keyper/epochkghandler

1 file changed

+13
-13
lines changed

rolling-shutter/keyper/epochkghandler/key.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func (*DecryptionKeyHandler) MessagePrototypes() []p2pmsg.Message {
3838
}
3939

4040
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() {
4343
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())
4545
}
46-
eon, err := medley.Uint64ToInt64Safe(key.Eon)
46+
eon, err := medley.Uint64ToInt64Safe(decryptionKeys.Eon)
4747
if err != nil {
4848
return pubsub.ValidationReject, errors.Wrapf(err, "overflow error while converting eon to int64 %d", eon)
4949
}
@@ -54,7 +54,7 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
5454
return pubsub.ValidationReject, err
5555
}
5656
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")
5858
return pubsub.ValidationReject, nil
5959
}
6060
dkgResultDB, err := queries.GetDKGResultForKeyperConfigIndex(ctx, eon)
@@ -72,14 +72,14 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
7272
return pubsub.ValidationReject, errors.Wrapf(err, "error while decoding pure DKG result for eon %d", eon)
7373
}
7474

75-
if len(key.Keys) == 0 {
75+
if len(decryptionKeys.Keys) == 0 {
7676
return pubsub.ValidationReject, errors.New("no keys in message")
7777
}
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())
8080
}
8181

82-
for i, k := range key.Keys {
82+
for i, k := range decryptionKeys.Keys {
8383
epochSecretKey, err := k.GetEpochSecretKey()
8484
if err != nil {
8585
return pubsub.ValidationReject, err
@@ -98,7 +98,7 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
9898
if !ok {
9999
return pubsub.ValidationReject, errors.Errorf("epoch secret key for identity %x is not valid", k.Identity)
100100
}
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 {
102102
return pubsub.ValidationReject, errors.Errorf("keys not ordered")
103103
}
104104
}
@@ -107,16 +107,16 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
107107

108108
func (handler *DecryptionKeyHandler) HandleMessage(ctx context.Context, msg p2pmsg.Message) ([]p2pmsg.Message, error) {
109109
metricsEpochKGDecryptionKeysReceived.Inc()
110-
key := msg.(*p2pmsg.DecryptionKeys)
110+
decryptionKeys := msg.(*p2pmsg.DecryptionKeys)
111111
// We assume that it's valid as it already passed the libp2p validator.
112112
// Insert the key into the cache.
113-
for _, k := range key.Keys {
113+
for _, k := range decryptionKeys.Keys {
114114
epochSecretKey, err := k.GetEpochSecretKey()
115115
if err != nil {
116116
return nil, err
117117
}
118118
handler.cache.Add(*epochSecretKey, k.Identity)
119119
}
120120
// 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)
122122
}

0 commit comments

Comments
 (0)