@@ -2,15 +2,18 @@ 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"
12
14
"github.com/NethermindEth/juno/consensus/driver"
13
15
"github.com/NethermindEth/juno/consensus/starknet"
16
+ "github.com/NethermindEth/juno/consensus/types"
14
17
"github.com/NethermindEth/juno/core"
15
18
"github.com/NethermindEth/juno/core/felt"
16
19
"github.com/NethermindEth/juno/db/memory"
@@ -28,8 +31,8 @@ import (
28
31
29
32
const (
30
33
commitBufferSize = 1024
31
- maxLag = 10
32
34
hostAddress = "/ip4/0.0.0.0/tcp/0"
35
+ maxRoundWait = types .Round (5 )
33
36
)
34
37
35
38
var (
@@ -169,6 +172,26 @@ func writeBlock(
169
172
}
170
173
}
171
174
175
+ func commitStream (t * testing.T , nodeCount int , commits chan commit ) goitre.Seq [commit ] {
176
+ timeoutFn := consensus .MockTimeoutFn (nodeCount )
177
+ var maxCommitWait time.Duration
178
+ for round := range maxRoundWait {
179
+ maxCommitWait += timeoutFn (types .StepPropose , round ) + timeoutFn (types .StepPrevote , round ) + timeoutFn (types .StepPrecommit , round )
180
+ }
181
+ return func (yield func (commit ) bool ) {
182
+ for {
183
+ select {
184
+ case commit := <- commits :
185
+ if ! yield (commit ) {
186
+ return
187
+ }
188
+ case <- time .After (maxCommitWait ):
189
+ require .FailNow (t , "timed out waiting for commit" )
190
+ }
191
+ }
192
+ }
193
+ }
194
+
172
195
func assertCommits (t * testing.T , commits chan commit , cfg testConfig , logger * utils.ZapLogger ) {
173
196
t .Helper ()
174
197
@@ -182,22 +205,23 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
182
205
commitCount := make (map [uint64 ]int )
183
206
184
207
nextHeight := uint64 (1 )
185
- for commit := range commits {
208
+ for commit := range commitStream ( t , cfg . nodeCount , commits ) {
186
209
blockNumber := commit .committedBlock .Block .Number
187
210
blockHash := commit .committedBlock .Block .Hash
188
- // Ignore commits after the target height
189
- if blockNumber > cfg .targetHeight {
190
- continue
191
- }
192
211
193
212
require .Falsef (
194
213
t ,
195
- blockNumber > nextHeight + maxLag ,
214
+ blockNumber > nextHeight + cfg . targetHeight ,
196
215
"finished height %d is too far behind committed height %d" ,
197
216
nextHeight ,
198
217
blockNumber ,
199
218
)
200
219
220
+ // Ignore commits after the target height
221
+ if blockNumber > cfg .targetHeight {
222
+ continue
223
+ }
224
+
201
225
// Ignore faulty nodes
202
226
if commit .nodeIndex >= honestNodeCount {
203
227
continue
@@ -218,12 +242,12 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
218
242
commitCount [blockNumber ]++
219
243
220
244
// If all honest nodes committed at this height, increment the finished counter
221
- for commitCount [nextHeight ] == honestNodeCount && nextHeight < cfg .targetHeight {
245
+ for commitCount [nextHeight ] == honestNodeCount && nextHeight <= cfg .targetHeight {
222
246
logger .Infow ("all honest nodes committed" , "height" , nextHeight )
223
247
nextHeight ++
224
248
}
225
249
226
- if nextHeight == cfg .targetHeight {
250
+ if nextHeight > cfg .targetHeight {
227
251
break
228
252
}
229
253
}
0 commit comments