Skip to content

Commit

Permalink
fix: gossipsub to yield more to the macro queue (#5664)
Browse files Browse the repository at this point in the history
* fix: add setTimeout to onGossipsubMessage and onValidationResult

* chore: more comments
  • Loading branch information
twoeths committed Jun 29, 2023
1 parent dbadc8b commit 0bccd9f
Showing 1 changed file with 21 additions and 12 deletions.
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

0 comments on commit 0bccd9f

Please sign in to comment.