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

DevP2P: ETH: only create DEBUG msgs if debugging #2958

Merged
merged 4 commits into from
Aug 15, 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
23 changes: 16 additions & 7 deletions packages/devp2p/src/protocol/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ export class ETH extends Protocol {

_handleMessage(code: ETH.MESSAGE_CODES, data: Uint8Array) {
const payload = RLP.decode(data)
const debugMsg = this.DEBUG
? // @ts-ignore
`Received ${this.getMsgPrefix(code)} message from ${this._peer._socket.remoteAddress}:${
// @ts-ignore
this._peer._socket.remotePort
}`
: undefined

if (code !== ETH.MESSAGE_CODES.STATUS && this.DEBUG) {
const debugMsg = this.DEBUG
? // @ts-ignore
`Received ${this.getMsgPrefix(code)} message from ${this._peer._socket.remoteAddress}:${
// @ts-ignore
this._peer._socket.remotePort
}`
: undefined
const logData = formatLogData(bytesToHex(data), this._verbose)
this.debug(this.getMsgPrefix(code), `${debugMsg}: ${logData}`)
}
Expand All @@ -85,6 +85,15 @@ export class ETH extends Protocol {
this._peerStatus !== undefined ? this._getStatusString(this._peerStatus) : ''
}`
if (this.DEBUG) {
const debugMsg = this.DEBUG
? `Received ${this.getMsgPrefix(code)} message from ${
// @ts-ignore
this._peer._socket.remoteAddress
}:${
// @ts-ignore
this._peer._socket.remotePort
}`
: undefined
this.debug(this.getMsgPrefix(code), `${debugMsg}: ${peerStatusMsg}`)
}
this._handleStatus()
Expand Down
Loading