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

fix: gossipsub to yield more to the macro queue #5664

Merged
merged 2 commits into from
Jun 19, 2023
Merged
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
33 changes: 21 additions & 12 deletions packages/beacon-node/src/network/gossip/gossipsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,21 +279,30 @@ export class Eth2Gossipsub extends GossipSub {
// Get seenTimestamp before adding the message to the queue or add async delays
const seenTimestampSec = Date.now() / 1000;

// Emit message to network processor
this.events.emit(NetworkEvent.pendingGossipsubMessage, {
topic,
msg,
msgId,
// Hot path, use cached .toString() version
propagationSource: propagationSource.toString(),
seenTimestampSec,
startProcessUnixSec: null,
});
// Use setTimeout to yield to the macro queue
// Without this we'll have huge event loop lag
// See https://github.com/ChainSafe/lodestar/issues/5604
setTimeout(() => {
this.events.emit(NetworkEvent.pendingGossipsubMessage, {
topic,
msg,
msgId,
// Hot path, use cached .toString() version
propagationSource: propagationSource.toString(),
seenTimestampSec,
startProcessUnixSec: null,
});
}, 0);
}

private onValidationResult(data: NetworkEventData[NetworkEvent.gossipMessageValidationResult]): void {
// TODO: reportMessageValidationResult should take PeerIdStr since it only uses string version
this.reportMessageValidationResult(data.msgId, peerIdFromString(data.propagationSource), data.acceptance);
// Use setTimeout to yield to the macro queue
// Without this we'll have huge event loop lag
// See https://github.com/ChainSafe/lodestar/issues/5604
setTimeout(() => {
// TODO: reportMessageValidationResult should take PeerIdStr since it only uses string version
this.reportMessageValidationResult(data.msgId, peerIdFromString(data.propagationSource), data.acceptance);
}, 0);
}
}

Expand Down