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

Verify signatures on both main thread and worker threads #3793

Merged
merged 11 commits into from
Mar 2, 2022
Prev Previous commit
Next Next commit
Add comments for blsVerifyOnMainThread usage
twoeths committed Feb 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8c4b13ec89fc3fc828e4f06265656b7f60c539ca
2 changes: 1 addition & 1 deletion packages/lodestar/src/chain/bls/multithread/index.ts
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ export class BlsMultiThreadWorkerPool implements IBlsVerifier {

async verifySignatureSets(sets: ISignatureSet[], opts: VerifySignatureOpts = {}): Promise<boolean> {
if (opts.verifyOnMainThread && !this.blsVerifyAllMultiThread) {
const timer = this.metrics?.blsTime.mainThreadDurationInThreadPool.startTimer();
const timer = this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.startTimer();
try {
return verifySignatureSetsMaybeBatch(
sets.map((set) => ({
2 changes: 1 addition & 1 deletion packages/lodestar/src/chain/bls/singleThread.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ export class BlsSingleThreadVerifier implements IBlsVerifier {
}

async verifySignatureSets(sets: ISignatureSet[]): Promise<boolean> {
const timer = this.metrics?.blsTime.mainThreadDurationInThreadPool.startTimer();
const timer = this.metrics?.blsThreadPool.mainThreadDurationInThreadPool.startTimer();
try {
return verifySignatureSetsMaybeBatch(
sets.map((set) => ({
14 changes: 7 additions & 7 deletions packages/lodestar/src/metrics/metrics/lodestar.ts
Original file line number Diff line number Diff line change
@@ -365,20 +365,20 @@ export function createLodestarMetrics(
help: "Time from the worker sending the result and the main thread receiving it",
buckets: [0.1],
}),
mainThreadDurationInThreadPool: register.histogram({
name: "lodestar_bls_thread_pool_main_thread_time_seconds",
help: "Time to verify signatures in main thread with thread pool mode",
buckets: [0.1, 1],
}),
},

// BLS time
blsTime: {
// BLS time on single thread mode
blsSingleThread: {
singleThreadDuration: register.histogram({
name: "lodestar_bls_single_thread_time_seconds",
help: "Time to verify signatures with single thread mode",
buckets: [0.1, 1],
}),
mainThreadDurationInThreadPool: register.histogram({
name: "lodestar_bls_thread_pool_main_thread_time_seconds",
help: "Time to verify signatures in main thread with thread pool mode",
buckets: [0.1, 1],
}),
},

// Sync
6 changes: 6 additions & 0 deletions packages/lodestar/src/network/gossip/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -110,6 +110,12 @@ export function getGossipHandlers(modules: ValidatorFnsModules, options: GossipH
metrics?.registerBeaconBlock(OpSource.gossip, seenTimestampSec, signedBlock.message);

// `validProposerSignature = true`, in gossip validation the proposer signature is checked
// At gossip time, it's critical to keep a good number of mesh peers.
// To do that, the Gossip Job Wait Time should be consistently <3s to avoid the behavior penalties in gossip
// Gossip Job Wait Time depends on the BLS Job Wait Time
// so `blsVerifyOnMainThread = true`: we want to verify signatures immediately without affecting the bls thread pool.
// otherwise we can't utilize bls thread pool capacity and Gossip Job Wait Time can't be kept low consistently.
// See https://github.com/ChainSafe/lodestar/issues/3792
chain
.processBlock(signedBlock, {validProposerSignature: true, blsVerifyOnMainThread: true})
.then(() => {
3 changes: 2 additions & 1 deletion packages/lodestar/src/sync/range/range.ts
Original file line number Diff line number Diff line change
@@ -194,7 +194,8 @@ export class RangeSync extends (EventEmitter as {new (): RangeSyncEmitter}) {
ignoreIfFinalized: true,
// We won't attest to this block so it's okay to ignore a SYNCING message from execution layer
fromRangeSync: true,
// When syncing, we should verify signatures in worker threads
// when this runs, syncing is the most important thing and gossip is not likely to run
// so we can utilize worker threads to verify signatures
blsVerifyOnMainThread: false,
};

6 changes: 6 additions & 0 deletions packages/lodestar/src/sync/unknownBlock.ts
Original file line number Diff line number Diff line change
@@ -164,6 +164,12 @@ export class UnknownBlockSync {
}

pendingBlock.status = PendingBlockStatus.processing;
// At gossip time, it's critical to keep a good number of mesh peers.
// To do that, the Gossip Job Wait Time should be consistently <3s to avoid the behavior penalties in gossip
// Gossip Job Wait Time depends on the BLS Job Wait Time
// so `blsVerifyOnMainThread = true`: we want to verify signatures immediately without affecting the bls thread pool.
// otherwise we can't utilize bls thread pool capacity and Gossip Job Wait Time can't be kept low consistently.
// See https://github.com/ChainSafe/lodestar/issues/3792
const res = await wrapError(
this.chain.processBlock(pendingBlock.signedBlock, {ignoreIfKnown: true, blsVerifyOnMainThread: true})
);