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 (backport #2597) (#2599)

This is an automatic backport of pull request #2597 done by
[Mergify](https://mergify.com).


---


<details>
<summary>Mergify commands and options</summary>

<br />

More conditions and actions can be found in the
[documentation](https://docs.mergify.com/).

You can also trigger Mergify actions by commenting on this pull request:

- `@Mergifyio refresh` will re-evaluate the rules
- `@Mergifyio rebase` will rebase this PR on its base branch
- `@Mergifyio update` will merge the base branch into this PR
- `@Mergifyio backport <destination>` will backport this PR on
`<destination>` branch

Additionally, on Mergify [dashboard](https://dashboard.mergify.com) you
can:

- look at your merge queues
- generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com
</details>

Co-authored-by: Hernán Vanzetto <15466498+hvanz@users.noreply.github.com>
  • Loading branch information
mergify[bot] and hvanz committed Mar 13, 2024
1 parent e9a8e6b commit 9d3bed3
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions test/e2e/generator/generate.go
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 9d3bed3

Please sign in to comment.