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

Client: fix rpc debug #3125

Merged
merged 6 commits into from
Nov 5, 2023
Merged

Client: fix rpc debug #3125

merged 6 commits into from
Nov 5, 2023

Conversation

jochem-brouwer
Copy link
Member

@jochem-brouwer jochem-brouwer commented Oct 30, 2023

The rpc debug is inconsistent and this PR fixes it. Currently it seems to always truncate RPC logs.

It adds a new flag rpcDebugVerbose which allows for a comma-separated list of methods to log in full. Same for rpcDebug, this logs the commands but will truncate those. If both rpcDebugVerbose and rpcDebug filters match the method, the log is not truncated. The necessity to --loglevel debug is removed to log the methods in full (the logs are written to INFO).

TODO: explicitly test this (but this should work)

Note: it is also possible to skip adding this new flag, and instead adding the word "verbose" to rpcDebug as suggested by Holger. However, this would imply that then all methods which match the filter are logged in verbose and I think this extra flag option gives us more freedom to explicitly verbose-log these methods.

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Merging #3125 (7088542) into master (1723406) will decrease coverage by 0.04%.
The diff coverage is 94.87%.

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 88.80% <ø> (ø)
blockchain 92.27% <ø> (ø)
client 86.14% <94.87%> (-0.05%) ⬇️
common 98.19% <ø> (ø)
devp2p 86.32% <ø> (ø)
ethash ∅ <ø> (∅)
evm 71.93% <ø> (ø)
statemanager 90.13% <ø> (ø)
trie 89.72% <ø> (-0.34%) ⬇️
tx 96.36% <ø> (ø)
util 87.53% <ø> (ø)
vm 76.22% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@holgerd77
Copy link
Member

RPC log truncating has a reason being mainly that from some RPC calls - particularly from the engine API - are so large that without truncating it is not possible any more to follow on the logging.

Can't completely oversee the changes from this PR respectively what it does and what not, but we need to find a good balance here to for one allow that it becomes possible - if one is interested in the outcome of one particular call - to see the full output. And on the other hand that RPC logging also allows for this "overview log", so that one has a constant ouptut of calls without getting overwhelmed.

@jochem-brouwer
Copy link
Member Author

Just some clarification, without this PR it seems that rpcDebug does not work, we launch hive with these flags:

--gethGenesis ./genesis.json --rpc --rpcEngine --saveReceipts --rpcAddr 0.0.0.0 --rpcEngineAddr 0.0.0.0 --rpcEnginePort 8551 --ws false --logLevel debug --rpcDebug all --isSingleNode

Note: --rpcDebug all. This still truncates logs (without this PR). This PR fixes this.

@holgerd77
Copy link
Member

Yes, not sure if my comment was clear: rpcDebug logs needs to be truncated at least as an option, otherwise this becomes completely unreadable for certain use cases.

I wonder if we eventually want to bite the sour bullet or whatever and DO another explicit option here?? --truncateRPCLogs or whatever? Since this is definitely otherwise totally intransparent and also gave me headaches as well in the past. But one definitely needs both.

Side note: beyond there are some RPC log inconsistencies in the client, e.g. parts of the (core) engine API (I think FCU and newPayload() ?) is not logged through the option but on normal debug mode, which is confusing and we should fix as well at some point.

@jochem-brouwer
Copy link
Member Author

jochem-brouwer commented Oct 31, 2023

Ah ok good point, I just re-checked, we have this (also in this PR - it is unchanged), see client/src/util/rpc.ts.

      if (show) {
        if (logger?.level === 'debug') {
          msg += `${request.method} called with params:\n${inspectParams(request.params)}`
        } else {
          msg += `${request.method} called with params: ${inspectParams(request.params, 125)}`
        }
        logger?.info(msg)
      }

Therefore, if --rpcDebug is enabled but --loglevel is not set to debug, the logs are truncated (by 125 chars) by default. So to get full logs, one has to explicitly set --loglevel to debug. (However this might raise the question: do we want an extra flag to actually --loglevel debug but not dump the rpcDebug completely (so truncate it)? (Especially for blob txs these might indeed get very large!))

const onRequest = (request: any) => {
let msg = ''
if (rpcDebug && rpcDebug !== '') {
let show = false
if (rpcDebug === 'all') {
if (rpcDebug === '' || rpcDebug === 'all') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are earlier checking rpcDebug !== '' then we shouldn't need to check again if rpcDebug === ''.

@@ -207,7 +207,8 @@ const args: ClientOpts = yargs(hideBin(process.argv))
.option('rpcDebug', {
describe:
'Additionally log complete RPC calls filtered by name (prefix), e.g.: "eth,engine_getPayload" (use "all" for all methods).',
default: '',
coerce: (arg: string) => (arg === '' ? 'all' : arg),
Copy link
Contributor

@scorbajio scorbajio Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I initially changed rpcDebug to allow for indicating a specific package for full request/response log output, I included a description with details about the need for logLevel being set to debug and also included choices which allowed for boolean options or a specific module to be enabled by name, as well as a default of false: b196a13. But now that we can pass in a comma separated string that could also include specific function names (e.g. eth,engine_getPayload), I think that we can look into using a yargs check function for the rpcDebug option to first validate the input and throw helpful error messages so users aren't confused as well as extend our description to include more usage details and maybe even some examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, would agree that this is a thing that we should well-document (also for ourselves).

@@ -207,7 +207,8 @@ const args: ClientOpts = yargs(hideBin(process.argv))
.option('rpcDebug', {
describe:
'Additionally log complete RPC calls filtered by name (prefix), e.g.: "eth,engine_getPayload" (use "all" for all methods).',
default: '',
Copy link
Contributor

@scorbajio scorbajio Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a default value can be more intuitive than removing it and instead having to handle undefined as a value.

@holgerd77
Copy link
Member

Ah ok good point, I just re-checked, we have this (also in this PR - it is unchanged), see client/src/util/rpc.ts.

      if (show) {
        if (logger?.level === 'debug') {
          msg += `${request.method} called with params:\n${inspectParams(request.params)}`
        } else {
          msg += `${request.method} called with params: ${inspectParams(request.params, 125)}`
        }
        logger?.info(msg)
      }

Therefore, if --rpcDebug is enabled but --loglevel is not set to debug, the logs are truncated (by 125 chars) by default. So to get full logs, one has to explicitly set --loglevel to debug. (However this might raise the question: do we want an extra flag to actually --loglevel debug but not dump the rpcDebug completely (so truncate it)? (Especially for blob txs these might indeed get very large!))

Yes, I was aware of this: debug -> full RPC log, otherwise -> truncated behavior.

And, yes, I think it would be worth to be able to tackle this separately (I can vaguely remember that I might have already tried on the sideline at some point?).

So an alternative to yet-another-flag might be that we add a keyword verbose to the existing option (important to add a note to CLI help as well then).

If this is added we do full logging (--rpcDebug=all,verbose, --rpcDebug=eth,verbose,...) otherwise we truncate.

@jochem-brouwer
Copy link
Member Author

Have tested using some hive tests and can report that it works like the top post suggests. CI should also pass.

Copy link
Contributor

@scorbajio scorbajio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

}
logger?.info(msg)
}
if (checkFilter(request.method, rpcDebugVerbose)) {
Copy link
Contributor

@scorbajio scorbajio Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To note, the options are:

  • both rpcDebugVerbose and rpcDebug are true, in which case the full version will be logged
  • both rpcDebugVerbose and rpcDebug are false, in which case nothing will be logged on requests and responses
  • rpcDebugVerbose is true and rpcDebug is false, in which case the full version will be logged
  • rpcDebugVerbose is false and rpcDebug is true, in which case the truncated version will be logged

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, so for extra for clarification: the true and false are the returned values from this method, and are thus applied on the filter. If there is no filter (the filter is the empty string by default, so "no filter") then it always returns false.

@scorbajio scorbajio merged commit 49f3cca into master Nov 5, 2023
44 checks passed
@scorbajio scorbajio deleted the fix-rpc-debug branch November 5, 2023 22:40
@jochem-brouwer
Copy link
Member Author

Have opened a PR for hive to update as well: ethereum/hive#939

@holgerd77
Copy link
Member

Maybe I missed this: what was the reasoning here again to go for the yet-another-flag solution in favor to an existing-flag using version like --rpcDebug=verbose,eth or similar?

@jochem-brouwer
Copy link
Member Author

The reasoning is that you can now for instance log verbose logs for engine_newPayload, but choose to only log truncated eth_sendRawTransaction (especially blob txs are huge). We could also settle for a very specific format inside the rpcDebug flag if that is desired and drop the new flag.

@holgerd77
Copy link
Member

Ah ok, no, makes sense, cool, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants