Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test(consensus): pack shards by measured duration, not file count
Round-robin splits by file count, but file durations differ by two orders of
magnitude -- the slowest measured file is 48s and the median is 4s. That left
shard 1 running 262s of tests against 208s for shard 4.

scripts/consensus-weights.tsv carries the per-file seconds measured from this
branch's own sharded run (parsed from the ::group:: markers in the Actions log),
and shard_files now packs with LPT when that table covers the suite.

Measured effect at 4 shards: max shard 262s -> 229s, which is the theoretical
lower bound for an even split, and the spread drops from 54s to 1s. Exactness is
preserved -- every file in exactly one shard, no duplicates, no gaps -- verified
across totals 1, 2, 3, 4, 6 and 8.

The weights are counted work, not wall clock: they are missing per-file process
spawn and teardown, so they predict the ratio between files well and absolute
shard duration less well. That is fine for a packing decision and wrong to quote
as a prediction.

Falls back to round-robin when the table is absent, partially covering the suite,
or unparseable. Packing on a stale or partial table would silently skew the
split, and a file with no weight would be placed as if it were free.
  • Loading branch information
hackobi committed Nov 18, 2026
commit b5c4b35dd4b749c02ae7055fc2b7ff40e10a8b69
265 changes: 265 additions & 0 deletions scripts/consensus-weights.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
docs/runbooks/dormant-mode.test.ts 0
scripts/launch-go-no-go.committee.test.ts 1
scripts/launch-go-no-go.plan.test.ts 8
scripts/launch-go-no-go.prover.test.ts 6
scripts/launch-go-no-go.snapshot.test.ts 5
scripts/launch-go-no-go.test.ts 24
scripts/launch-height1-check.test.ts 3
scripts/node-doctor.test.ts 8
scripts/sudo-call.test.ts 1
scripts/test-consensus.registration.test.ts 0
scripts/validator-prove-signing.test.ts 28
scripts/validator.test.ts 5
src/config/loader.forkSchedulePolicy.test.ts 0
src/config/loader.gossip.test.ts 1
src/config/loader.logsDir.test.ts 3
src/config/loader.rapidApi.test.ts 0
src/config/mainnetParameters.test.ts 0
src/config/proxyChecks.test.ts 0
src/features/incentive/pointsApplyPure.test.ts 4
src/features/tlsnotary/notaryUnreachable.test.ts 4
src/features/tlsnotary/proxyRelay.test.ts 1
src/features/tlsnotary/proxyToken.test.ts 3
src/features/tlsnotary/relayTarget.test.ts 0
src/features/web2/proxy/Proxy.contentType.test.ts 1
src/forks/atomicWorkFork.test.ts 4
src/forks/blockCapsFork.test.ts 4
src/forks/commitLockFork.test.ts 3
src/forks/committeeBindingFork.test.ts 4
src/forks/editBindingFork.test.ts 4
src/forks/finalityProofsFork.test.ts 4
src/forks/governanceGate.test.ts 4
src/forks/identityCarryoverFork.test.ts 4
src/forks/instantMessagingBindingFork.test.ts 5
src/forks/l2psGateFork.test.ts 4
src/forks/l2psGateHandlers.test.ts 3
src/forks/l2psSettlementAdmission.test.ts 4
src/forks/l2psSettlementFork.test.ts 4
src/forks/nonceIntegrityFork.test.ts 4
src/forks/quorumParityFork.test.ts 4
src/forks/signatureDomainGate.test.ts 4
src/forks/telegramSenderBindingFork.test.ts 5
src/forks/tlsnDisabledFork.test.ts 4
src/forks/tlsnVerifiedFork.test.ts 3
src/forks/tokenStakingFork.test.ts 5
src/forks/txTypeAllowListFork.test.ts 4
src/forks/unpinnedCommitteeFork.test.ts 4
src/forks/valueRulesForks.test.ts 4
src/forks/xmRemoveCanonicalFork.test.ts 4
src/libs/abstraction/web2/githubToken.test.ts 5
src/libs/blockchain/blockApplyAtomicity.test.ts 4
src/libs/blockchain/blockCommitOutcome.test.ts 3
src/libs/blockchain/blockRowStorable.test.ts 4
src/libs/blockchain/chainTransactions.insert.test.ts 4
src/libs/blockchain/chainTransactions.status.test.ts 3
src/libs/blockchain/finality/commitments.test.ts 4
src/libs/blockchain/finality/requesterFixtures.test.ts 4
src/libs/blockchain/finality/storageHistory.test.ts 4
src/libs/blockchain/finality/storageRecord.test.ts 0
src/libs/blockchain/finality/storageRoot.test.ts 3
src/libs/blockchain/finality/validatorSet.test.ts 4
src/libs/blockchain/finality/verify.test.ts 1
src/libs/blockchain/gcr/applyTime.test.ts 4
src/libs/blockchain/gcr/gcr_routines/GCRAtomicStorageRoutines.test.ts 1
src/libs/blockchain/gcr/gcr_routines/GCRStorageProgramRoutines.granular.test.ts 5
src/libs/blockchain/gcr/gcr_routines/hashGCR.storageRoot.test.ts 4
src/libs/blockchain/gcr/gcr_routines/identityManager.xmBinding.test.ts 4
src/libs/blockchain/gcr/gcr_routines/noAccountRowsOutsideApply.test.ts 3
src/libs/blockchain/gcr/gcr_routines/routines/identityCarryover.test.ts 4
src/libs/blockchain/gcr/gcr_routines/routines/identityContextKeys.test.ts 4
src/libs/blockchain/gcr/gcr_routines/routines/scoreIdentityRoutines.test.ts 4
src/libs/blockchain/gcr/gcr_routines/routines/zkAttestationContext.test.ts 3
src/libs/blockchain/gcr/gcr_routines/routines/zkRoutines.test.ts 4
src/libs/blockchain/gcr/handleGCR.atomic.test.ts 5
src/libs/blockchain/gcr/handleGCR.failedTx.test.ts 4
src/libs/blockchain/gcr/handleGCR.identityRollback.test.ts 4
src/libs/blockchain/gcr/handleGCR.keyRefusal.test.ts 5
src/libs/blockchain/gcr/handleGCR.l2psSettlement.test.ts 4
src/libs/blockchain/gcr/handleGCR.nativeValue.test.ts 4
src/libs/blockchain/gcr/handleGCR.nonceIntegrity.test.ts 3
src/libs/blockchain/gcr/handleGCR.supply.test.ts 4
src/libs/blockchain/gcr/handleGCR.tlsnOnchain.test.ts 5
src/libs/blockchain/gcr/stagedWrites.test.ts 4
src/libs/blockchain/gcr/storableRows.test.ts 4
src/libs/blockchain/gcr/storageLeafWrite.test.ts 4
src/libs/blockchain/genesis/genesisSeedingTime.test.ts 5
src/libs/blockchain/mempool.editBinding.test.ts 4
src/libs/blockchain/mempool.nextBlockRef.test.ts 3
src/libs/blockchain/mempool.nonceIntegrity.test.ts 2
src/libs/blockchain/mempool.receive.test.ts 4
src/libs/blockchain/routines/Sync.mergePeerlist.test.ts 4
src/libs/blockchain/routines/Sync.orphanRollback.test.ts 4
src/libs/blockchain/routines/Sync.verification.test.ts 5
src/libs/blockchain/routines/syncVerification.test.ts 5
src/libs/blockchain/routines/validateTransaction.feeBalance.test.ts 4
src/libs/blockchain/routines/validateTransaction.nonceWindow.test.ts 3
src/libs/blockchain/routines/validateTransaction.valueRules.test.ts 5
src/libs/blockchain/routines/validatorsManagement.typecheck.test.ts 8
src/libs/blockchain/sdkTypes.typecheck.test.ts 7
src/libs/blockchain/validation/editBinding.nonceIntegrity.test.ts 4
src/libs/blockchain/validation/editBinding.test.ts 4
src/libs/blockchain/validation/editBinding.wire.test.ts 5
src/libs/blockchain/validation/generateGcrEdits.test.ts 0
src/libs/blockchain/validation/nativeValueRules.test.ts 3
src/libs/blockchain/validation/nulRefusal.test.ts 4
src/libs/blockchain/validation/postgresStorable.rowInsert.test.ts 5
src/libs/blockchain/validation/postgresStorable.test.ts 4
src/libs/blockchain/validation/signerRule.test.ts 0
src/libs/blockchain/validation/storageGranular.wire.test.ts 5
src/libs/blockchain/validation/tlsnStoreRefused.test.ts 5
src/libs/blockchain/validation/txAdmission.test.ts 3
src/libs/blockchain/validation/txSignatureDomain.test.ts 4
src/libs/blockchain/validation/txValidatorPool.chunkFailure.test.ts 4
src/libs/blockchain/validation/verifyBlock.crypto.test.ts 7
src/libs/blockchain/validation/verifyBlock.test.ts 4
src/libs/blockchain/validation/verifyBlockTxSignatures.test.ts 3
src/libs/blockchain/validation/verifyBlockTxs.test.ts 4
src/libs/blockchain/validation/verifyValueEdits.test.ts 4
src/libs/blockchain/validation/verifyValueEdits.wire.test.ts 4
src/libs/communications/broadcastManager.syncData.test.ts 1
src/libs/consensus/confirmationEstimate.test.ts 4
src/libs/consensus/genesisShardSize.test.ts 4
src/libs/consensus/genesisSudoPubkey.test.ts 0
src/libs/consensus/mergePeerEligibility.test.ts 0
src/libs/consensus/stakedSet.test.ts 4
src/libs/consensus/v2/PoRBFT.adoptionSync.test.ts 5
src/libs/consensus/v2/PoRBFT.checkBeforeRetry.test.ts 4
src/libs/consensus/v2/PoRBFT.committedReply.test.ts 3
src/libs/consensus/v2/PoRBFT.committeeProbe.test.ts 5
src/libs/consensus/v2/PoRBFT.roundError.test.ts 5
src/libs/consensus/v2/commitLock/candidate.test.ts 0
src/libs/consensus/v2/commitLock/commitLock.crypto.test.ts 1
src/libs/consensus/v2/commitLock/commitLock.safety.test.ts 5
src/libs/consensus/v2/commitLock/lockStore.test.ts 0
src/libs/consensus/v2/commitLock/precommit.test.ts 5
src/libs/consensus/v2/commitLock/restartFloor.test.ts 0
src/libs/consensus/v2/committeeBinding.safety.test.ts 2
src/libs/consensus/v2/forgeLockedCandidate.lostLock.test.ts 4
src/libs/consensus/v2/forgeLockedCandidate.test.ts 4
src/libs/consensus/v2/quorum.test.ts 0
src/libs/consensus/v2/routines/blockCaps.test.ts 4
src/libs/consensus/v2/routines/blockTransactions.settlementCap.test.ts 4
src/libs/consensus/v2/routines/blockTransactions.test.ts 4
src/libs/consensus/v2/routines/boundCommittee.collusion.test.ts 1
src/libs/consensus/v2/routines/boundCommittee.test.ts 0
src/libs/consensus/v2/routines/broadcastBlockHash.committed.test.ts 5
src/libs/consensus/v2/routines/broadcastBlockHash.malformed401.test.ts 4
src/libs/consensus/v2/routines/broadcastBlockHash.voteReply.test.ts 4
src/libs/consensus/v2/routines/committedBlock.test.ts 0
src/libs/consensus/v2/routines/committeeCommit.test.ts 2
src/libs/consensus/v2/routines/cosignTimestamp.test.ts 0
src/libs/consensus/v2/routines/createBlock.commitLock.test.ts 0
src/libs/consensus/v2/routines/createBlock.finality.test.ts 1
src/libs/consensus/v2/routines/createBlock.signing.test.ts 1
src/libs/consensus/v2/routines/deterministicOrder.test.ts 3
src/libs/consensus/v2/routines/ensureCandidateBlockFormed.wait.test.ts 1
src/libs/consensus/v2/routines/getShard.finality.test.ts 0
src/libs/consensus/v2/routines/getShard.test.ts 3
src/libs/consensus/v2/routines/manageProposeBlockHash.crypto.test.ts 1
src/libs/consensus/v2/routines/mempoolFilters.test.ts 4
src/libs/consensus/v2/routines/mergeMempools.test.ts 0
src/libs/consensus/v2/routines/networkAheadVeto.test.ts 0
src/libs/consensus/v2/routines/peerlistMerge.test.ts 3
src/libs/consensus/v2/routines/pinShardIdentities.test.ts 3
src/libs/consensus/v2/routines/pqcIdentityAtForge.test.ts 5
src/libs/consensus/v2/routines/seedGrinding.test.ts 0
src/libs/consensus/v2/routines/stallDetection.committee.test.ts 0
src/libs/consensus/v2/routines/stallDetection.shard.test.ts 0
src/libs/consensus/v2/types/secretaryManager.committee.test.ts 10
src/libs/consensus/v2/types/secretaryManager.rejoin.test.ts 7
src/libs/consensus/v2/types/secretaryManager.timeout.test.ts 4
src/libs/consensus/v2/types/secretaryManager.timestamp.test.ts 3
src/libs/consensus/v2/types/secretaryManagerRegistry.test.ts 5
src/libs/crypto/canonicalJson.test.ts 0
src/libs/crypto/merkle/rfc6962.test.ts 0
src/libs/crypto/merkle/sparse.test.ts 1
src/libs/debug/nonceTrace.test.ts 0
src/libs/gossip/GossipManager.lifecycle.test.ts 6
src/libs/gossip/sidecarHealth.test.ts 0
src/libs/gossip/txPublishPeers.test.ts 3
src/libs/identity/foreignSignature.test.ts 0
src/libs/identity/humanPassportClaimGate.test.ts 0
src/libs/identity/providers/scoreRefresh.test.ts 4
src/libs/identity/signingRecord.test.ts 3
src/libs/identity/tools/twitter.request.test.ts 5
src/libs/identity/web2Unlink.test.ts 0
src/libs/l2ps/l2psAggregatorSettlement.test.ts 4
src/libs/l2ps/l2psAggregatorTeardown.test.ts 4
src/libs/l2ps/l2psApplyTime.test.ts 4
src/libs/l2ps/l2psSettlementOldPath.test.ts 4
src/libs/l2ps/settlement/aggregator.test.ts 4
src/libs/l2ps/settlement/bootCheck.test.ts 3
src/libs/l2ps/settlement/encoding.test.ts 1
src/libs/l2ps/settlement/planner.test.ts 0
src/libs/l2ps/settlement/transfer.test.ts 0
src/libs/l2ps/settlement/validation.test.ts 4
src/libs/network/authReplayCache.test.ts 0
src/libs/network/broadcastDisposition.test.ts 1
src/libs/network/broadcastReferenceWindow.test.ts 0
src/libs/network/endpointValidation.admissionReason.test.ts 15
src/libs/network/handlers/getAddressInfo.test.ts 0
src/libs/network/handlers/getMempool.test.ts 0
src/libs/network/handlers/getTxByHash.test.ts 0
src/libs/network/handlers/requestTlsnProxy.test.ts 3
src/libs/network/handlers/tlsnotaryGetInfo.test.ts 4
src/libs/network/helloGenesisGate.test.ts 0
src/libs/network/httpBodyBinding.test.ts 4
src/libs/network/manageConsensusRoutines.commitLock.test.ts 3
src/libs/network/manageConsensusRoutines.committed.test.ts 4
src/libs/network/manageGCRRoutines.humanPassportClaim.test.ts 5
src/libs/network/manageGCRRoutines.readOnly.test.ts 4
src/libs/network/outboundEntryGate.test.ts 4
src/libs/network/peerHttpAuth.test.ts 0
src/libs/network/proposeBlockHashSender.test.ts 0
src/libs/network/rateLimiter.loopback.test.ts 1
src/libs/network/routines/nodecalls/finalityProofCalls.test.ts 1
src/libs/network/routines/nodecalls/getFinalizedHead.test.ts 0
src/libs/network/routines/nodecalls/readApi.test.ts 0
src/libs/network/routines/nodecalls/requesterFixtures.head.test.ts 0
src/libs/network/routines/nodecalls/requesterFixtures.status.test.ts 3
src/libs/network/rpcEditBinding.test.ts 5
src/libs/network/rpcGossipSize.test.ts 5
src/libs/network/sudoReplayFloor.test.ts 4
src/libs/network/tlsnotaryRoutesGate.test.ts 3
src/libs/omniprotocol/integration/BaseAdapter.test.ts 0
src/libs/omniprotocol/peerAuthBinding.test.ts 5
src/libs/omniprotocol/peerLiveness.test.ts 0
src/libs/omniprotocol/protocol/noConsensusStateWrites.test.ts 0
src/libs/omniprotocol/server/preauthLimits.test.ts 0
src/libs/omniprotocol/transport/ConnectionPool.connectTimeout.test.ts 0
src/libs/omniprotocol/transport/ConnectionPool.perPeerCap.test.ts 9
src/libs/omniprotocol/transport/preauthBuffering.test.ts 5
src/libs/peer/routines/anchorPairing.test.ts 4
src/libs/peer/routines/checkOfflinePeers.test.ts 1
src/libs/peer/routines/peerBootstrap.test.ts 1
src/libs/peer/syncClaims.test.ts 0
src/libs/tlsnotary/httpTranscript.test.ts 0
src/libs/tlsnotary/storedPresentation.test.ts 4
src/libs/tlsnotary/tlsnOnchainPg.test.ts 4
src/libs/tlsnotary/tlsnVerifiedIdentity.test.ts 5
src/libs/tlsnotary/wasmVerifier.test.ts 3
src/libs/utils/clockProbe.test.ts 4
src/libs/utils/keyMaker.test.ts 24
src/model/datasource.test.ts 4
src/model/dbPreflight.test.ts 0
src/utilities/nodeVersion.test.ts 5
src/utilities/tui/CategorizedLogger.level.test.ts 1
testing/consensus/forkScheduleAbstainRoutine.test.ts 3
testing/forks/disableForkMachineryFlag.test.ts 5
testing/forks/loadForkConfig.test.ts 4
testing/forks/web2ProofBindingWiring.test.ts 4
testing/genesis/acceptedForkSchedule.test.ts 0
testing/genesis/buildGenesisBlock.test.ts 4
testing/genesis/findGenesisBlock.requireValidators.test.ts 5
testing/genesis/forkScheduleAbstain.test.ts 7
testing/genesis/forkScheduleAgreement.test.ts 0
testing/genesis/forkScheduleWatch.test.ts 4
testing/genesis/genesisHashTool.test.ts 48
testing/genesis/genesisMismatch.test.ts 0
testing/genesis/genesisPin.test.ts 0
testing/genesis/genesisSchedule.test.ts 0
testing/genesis/identityCarryover.test.ts 5
testing/genesis/normalizeGenesisForHash.test.ts 4
testing/genesis/restoreSnapshot.hashAtRestore.test.ts 4
testing/loadgen/src/features/gcr/gcr_points_smoke.test.ts 4
tests/web2/proxy.test.ts 4
66 changes: 58 additions & 8 deletions scripts/test-consensus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,20 @@ fi
# Sharding. Unset means one shard holding everything, so the default invocation
# is unchanged. Set by the CI matrix, or passed as "--shard INDEX/TOTAL".
#
# Files are dealt round-robin over the stable sorted list rather than packed by
# measured duration: the per-file timings that would make packing better are not
# collected anywhere yet, and guessing them would produce an uneven split that
# looks considered. Round-robin keeps the split exact -- every file lands in
# exactly one shard, no gaps and no duplicates -- and is close to even by count.
# The split is LPT (longest processing time first) over measured per-file
# durations in scripts/consensus-weights.tsv, when that file covers the suite.
# Round-robin over the sorted list by file count is the fallback.
#
# LPT is what makes the split actually even. Round-robin is even by COUNT, but
# files differ by two orders of magnitude (the slowest measured file is 48s, the
# median is 4s), so counting files left one shard ~30% slower than the others.
# Both strategies produce an exact partition: every file in exactly one shard,
# no duplicates, no gaps.
#
# The weights file is data, not a maintained promise. If it is missing, or if it
# does not cover every file in the suite, this falls back to round-robin rather
# than packing on a partial table -- a stale table would silently skew the split,
# and a missing file has no weight to place.
SHARD_INDEX="${SHARD_INDEX:-}"
SHARD_TOTAL="${SHARD_TOTAL:-}"
if [ "${1:-}" = "--shard" ]; then
Expand Down Expand Up @@ -228,10 +237,51 @@ if [ "$SHARD_INDEX" -lt 1 ] || [ "$SHARD_INDEX" -gt "$SHARD_TOTAL" ]; then
exit 2
fi

