Skip to content

Conversation

@ariard
Copy link

@ariard ariard commented Sep 4, 2020

Block-relay-only peers were introduced by #15759. According to its
author, it was intented to make them only immune to outbound peer
rotation-based eviction and not from all eviction as modified comment
leans to think of.

Clearly indicate that outbound block-relay peers aren't protected
from eviction by the bad/lagging chain logic.

Fix #19863

Copy link
Member

@sdaftuar sdaftuar left a comment

Choose a reason for hiding this comment

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

The comments above the definition of ChainSyncTimeoutState in net_processing.cpp should also be updated.

Copy link
Member

Choose a reason for hiding this comment

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

How about:

// Note that outbound block-relay peers are excluded from this protection, and thus always subject to eviction under the bad/lagging chain logic.

Copy link
Member

Choose a reason for hiding this comment

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

Also, you may want to consider adding a comment that explains how m_protect is used by stale-tip-based eviction as well. In particular, the stale-tip -> extra full outbound peer logic could cause an existing full outbound to be evicted, but peers with m_protect set will not be chosen for eviction.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. Also added a commit on scope of m_protect w.r.t to both eviction logics.

@ariard ariard force-pushed the 2020-09-clarify-eviction-block-relay branch from b94ebc3 to 6ce273b Compare September 4, 2020 18:38
@ariard
Copy link
Author

ariard commented Sep 4, 2020

Updated at 6ce273b. I guess we could split up m_protect or clarify ChainSyncTimeout name but I don't want to interfere with actual refactoring of CNodeState (#19398). It would be easier to reorganize structures after completion of this project.

@maflcko maflcko changed the title Clarify scope of eviction protection of outbound block-relay peers doc: Clarify scope of eviction protection of outbound block-relay peers Sep 5, 2020
@maflcko maflcko added the Docs label Sep 5, 2020
Block-relay-only peers were introduced by bitcoin#15759. According to its
author, it was intented to make them only immune to outbound peer
rotation-based eviction and not from all eviction as modified comment
leans to think of.

Clearly indicate that outbound block-relay peers aren't protected
from eviction by the bad/lagging chain logic.
@ariard ariard force-pushed the 2020-09-clarify-eviction-block-relay branch from 6ce273b to 706f1f0 Compare September 7, 2020 14:48
@ariard ariard force-pushed the 2020-09-clarify-eviction-block-relay branch from 706f1f0 to b55f979 Compare September 8, 2020 14:35
@ariard
Copy link
Author

ariard commented Sep 8, 2020

Thanks @naumenkogs, took your last suggestion at b55f979

@naumenkogs
Copy link
Contributor

ACK b55f9790194746ce0180fc9fc5e085bdb118432c

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Concept ACK

Copy link
Member

@jonatack jonatack Sep 9, 2020

Choose a reason for hiding this comment

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

b55f9790 suggestions

