-
Notifications
You must be signed in to change notification settings - Fork 775
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, Client: Fix duplicated debug messages #1643
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @ScottyPoi and yay for the first PR!
I'm concerned about the IP based debug messages and would like others to weigh in. We need to decide how to handle them since we lose them with these changes (as far as I can tell based on testing it out) without adding an additional way to access those messages.
packages/devp2p/src/rlpx/peer.ts
Outdated
if (disconnectReason && messageName === 'DISCONNECT') { | ||
if (this.msgDebuggers[disconnectReason]) { | ||
this.msgDebuggers[disconnectReason](msg) | ||
} | ||
} | ||
} else if (this.msgDebuggers[messageName]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@holgerd77 Which messages did we want to dedup on this one? With this PR's changes, it looks like this:
And on current master
, it looks like this.
Should we be removing the IP based messages? I believe with these changes we will lose the IP based messages entirely since I don't know if we'll ever encounter a situation where there is an IP based message debugger that doesn't also have a messageName
debugger (which is a higher priority in the conditional logic here. Maybe we should change it to something like below so users could specify if they want to see log messages from a specific IP address:
if (ip && process.env.DEBUG === `devp2p:${ip}`) {
this.msgDebuggers[ip](msg)
} else if (disconnectReason && messageName === 'DISCONNECT') {
if (this.msgDebuggers[disconnectReason]) {
this.msgDebuggers[disconnectReason](msg)
}...
It produces output that looks something like this:
We'd have to apply this same check everywhere we have the IP based messaging and then add some updates to the docs to reflect this usage but it seems to work well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These devp2p:127.0.0.1
or devp2p:rlpx:peer:HELLO
prefixes on the log messages are actually only the names of the loggers activated and not a "feature" to display the IP adress on some loggers. 😋
So on your usage this is the correct dedublication, the main point of this whole thing is the we do not have situations where the same message (in the screenshot from above e.g. "Received HELLO message...") is sent multiple times.
And even if only devp2p:rlpx:peer:HELLO
is logged, the remote peer IP is visible in the debug message itself.
That said:
I also tested a local connection along these instructions with the following command:
cd ../devp2p && npm run build && cd ../client && DEBUG=devp2p:127.0.0.1 npm run client:start:dev2 -- --bootnodes=enode://90e0424dff457a1b677b45aa0bf861e71284c45514e944060f8fb3cca65ddc1b241e686e7a9fb8ac37e6090376a4faf379368cc8ad59ae29194ee3126c3e9c88@127.0.0.1:30303
And with the current conditional order the IP logger wouldn't display in this case.
I guess it's enough if we just switch the meesage logger and the IP logger order and keep the rest in place, so this would work for me locally:
const ip = this._socket.remoteAddress
if (disconnectReason && messageName === 'DISCONNECT') {
if (this.msgDebuggers[disconnectReason]) {
this.msgDebuggers[disconnectReason](msg)
}
} else if (ip && this.msgDebuggers[ip]) {
this.msgDebuggers[ip](msg)
} else if (this.msgDebuggers[messageName]) {
this.msgDebuggers[messageName](msg)
} else {
debug(msg)
}
Short nit for @ScottyPoi (actually all of this comment is mainly for Scotty of course 😛): it would be good if you also add brackets to one-liner code (so this simple debug(msg)
. We had some bugs lately caused by someone adding something below such a line and not noticing this is not executed in this conditional context. So this would be a bit more on the safe side.
Note: this order change from above would also need to be adjusted in the eth/index.ts
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great start 🎉, some comments. 🙂
packages/devp2p/src/rlpx/peer.ts
Outdated
if (disconnectReason && messageName === 'DISCONNECT') { | ||
if (this.msgDebuggers[disconnectReason]) { | ||
this.msgDebuggers[disconnectReason](msg) | ||
} | ||
} | ||
} else if (this.msgDebuggers[messageName]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These devp2p:127.0.0.1
or devp2p:rlpx:peer:HELLO
prefixes on the log messages are actually only the names of the loggers activated and not a "feature" to display the IP adress on some loggers. 😋
So on your usage this is the correct dedublication, the main point of this whole thing is the we do not have situations where the same message (in the screenshot from above e.g. "Received HELLO message...") is sent multiple times.
And even if only devp2p:rlpx:peer:HELLO
is logged, the remote peer IP is visible in the debug message itself.
That said:
I also tested a local connection along these instructions with the following command:
cd ../devp2p && npm run build && cd ../client && DEBUG=devp2p:127.0.0.1 npm run client:start:dev2 -- --bootnodes=enode://90e0424dff457a1b677b45aa0bf861e71284c45514e944060f8fb3cca65ddc1b241e686e7a9fb8ac37e6090376a4faf379368cc8ad59ae29194ee3126c3e9c88@127.0.0.1:30303
And with the current conditional order the IP logger wouldn't display in this case.
I guess it's enough if we just switch the meesage logger and the IP logger order and keep the rest in place, so this would work for me locally:
const ip = this._socket.remoteAddress
if (disconnectReason && messageName === 'DISCONNECT') {
if (this.msgDebuggers[disconnectReason]) {
this.msgDebuggers[disconnectReason](msg)
}
} else if (ip && this.msgDebuggers[ip]) {
this.msgDebuggers[ip](msg)
} else if (this.msgDebuggers[messageName]) {
this.msgDebuggers[messageName](msg)
} else {
debug(msg)
}
Short nit for @ScottyPoi (actually all of this comment is mainly for Scotty of course 😛): it would be good if you also add brackets to one-liner code (so this simple debug(msg)
. We had some bugs lately caused by someone adding something below such a line and not noticing this is not executed in this conditional context. So this would be a bit more on the safe side.
Note: this order change from above would also need to be adjusted in the eth/index.ts
file.
packages/devp2p/src/rlpx/rlpx.ts
Outdated
// debug( | ||
// `${socket.remoteAddress}:${socket.remotePort} disconnect, reason: ${DISCONNECT_REASONS[reason]}` | ||
// ) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's this? 😀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seemed entirely reduntant to debug messages coming from peer.ts. I left it here commented out in case I was mistaken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am not sure if we loose debug information here in the case we are not triggering the disconnect ourselves but the disconnect got triggered from the peer side.
Maybe double check and/or in doubt just leave, we can always remove this later along continued work since this is not so "core" for this PR to fulfill its purpose.
Ah, just realizing that this special I used: cd ../devp2p && npm run build && cd ../client && DEBUG=devp2p:FIRST_PEER npm run client:start:dev2 -- --bootnodes=enode://90e0424dff457a1b677b45aa0bf861e71284c45514e944060f8fb3cca65ddc1b241e686e7a9fb8ac37e6090376a4faf379368cc8ad59ae29194ee3126c3e9c88@127.0.0.1:30303 Note that this might also not have been working before this PR, didn't test. |
Changed to using the debug.extend() method to create the extended message names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you found the way how to actually properly do this, that's so great!!! 🙏 🙏 🙏
That's a lot better, thanks for digging deeper into this.
One comment on the disconnect debug removal, also please remove all commented out code, I guess otherwise this should be ready for merge.
Great work! 🙂
packages/devp2p/src/rlpx/rlpx.ts
Outdated
// debug( | ||
// `${socket.remoteAddress}:${socket.remotePort} disconnect, reason: ${DISCONNECT_REASONS[reason]}` | ||
// ) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I am not sure if we loose debug information here in the case we are not triggering the disconnect ourselves but the disconnect got triggered from the peer side.
Maybe double check and/or in doubt just leave, we can always remove this later along continued work since this is not so "core" for this PR to fulfill its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks a lot Scotty! 🙂
* VM: Adopted Backwards-compatible Dynamic Gas Cost Refactoring (#1553) * VM: report dynamic gas values in `fee` field of `step` event (#1364) * vm: codes: add dynamicGas property vm: codes: make codes more typesafe * vm: create no-op dynamic gas handlers * vm: first batch of dynamic gas up to 0x3f * vm: add other opcodes to gas map vm: change step event fee type from number to BN vm: deduct dynamic gas vm: fix stack peek vm: do not add gasLimit to gas cost for CREATE * vm: move errors to gas map * vm: fix memory dynamic gas bug * vm: fix gas bugs caused by not considering base fee * vm: fix message call gas related bugs, clone current gas left * add typedoc for peek use underscore for unused peek params (and fix eslint config) format some comment newlines for readability switch from require to import for exceptions * simplify the 2929 state manager castings in runTx * add changelog entry * vm: add EIP1283 tests * vm: split non-eip2929 and eip2929 gas costs * vm: fix gas costs * vm: add early-hardfork coverage * vm: clarify pre-Constantinople SSTORE gas vm: clarify EIP-150 comment * run coverage for all state and blockchain tests, remove redundant istanbul run * vm: fix CALLCODE gas vm: explicitly clone gasLimit for maxCallGas * vm: remove TODO in interpreter * update defaultCost to BN, cast 2929 statemanager to simplify use syntax * use underscore for unused variables, simplify types since they can be inferred * vm: fix browser tests + fix rebase * VM: moved dynamic fee to dedicated dynamicFee field in step event and retained fee behavior and type for backwards compatibility * VM: aligned InterpreterStep and step event object property documentation, completed missing step event properties * VM: test fix * vm: fix hardhat e2e tests * vm: fix MSTORE opcodes * vm: added dynamicGas property to push0 (EIP-3855) opcode * hardhat e2e: add temporary workaround for skipping tests with inconsistent memory field * nit style: use underscore instead of comment out unused variable Co-authored-by: Jochem Brouwer <jochembrouwer96@gmail.com> Co-authored-by: Ryan Ghods <ryan@ryanio.com> * ci: bump karma-typescript version (#1631) * bump karma-typescript to new release * bump libp2p-bootstrap * update package-lock * VM: Jump dest analysis enhancements (#1629) * Change valid jumps to single array * Switch array to Uint8Array * use correct opt code * Check for jumpsub * Address feedback * Address fixes * More efficiency * Adjust if/else logic for efficiency * Move comments Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com> Co-authored-by: Ryan Ghods <ryan@ryanio.com> * rlp: add to root readme (#1642) * add rlp to root readme * add carryforward for rlp flag since it is not always tested on every build unless its paths are modified * Client: Add tests to verify shutdown (#1641) * Add tests to verify client shutdown * Add libp2p test * Address feedback * most libp2p into separate file * VM: Add comparison testing between branchs for State Test Runner (#1634) * Add diff tester and performance * update script * Simplify script * Readme updates * move start * Update stashing logic in script * tx: input value testing (#1620) * tx: helper methods to generate tx values * tx: helper methods to generate tx values * chore: scaffold test and add extra to values * chore: add missing spread operator * chore: single value for each tx key * tx: add generateCombinations method and legacy + eip 1559 test cases * chore: remove console log * chore: use london hardfork for eip1559 * tx: refactor generateCombinations interface and properly compare hash * tx: deterministically randomly sample 1000 elements from array for testing * chore: remove v * chore: remove todo * chore: clearer variable declarations and types * tx: fix and simplify random sampling * tx: display tx hash in testing output * tx: convert buffer to hex for output log * ci: fix node-versions run for node <16 (#1653) * re-add updating to npm v7 for node versions <16 * only upgrade npm for node v <16 * fix bin/rlp js: node 12 doesn't support ES11 which added support for nullish coalescing operator (??) so we'll use ternary here alternatively we could write this file in TS and compile to e.g. dist/bin/rlp (like we do in the client bin), but maybe if the file gets more complicated, in its current state i don't think it's so neccessary * use same errorMsg format for JSON.parse, remove unneeded extra Uint8Array.from (already is uint8array) * rlp: v3 updates from integration (#1648) * rlp updates * util: add arrToBufArr and bufArrToArr and tests * util updates, add deprecation notice for re-exports * rlp tsconfig: include rootDir for composite option * remove util exports deprecation notices * rlp: add readme note for buffer compatibility * undo capitalization * Devp2p, Client: Fix duplicated debug messages (#1643) * devp2p: update debug package * blockchain: update debug package * client: update debug package * vm: update debug package * devp2p/dpt fix for #1485 * devp2p/eth: Fix for 485 * devp2p: Fix for #1485: add base debug * devp2p/dpt #1485: change to debug.extend() * devp2p:dpt:server change to degub.extend() * devp2p:eth change to debug.extend() * devp2p/les: change to debug.extend() * devp2p:rlpx: change to debug.extend() * rlps: change to debug.extend() * Update debug to use IP as first tag * vm, client: removed ProofStateManager interface, added optional getProof, verifyProof methods to StateManager interface (#1660) * Monorepo (& Tx, VM): Examples scripts in CI (#1658) * chore(examples): examples added to ci * chore(examples-ci): remove script from VM (for now) & rename examples workflow file * chore(ci): new script formwatted with prettier & example workflow changes to run with non-test branches Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com> Co-authored-by: Holger Drewes <Holger.Drewes@gmail.com> Co-authored-by: acolytec3 <17355484+acolytec3@users.noreply.github.com> Co-authored-by: Gabriel Rocheleau <contact@rockwaterweb.com> Co-authored-by: ScottyPoi <66335769+ScottyPoi@users.noreply.github.com> Co-authored-by: Cesar Brazon <cesarbrazon10@gmail.com>
Updates debug package to 4.3.3
Also fixes some logic devp2p code that caused multiple debug messages.