@@ -3,13 +3,12 @@ package epochkghandler
3
3
import (
4
4
"bytes"
5
5
"context"
6
- "math"
7
-
8
6
"github.com/jackc/pgx/v4"
9
7
"github.com/jackc/pgx/v4/pgxpool"
10
8
pubsub "github.com/libp2p/go-libp2p-pubsub"
11
9
"github.com/pkg/errors"
12
10
"github.com/rs/zerolog/log"
11
+ "github.com/shutter-network/rolling-shutter/rolling-shutter/medley"
13
12
14
13
"github.com/shutter-network/shutter/shlib/puredkg"
15
14
"github.com/shutter-network/shutter/shlib/shcrypto"
@@ -39,34 +38,36 @@ func (handler *DecryptionKeyHandler) ValidateMessage(ctx context.Context, msg p2
39
38
return pubsub .ValidationReject ,
40
39
errors .Errorf ("instance ID mismatch (want=%d, have=%d)" , handler .config .GetInstanceID (), key .GetInstanceID ())
41
40
}
42
- if key .Eon > math .MaxInt64 {
43
- return pubsub .ValidationReject , errors .Errorf ("eon %d overflows int64" , key .Eon )
41
+
42
+ eon , err := medley .Uint64ToInt64Safe (key .Eon )
43
+ if err != nil {
44
+ return pubsub .ValidationReject , errors .Wrapf (err , "overflow error while converting eon to int64 %d" , key .Eon )
44
45
}
45
46
46
47
queries := database .New (handler .dbpool )
47
48
48
- _ , isKeyper , err := queries .GetKeyperIndex (ctx , int64 ( key . Eon ) , handler .config .GetAddress ())
49
+ _ , isKeyper , err := queries .GetKeyperIndex (ctx , eon , handler .config .GetAddress ())
49
50
if err != nil {
50
51
return pubsub .ValidationReject , err
51
52
}
52
53
if ! isKeyper {
53
- log .Debug ().Uint64 ("eon" , key . Eon ).Msg ("Ignoring decryptionKey for eon; we're not a Keyper" )
54
+ log .Debug ().Int64 ("eon" , eon ).Msg ("Ignoring decryptionKey for eon; we're not a Keyper" )
54
55
return pubsub .ValidationReject , nil
55
56
}
56
57
57
- dkgResultDB , err := queries .GetDKGResultForKeyperConfigIndex (ctx , int64 ( key . Eon ) )
58
+ dkgResultDB , err := queries .GetDKGResultForKeyperConfigIndex (ctx , eon )
58
59
if err == pgx .ErrNoRows {
59
- return pubsub .ValidationReject , errors .Errorf ("no DKG result found for eon %d" , key . Eon )
60
+ return pubsub .ValidationReject , errors .Errorf ("no DKG result found for eon %d" , eon )
60
61
}
61
62
if err != nil {
62
- return pubsub .ValidationReject , errors .Wrapf (err , "failed to get dkg result for eon %d from db" , key . Eon )
63
+ return pubsub .ValidationReject , errors .Wrapf (err , "failed to get dkg result for eon %d from db" , eon )
63
64
}
64
65
if ! dkgResultDB .Success {
65
- return pubsub .ValidationReject , errors .Errorf ("no successful DKG result found for eon %d" , key . Eon )
66
+ return pubsub .ValidationReject , errors .Errorf ("no successful DKG result found for eon %d" , eon )
66
67
}
67
68
pureDKGResult , err := shdb .DecodePureDKGResult (dkgResultDB .PureResult )
68
69
if err != nil {
69
- return pubsub .ValidationReject , errors .Wrapf (err , "error while decoding pure DKG result for eon %d" , key . Eon )
70
+ return pubsub .ValidationReject , errors .Wrapf (err , "error while decoding pure DKG result for eon %d" , eon )
70
71
}
71
72
72
73
if len (key .Keys ) == 0 {
0 commit comments