-    /** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logics.
+    /** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
       *
       * Both are only in effect for outbound, non-manual, non-protected connections.
       * Any peer protected (m_protect = true) is not chosen for eviction. A peer is
-      * marked as protected if :
+      * marked as protected if all of these are true:
       *   - its connection type is IsBlockOnlyConn() == false
       *   - it gave us a valid connecting header
-      *   - it has a better chain than we have
       *   - we haven't reached MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT yet
+      *   - it has a better chain than we have
+      *   - it is not already marked as protected

Copy link
Author

@ariard ariard Sep 9, 2020

Choose a reason for hiding this comment

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

Thanks, I'm going to leave it as it is. It's a bit confusing saying that something is "marked as protected if it is not already marked as protected".

Note, actually CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL are two different logics, thus the plural.

Copy link
Member

@jonatack jonatack Sep 9, 2020

Choose a reason for hiding this comment

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

I'm aware. Logic is most often used as an uncountable noun, but it's not an issue.

While rewriting this, I think it would be good to clarify that the list of conditions is "if all of these" and not "if any of these".

The reordering suggestion is to follow the order of the actual checks.

I verified that the proposed documentation corresponds to the code.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the noun suggestion. Took it, also the re-ordering. But not the "it is not already marked as protected" it's a tautology IMO (it would false future triggering of protection if we don't due to g_outbound_peers_with_protect_from_disconnect is incremented in same conditional, but technically the state transition is defined without)

… logics

The field m_protect is used to protect from eviction both by bad/lagging
chain and extra outbound peers logics. Outbound block-relay peers are
always excluded from this protection.
@ariard ariard force-pushed the 2020-09-clarify-eviction-block-relay branch from b55f979 to d769254 Compare September 10, 2020 13:52
@ariard
Copy link
Author

ariard commented Sep 10, 2020

Updated at d769254, with last @jonatack suggestions.

@naumenkogs
Copy link
Contributor

ACK d769254

/** State used to enforce CHAIN_SYNC_TIMEOUT and EXTRA_PEER_CHECK_INTERVAL logic.
*
* Both are only in effect for outbound, non-manual, non-protected connections.
* Any peer protected (m_protect = true) is not chosen for eviction. A peer is
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 this explanation actually belongs to the declaration of m_protect better, but I don't care enough to ask for this... Consider this if you gonna update it.

@jonatack
Copy link
Member

ACK d769254

Thanks for updating @ariard.

@ariard ariard closed this Sep 22, 2020
@ariard ariard reopened this Sep 22, 2020
@laanwj laanwj merged commit 597488d into bitcoin:master Oct 2, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 4, 2020
…bound block-relay peers

d769254 [doc] Clarify semantic of peer's m_protect w.r.t to outbound eviction logics (Antoine Riard)
ac71fe9 [doc] Clarify scope of eviction protection of outbound block-relay peers (Antoine Riard)

Pull request description:

  Block-relay-only peers were introduced by bitcoin#15759. According to its
  author, it was intented to make them only immune to outbound peer
  rotation-based eviction and not from all eviction as modified comment
  leans to think of.

  Clearly indicate that outbound block-relay peers aren't protected
  from eviction by the bad/lagging chain logic.

  Fix bitcoin#19863

ACKs for top commit:
  naumenkogs:
    ACK d769254
  jonatack:
    ACK d769254

Tree-SHA512: 597fbd62838a6e39276024165b11514cad20a2e9d33cf9202d261cbadcb62b2df427c858e0cb57e585840d4c1d4600104aa53916bb868541f2580e4eed9b4b52
* - its connection type is IsBlockOnlyConn() == false
* - it gave us a valid connecting header
* - we haven't reached MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT yet
* - it has a better chain than we have
Copy link
Contributor

@amitiuttarwar amitiuttarwar Feb 12, 2021

Choose a reason for hiding this comment

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

I don't think this is quite right?

the relevant part of the check in ProcessHeadersMessage checks nodestate->pindexBestKnownBlock->nChainWork >= ::ChainActive().Tip()->nChainWork, aka would set m_protect to true if they have the same chain tip as we do.

I think saying the peer "has a better chain" is misleading, because then I'd expect a long-running node to usually not have protected peers. Based on the logic I see, I'd expect a long-running node to usually have MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT.

what do you think?

Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 3, 2021
Summary:
> [doc] Clarify scope of eviction protection of outbound block-relay peers
>
> Block-relay-only peers were introduced by #15759. According to its
> author, it was intented to make them only immune to outbound peer
> rotation-based eviction and not from all eviction as modified comment
> leans to think of.
>
> Clearly indicate that outbound block-relay peers aren't protected
> from eviction by the bad/lagging chain logic.

> [doc] Clarify semantic of peer's m_protect w.r.t to outbound eviction logics
>
> The field m_protect is used to protect from eviction both by bad/lagging
> chain and extra outbound peers logics. Outbound block-relay peers are
> always excluded from this protection.

This is a backport of [[bitcoin/bitcoin#19871 | core#19871]]

Test Plan: proofreading

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10420
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
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.

Clarify eviction protection scope of outbound block-relay-only peers

7 participants