# Build this shard's file list. The total is carried in the summary line so a
# shard that was handed an empty slice can be told apart from a suite that has
# genuinely lost its tests.
# Build this shard's file list.
#
# With weights: LPT packs the suite onto SHARD_TOTAL bins, then this shard prints
# the bin it owns. The packing is deterministic -- same inputs, same bins -- so
# every shard independently computes the same assignment without coordinating.
# Without weights: round-robin by position in the sorted list.
#
# The total is carried in the summary line so a shard that was handed an empty
# slice can be told apart from a suite that has genuinely lost its tests.
WEIGHTS_FILE="$(cd "$(dirname "$0")/.." && pwd)/scripts/consensus-weights.tsv"

shard_files() {
if [ -f "$WEIGHTS_FILE" ] && awk -F'\t' -v tot="$SHARD_TOTAL" -v idx="$SHARD_INDEX" '
# Pass 1: collect weights and the suite. Pass 2: emit this shard.
FNR == NR {
if (NF >= 2) w[$1] = $2
next
}
{ suite[++n] = $0 }
END {
# Every suite file must have a weight, or packing would place an
# unweighted file as if it were free. Fall back instead.
for (i = 1; i <= n; i++) if (!(suite[i] in w)) exit 1
if (n == 0 || tot < 1 || idx < 1 || idx > tot) exit 1

# LPT: heaviest first, each onto the currently lightest bin.
for (i = 1; i <= n; i++) order[i] = suite[i]
for (i = 2; i <= n; i++) {
key = order[i]; j = i - 1
while (j >= 1 && w[order[j]] < w[key]) { order[j+1] = order[j]; j-- }
order[j+1] = key
}
for (i = 1; i <= tot; i++) load[i] = 0
for (i = 1; i <= n; i++) {
best = 1
for (b = 2; b <= tot; b++) if (load[b] < load[best]) best = b
load[best] += w[order[i]]
bin[order[i]] = best
}
for (i = 1; i <= n; i++) if (bin[suite[i]] == idx) print suite[i]
}
' "$WEIGHTS_FILE" - < <(list_suite_files | sort -u); then
return 0
fi
# Fallback: no weights, or weights that do not cover the suite.
awk -v idx="$SHARD_INDEX" -v tot="$SHARD_TOTAL" '((NR - 1) % tot) == (idx - 1)'
}

Expand Down