Skip to content

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Nov 17, 2022

with its pre-existing v23 default value of false, as it is intermittently absent during peer disconnection -- see #26457 (review). Credit to Martin Zumsande for finding this.

This allows dropping the patch in #25176 here, and, if backported to v24, provides API continuity as relaytxes was always present in getpeerinfo since it was introduced in 2015.

Also fix -netinfo relaytxes doc to address #26109 (comment).

Co-authored-by: Martin Zumsande mzumsande@gmail.com

with its pre-existing v23 default value of false, as it would only
potentially be absent (null) during peer disconnection.

Credit to Martin Zumsande for finding this.

This allows to also drop the null check for that field in -netinfo.

Also fix -netinfo relaytxes doc.

Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
@jonatack
Copy link
Member Author

jonatack commented Nov 17, 2022

The GUI Peers details "Transaction Relay" tooltip text in master should be updated, but I haven't included it here to limit this pull to changes only for potential backport. Done in bitcoin-core/gui#681.

@maflcko maflcko changed the title Always return getpeerinfo "relaytxes" field rpc: Always return getpeerinfo "relaytxes" field Nov 17, 2022
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 17, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26727 (rpc: remove optional from fStateStats fields by fanquake)
  • #26621 (refactor: Continue moving application data from CNode to Peer by dergoegge)
  • #26328 (netinfo: fix relaytxes doc, display 3 relaytxes states by jonatack)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

if (fStateStats) {
obj.pushKV("relaytxes", statestats.m_relay_txs);
}
obj.pushKV("relaytxes", fStateStats ? statestats.m_relay_txs : false);
Copy link
Member

Choose a reason for hiding this comment

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

But this is incorrect. The default doesn't matter here - the value that it had for the entire connection is what it should be during disconnection. That value is gone at this point. So either we can't send the field, or can't send the peer entirely. Sending "false" is wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think agree with the statement above, fStateStats is only true if the peer id exists in m_node_states and m_peer_map, so it seems like the node shouldn't exist in the return value at all.

I guess according to the comment at #26457 (review), there is the potential for a race condition, but seems awkward to replicate in the wild as any disconnection removes the nodes pointers and states entirely by the time the rpc is called.

@fanquake
Copy link
Member

fanquake commented Dec 5, 2022

What is the status of this?

Think I agree with the two commentors above. Returning (potentially) incorrect data, just so that we have a value for a field that may otherwise not be present (but only if you're racing a peer disconnect when calling the RPC, where it's unclear if we should even be providing data), doesn't necessarily seem like an improvement.

@mzumsande given that you're listed as co-author, do you have any thoughts?

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

My opinion is that in general, a good rule is that for each field that is optional, we should be able to explain when we do no report it (e.g. during startup) and include that explanation in the RPC help when it's not completely obvious. In principle, the same is true for fields that are not technically optional but have default values. With boolean values, actual optionality seems better because we can't pick a value that is easily recognizable as a default value like "-1" for an integer value or an empty string.

As for the fields of CNodeStateStats I think that the race at shutdown should be fixed. I suggested a simple fix in #26515, if that is not the preferred approach, maybe we could alternatively refactor getpeerinfo to take a lock while gathering data about a peer, making it impossible for peers to be disconnected while the rpc collects the data for a given peer (I haven't looked into this).

@fanquake
Copy link
Member

fanquake commented Dec 6, 2022

As for the fields of CNodeStateStats I think that the race at shutdown should be fixed.

@mzumsande Thanks. I agree, and think either of the approaches, of not returning data when it can't be/isn't complete, or taking a lock and ensuring data is complete, are better approaches than filling fields with default values, in the case that data may be missing.

@jonatack
Copy link
Member Author

Closing in favor of #26328.

@jonatack jonatack closed this Jan 10, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jan 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants