@@ -2,10 +2,12 @@ package integtest
2
2
3
3
import (
4
4
"fmt"
5
+ goitre "iter"
5
6
"maps"
6
7
"slices"
7
8
gosync "sync"
8
9
"testing"
10
+ "time"
9
11
10
12
"github.com/NethermindEth/juno/blockchain"
11
13
"github.com/NethermindEth/juno/consensus"
@@ -28,8 +30,8 @@ import (
28
30
29
31
const (
30
32
commitBufferSize = 1024
31
- maxLag = 10
32
33
hostAddress = "/ip4/0.0.0.0/tcp/0"
34
+ maxCommitWait = 30 * time .Second
33
35
)
34
36
35
37
var (
@@ -169,6 +171,21 @@ func writeBlock(
169
171
}
170
172
}
171
173
174
+ func commitStream (t * testing.T , commits chan commit ) goitre.Seq [commit ] {
175
+ return func (yield func (commit ) bool ) {
176
+ for {
177
+ select {
178
+ case commit := <- commits :
179
+ if ! yield (commit ) {
180
+ return
181
+ }
182
+ case <- time .After (maxCommitWait ):
183
+ require .FailNow (t , "timed out waiting for commit" )
184
+ }
185
+ }
186
+ }
187
+ }
188
+
172
189
func assertCommits (t * testing.T , commits chan commit , cfg testConfig , logger * utils.ZapLogger ) {
173
190
t .Helper ()
174
191
@@ -182,22 +199,23 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
182
199
commitCount := make (map [uint64 ]int )
183
200
184
201
nextHeight := uint64 (1 )
185
- for commit := range commits {
202
+ for commit := range commitStream ( t , commits ) {
186
203
blockNumber := commit .committedBlock .Block .Number
187
204
blockHash := commit .committedBlock .Block .Hash
188
- // Ignore commits after the target height
189
- if blockNumber > cfg .targetHeight {
190
- continue
191
- }
192
205
193
206
require .Falsef (
194
207
t ,
195
- blockNumber > nextHeight + maxLag ,
208
+ blockNumber > nextHeight + cfg . targetHeight ,
196
209
"finished height %d is too far behind committed height %d" ,
197
210
nextHeight ,
198
211
blockNumber ,
199
212
)
200
213
214
+ // Ignore commits after the target height
215
+ if blockNumber > cfg .targetHeight {
216
+ continue
217
+ }
218
+
201
219
// Ignore faulty nodes
202
220
if commit .nodeIndex >= honestNodeCount {
203
221
continue
@@ -218,12 +236,12 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
218
236
commitCount [blockNumber ]++
219
237
220
238
// If all honest nodes committed at this height, increment the finished counter
221
- for commitCount [nextHeight ] == honestNodeCount && nextHeight < cfg .targetHeight {
239
+ for commitCount [nextHeight ] == honestNodeCount && nextHeight <= cfg .targetHeight {
222
240
logger .Infow ("all honest nodes committed" , "height" , nextHeight )
223
241
nextHeight ++
224
242
}
225
243
226
- if nextHeight == cfg .targetHeight {
244
+ if nextHeight > cfg .targetHeight {
227
245
break
228
246
}
229
247
}
0 commit comments