@@ -24,25 +24,23 @@ type BCChallengeResponse struct {
24
24
Challenges []* ChallengeEntity `json:"challenges"`
25
25
}
26
26
27
- var lastChallengeTimestamp int
27
+ var lastChallengeRound int64
28
28
29
29
func syncOpenChallenges (ctx context.Context ) {
30
- const incrOffset = 20
31
30
defer func () {
32
31
if r := recover (); r != nil {
33
32
logging .Logger .Error ("[recover]challenge" , zap .Any ("err" , r ))
34
33
}
35
34
}()
36
35
37
- offset := 0
38
36
params := make (map [string ]string )
39
37
params ["blobber" ] = node .Self .ID
40
- params [ "offset" ] = strconv . Itoa ( offset )
41
- params ["limit" ] = "20 "
42
- if lastChallengeTimestamp > 0 {
43
- params ["from" ] = strconv .Itoa ( lastChallengeTimestamp )
38
+
39
+ params ["limit" ] = "50 "
40
+ if lastChallengeRound > 0 {
41
+ params ["from" ] = strconv .FormatInt ( lastChallengeRound , 10 )
44
42
}
45
- logging . Logger . Info ( "[challenge]sync:pull" , zap . Any ( "params" , params ))
43
+
46
44
start := time .Now ()
47
45
48
46
var downloadElapsed , jsonElapsed time.Duration
@@ -54,6 +52,9 @@ func syncOpenChallenges(ctx context.Context) {
54
52
return
55
53
default :
56
54
}
55
+
56
+ logging .Logger .Info ("[challenge]sync:pull" , zap .Any ("params" , params ))
57
+
57
58
var challenges BCChallengeResponse
58
59
var challengeIDs []string
59
60
challenges .Challenges = make ([]* ChallengeEntity , 0 )
@@ -75,13 +76,13 @@ func syncOpenChallenges(ctx context.Context) {
75
76
break
76
77
}
77
78
sort .Slice (challenges .Challenges , func (i , j int ) bool {
78
- return challenges .Challenges [i ].CreatedAt < challenges .Challenges [j ].CreatedAt
79
+ return challenges .Challenges [i ].RoundCreatedAt < challenges .Challenges [j ].RoundCreatedAt
79
80
})
80
81
count += len (challenges .Challenges )
81
82
for _ , c := range challenges .Challenges {
82
83
challengeIDs = append (challengeIDs , c .ChallengeID )
83
- if c .CreatedAt > common . Timestamp ( lastChallengeTimestamp ) {
84
- lastChallengeTimestamp = int ( c . CreatedAt )
84
+ if c .RoundCreatedAt >= lastChallengeRound {
85
+ lastChallengeRound = c . RoundCreatedAt
85
86
}
86
87
toProcessChallenge <- c
87
88
}
@@ -93,8 +94,6 @@ func syncOpenChallenges(ctx context.Context) {
93
94
if len (challenges .Challenges ) == 0 {
94
95
break
95
96
}
96
- offset += incrOffset
97
- params ["offset" ] = strconv .Itoa (offset )
98
97
}
99
98
100
99
dbTimeStart := time .Now ()
@@ -110,6 +109,11 @@ func syncOpenChallenges(ctx context.Context) {
110
109
111
110
func validateOnValidators (c * ChallengeEntity ) {
112
111
112
+ logging .Logger .Info ("[challenge]validate: " ,
113
+ zap .Any ("challenge" , c ),
114
+ zap .String ("challenge_id" , c .ChallengeID ),
115
+ )
116
+
113
117
ctx := datastore .GetStore ().CreateTransaction (context .TODO ())
114
118
defer ctx .Done ()
115
119
@@ -119,7 +123,7 @@ func validateOnValidators(c *ChallengeEntity) {
119
123
logging .Logger .Error ("[challengetiming]add: " ,
120
124
zap .String ("challenge_id" , c .ChallengeID ),
121
125
zap .Error (err ))
122
- deleteChallenge (int64 ( c . CreatedAt ) )
126
+ deleteChallenge (c . RoundCreatedAt )
123
127
tx .Rollback ()
124
128
}
125
129
@@ -150,7 +154,7 @@ func validateOnValidators(c *ChallengeEntity) {
150
154
zap .Time ("created" , createdTime ),
151
155
zap .Error (err ))
152
156
//TODO: Should we delete the challenge from map or send it back to the todo channel?
153
- deleteChallenge (int64 ( c . CreatedAt ) )
157
+ deleteChallenge (c . RoundCreatedAt )
154
158
tx .Rollback ()
155
159
return
156
160
}
0 commit comments