Skip to content

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

Merged
achow101 merged 3 commits into
bitcoin:masterfrom
theStack:202312-test-verify_maxupload_target_state
Feb 9, 2024
Merged

achow101 merged 3 commits into
bitcoin:masterfrom
theStack:202312-test-verify_maxupload_target_state

Conversation

@theStack

@theStack theStack commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

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

DrahtBot commented Dec 4, 2023 •

Copy link
Copy Markdown
Contributor

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

maflcko commented Feb 6, 2024

Copy link
Copy Markdown
Member

lgtm ACK b58f009

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

@sr-gi sr-gi left a comment •

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

# 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

@sr-gi sr-gi Feb 6, 2024 •

Copy link
Copy Markdown
Member

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

achow101 commented Feb 9, 2024

Copy link
Copy Markdown
Member

ACK b58f009

@achow101
achow101 merged commit b2b2b1e into bitcoin:master Feb 9, 2024
@theStack
theStack deleted the 202312-test-verify_maxupload_target_state branch February 9, 2024 00:42
@bitcoin bitcoin locked and limited conversation to collaborators Feb 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants