Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txsource/queries: increase the odds of querying the latest height #2787

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changelog/2787.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
txsource/queries: increase the odds of querying the latest height
10 changes: 8 additions & 2 deletions go/oasis-node/cmd/debug/txsource/workload/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (

// Ratio of queries that should query height 1.
queriesEarliestHeightRatio = 0.1
// Ratio of queries that should query latest available height.
queriesLatestHeightRatio = 0.1
)

// QueriesFlags are the queries workload flags.
Expand Down Expand Up @@ -339,6 +341,8 @@ func (q *queries) doRuntimeQueries(ctx context.Context, rng *rand.Rand) error {
switch {
case p < queriesEarliestHeightRatio:
round = 1
case p < queriesEarliestHeightRatio+queriesLatestHeightRatio:
round = latestRound
default:
// [1, latestRound]
round = uint64(rng.Int63n(int64(latestRound) + 1))
Expand Down Expand Up @@ -425,13 +429,15 @@ func (q *queries) Run(gracefulExit context.Context, rng *rand.Rand, conn *grpc.C
earliestHeight = block.Height - numKept
}

// Select height at which queries should be done. Earliest
// is special cased with increased probability.
// Select height at which queries should be done. Earliest and latest
// heights are special cased with increased probability to be selected.
var height int64
p := rng.Float32()
switch {
case p < queriesEarliestHeightRatio:
height = earliestHeight
case p < queriesEarliestHeightRatio+queriesLatestHeightRatio:
height = block.Height
default:
// [earliestHeight, block.Height]
height = rng.Int63n(block.Height-earliestHeight+1) + earliestHeight
Expand Down