Skip to content

Commit

Permalink
devp2p: optimize eth debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Aug 14, 2023
1 parent 125a696 commit 7a2493c
Showing 1 changed file with 16 additions and 7 deletions.
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

0 comments on commit 7a2493c

Please sign in to comment.