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

test: maxuploadtarget: check for mempool msg disconnect if limit is reached, improve existing test coverage #28996

Merged

Conversation

theStack
Copy link
Contributor

@theStack theStack commented Dec 4, 2023

This PR improves existing and adds new test coverage for the -maxuploadtarget mechanism (feature_maxuploadtarget.py) in the following ways, one commit each:

  • verify the uploadtarget state via the getnettotals RPC (uploadtarget result field):

    bitcoin/src/rpc/net.cpp

    Lines 581 to 582 in 160d236

    outboundLimit.pushKV("target_reached", connman.OutboundTargetReached(false));
    outboundLimit.pushKV("serve_historical_blocks", !connman.OutboundTargetReached(true));

    Note that reaching the total limit (target_reached == True) always implies that the historical blocks serving limits is also reached (serve_historical_blocks == False), i.e. it's impossible that both flags are set to True.

  • check for peer's specific disconnect reason (in this case, "historical block serving limit reached, disconnect peer"):

    bitcoin/src/net_processing.cpp

    Lines 2272 to 2280 in 160d236

    // disconnect node in case we have reached the outbound limit for serving historical blocks
    if (m_connman.OutboundTargetReached(true) &&
    (((m_chainman.m_best_header != nullptr) && (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
    !pfrom.HasPermission(NetPermissionFlags::Download) // nodes with the download permission may exceed target
    ) {
    LogPrint(BCLog::NET, "historical block serving limit reached, disconnect peer=%d\n", pfrom.GetId());
    pfrom.fDisconnect = true;
    return;
    }

  • add a test for a peer disconnect if the uploadtarget is reached and a mempool message is received (if bloom filters are enabled):

    bitcoin/src/net_processing.cpp

    Lines 4755 to 4763 in 160d236

    if (m_connman.OutboundTargetReached(false) && !pfrom.HasPermission(NetPermissionFlags::Mempool))
    {
    if (!pfrom.HasPermission(NetPermissionFlags::NoBan))
    {
    LogPrint(BCLog::NET, "mempool request with bandwidth limit reached, disconnect peer=%d\n", pfrom.GetId());
    pfrom.fDisconnect = true;
    }
    return;
    }

    Note that another reason for disconnect after receiving a MEMPOOL msg of a peer is if bloom filters are disabled on the node. This case is already covered in the functional test p2p_nobloomfilter_messages.py.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 4, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK maflcko, sr-gi, achow101

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

…t.py

This ensures that the disconnect happens for the expected reason and
also makes it easier to navigate between implementation and test code,
i.e. both the questions "do we have test coverage for this disconnect?"
(from an implementation reader's perspective) and "where is the code
handling this disconnect?" (from a test reader's perspective) can be
answered simply by grep-ping the corresponding debug message.
…eached

Note that another reason for disconnect after receiving a MEMPOOL msg of a peer
is if bloom filters are disabled on the node. This case is covered in the
functional test `p2p_nobloomfilter_messages.py`.
@theStack theStack force-pushed the 202312-test-verify_maxupload_target_state branch from 541eeef to b58f009 Compare February 5, 2024 17:11
@DrahtBot DrahtBot removed the CI failed label Feb 5, 2024
@maflcko
Copy link
Member

maflcko commented Feb 6, 2024

lgtm ACK b58f009

@glozow glozow requested a review from sr-gi February 6, 2024 10:47
Copy link
Member

@sr-gi sr-gi left a comment

Choose a reason for hiding this comment

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

tACK b58f009

@@ -139,23 +161,32 @@ def run_test(self):
p2p_conns[2].sync_with_ping()
Copy link
Member

Choose a reason for hiding this comment

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

This is sort of unrelated, but it may be worth bringing it in given we are updating this test anyway. The line right above this mentions that the time is advanced by 24 hours and then the checks are performed again. However, the time is actually advance 48 hours: it was previously set to 48 hours in the past, and now it's set to the current time.

I guess it wouldn't hurt to also define SECONDS_PER_DAY = 60*60*24 for readability throughout the test.


# Reconnect to self.nodes[0]
peer = self.nodes[0].add_p2p_connection(TestP2PConn())

# Sending mempool message shouldn't disconnect peer, as total limit isn't reached yet
peer.send_and_ping(msg_mempool())

#retrieve 20 blocks which should be enough to break the 1MB limit
Copy link
Member

@sr-gi sr-gi Feb 6, 2024

Choose a reason for hiding this comment

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

nit: whitespace + caps here

PS: idk why this was pinned here, I meant L181

@achow101
Copy link
Member

achow101 commented Feb 9, 2024

ACK b58f009

@achow101 achow101 merged commit b2b2b1e into bitcoin:master Feb 9, 2024
16 checks passed
@theStack theStack deleted the 202312-test-verify_maxupload_target_state branch February 9, 2024 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants