Skip to content

Commit 2e0b2a5

Browse files
committed
WIP
1 parent 228cf9d commit 2e0b2a5

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

.github/workflows/juno-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: [ubuntu-latest, macos-latest, ubuntu-arm64-4-core]
21+
iteration: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
2122
runs-on: ${{ matrix.os }}
2223
env:
2324
VM_DEBUG: true

consensus/integtest/integ_test.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package integtest
22

33
import (
44
"fmt"
5+
goitre "iter"
56
"maps"
67
"slices"
78
gosync "sync"
89
"testing"
10+
"time"
911

1012
"github.com/NethermindEth/juno/blockchain"
1113
"github.com/NethermindEth/juno/consensus"
1214
"github.com/NethermindEth/juno/consensus/driver"
1315
"github.com/NethermindEth/juno/consensus/starknet"
16+
"github.com/NethermindEth/juno/consensus/types"
1417
"github.com/NethermindEth/juno/core"
1518
"github.com/NethermindEth/juno/core/felt"
1619
"github.com/NethermindEth/juno/db/memory"
@@ -28,8 +31,8 @@ import (
2831

2932
const (
3033
commitBufferSize = 1024
31-
maxLag = 10
3234
hostAddress = "/ip4/0.0.0.0/tcp/0"
35+
maxRoundWait = types.Round(5)
3336
)
3437

3538
var (
@@ -169,6 +172,26 @@ func writeBlock(
169172
}
170173
}
171174

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+
172195
func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *utils.ZapLogger) {
173196
t.Helper()
174197

@@ -182,22 +205,23 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
182205
commitCount := make(map[uint64]int)
183206

184207
nextHeight := uint64(1)
185-
for commit := range commits {
208+
for commit := range commitStream(t, cfg.nodeCount, commits) {
186209
blockNumber := commit.committedBlock.Block.Number
187210
blockHash := commit.committedBlock.Block.Hash
188-
// Ignore commits after the target height
189-
if blockNumber > cfg.targetHeight {
190-
continue
191-
}
192211

193212
require.Falsef(
194213
t,
195-
blockNumber > nextHeight+maxLag,
214+
blockNumber > nextHeight+cfg.targetHeight,
196215
"finished height %d is too far behind committed height %d",
197216
nextHeight,
198217
blockNumber,
199218
)
200219

220+
// Ignore commits after the target height
221+
if blockNumber > cfg.targetHeight {
222+
continue
223+
}
224+
201225
// Ignore faulty nodes
202226
if commit.nodeIndex >= honestNodeCount {
203227
continue
@@ -218,12 +242,12 @@ func assertCommits(t *testing.T, commits chan commit, cfg testConfig, logger *ut
218242
commitCount[blockNumber]++
219243

220244
// 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 {
222246
logger.Infow("all honest nodes committed", "height", nextHeight)
223247
nextHeight++
224248
}
225249

226-
if nextHeight == cfg.targetHeight {
250+
if nextHeight > cfg.targetHeight {
227251
break
228252
}
229253
}

consensus/mock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func InitMockServices(hiSeed, loSeed uint64, nodeIndex, nodeCount int) MockServi
3131
PrivateKey: mockKey(nodeIndex),
3232
NodeAddress: mockNodeAddress(nodeIndex),
3333
Validators: newMockValidators(hiSeed, loSeed, nodeCount),
34-
TimeoutFn: mockTimeoutFn(nodeCount),
34+
TimeoutFn: MockTimeoutFn(nodeCount),
3535
}
3636
}
3737

@@ -61,7 +61,7 @@ func mockNodeAddress(i int) starknet.Address {
6161
return starknet.Address(felt.FromUint64(uint64(i)))
6262
}
6363

64-
func mockTimeoutFn(nodeCount int) func(types.Step, types.Round) time.Duration {
64+
func MockTimeoutFn(nodeCount int) func(types.Step, types.Round) time.Duration {
6565
return func(step types.Step, round types.Round) time.Duration {
6666
// Total number of messages are N^2, so the load is roughly proportional to O(N^2)
6767
// Every round increases the timeout by timeoutRoundFactor. It also guarantees that the timeout will be at least timeoutRoundFactor

0 commit comments

Comments
 (0)