Skip to content

Commit

Permalink
fix(e2e): Add clock skew only to processes that accumulate less than …
Browse files Browse the repository at this point in the history
…1/3 of voting power (cometbft#2597)

Some nightly tests are failing because validators with clock skew and
high stake are slowing down progress.

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [ ] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
  • Loading branch information
hvanz authored Mar 13, 2024
1 parent f307c0c commit f4e5958
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions test/e2e/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,50 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion st
// First we generate seed nodes, starting at the initial height.
for i := 1; i <= numSeeds; i++ {
manifest.Nodes[fmt.Sprintf("seed%02d", i)] = generateNode(
r, e2e.ModeSeed, 0, false, 0)
r, e2e.ModeSeed, 0, false)
}

// Next, we generate validators. We make sure a BFT quorum of validators start
// at the initial height, and that we have two archive nodes. We also set up
// the initial validator set, and validator set updates for delayed nodes.
nextStartAt := manifest.InitialHeight + 5
quorum := numValidators*2/3 + 1
var totalWeight int64
for i := 1; i <= numValidators; i++ {
startAt := int64(0)
var clockSkew time.Duration
if i > quorum {
startAt = nextStartAt
nextStartAt += 5
// Interval: [-500ms, 59s500ms)
clockSkew = time.Duration(int64(r.Float64()*float64(time.Minute))) - 500*time.Millisecond
}
name := fmt.Sprintf("validator%02d", i)
manifest.Nodes[name] = generateNode(
r, e2e.ModeValidator, startAt, i <= 2, clockSkew)
manifest.Nodes[name] = generateNode(r, e2e.ModeValidator, startAt, i <= 2)

weight := int64(30 + r.Intn(71))
if startAt == 0 {
(*manifest.Validators)[name] = int64(30 + r.Intn(71))
(*manifest.Validators)[name] = weight
} else {
manifest.ValidatorUpdates[strconv.FormatInt(startAt+5, 10)] = map[string]int64{
name: int64(30 + r.Intn(71)),
}
manifest.ValidatorUpdates[strconv.FormatInt(startAt+5, 10)] = map[string]int64{name: weight}
}
totalWeight += weight
}

// Add clock skew only to processes that accumulate less than 1/3 of voting power.
var accWeight int64
for i := 1; i <= numValidators; i++ {
name := fmt.Sprintf("validator%02d", i)
startAt := manifest.Nodes[name].StartAt
var weight int64
if startAt == 0 {
weight = (*manifest.Validators)[name]
} else {
weight = manifest.ValidatorUpdates[strconv.FormatInt(startAt+5, 10)][name]
}

if accWeight > totalWeight*2/3 {
// Interval: [-500ms, 59s500ms)
manifest.Nodes[name].ClockSkew = time.Duration(int64(r.Float64()*float64(time.Minute))) - 500*time.Millisecond
}
accWeight += weight
}

// Move validators to InitChain if specified.
Expand All @@ -242,7 +258,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion st
nextStartAt += 5
}
manifest.Nodes[fmt.Sprintf("full%02d", i)] = generateNode(
r, e2e.ModeFull, startAt, false, 0)
r, e2e.ModeFull, startAt, false)
}

// We now set up peer discovery for nodes. Seed nodes are fully meshed with
Expand Down Expand Up @@ -305,7 +321,7 @@ func generateTestnet(r *rand.Rand, opt map[string]interface{}, upgradeVersion st
// here, since we need to know the overall network topology and startup
// sequencing.
func generateNode(
r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool, clockSkew time.Duration,
r *rand.Rand, mode e2e.Mode, startAt int64, forceArchive bool,
) *e2e.ManifestNode {
node := e2e.ManifestNode{
Version: nodeVersions.Choose(r).(string),
Expand All @@ -320,7 +336,6 @@ func generateNode(
RetainBlocks: uint64(nodeRetainBlocks.Choose(r).(int)),
EnableCompanionPruning: false,
Perturb: nodePerturbations.Choose(r),
ClockSkew: clockSkew,
}

// If this node is forced to be an archive node, retain all blocks and
Expand Down

0 comments on commit f4e5958

Please sign in to comment.