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

fix: incorrect and inadequate checks of sync message #4192

Merged

Conversation

yangby-cryptape
Copy link
Collaborator

What problem does this PR solve?

The checks of sync message are incorrect and inadequate since CKB2021.

if let packed::SyncMessageUnionReader::SendBlock(ref reader) = item {
if reader.count_extra_fields() > 1 {
info!(
"Peer {} sends us a malformed message: \
too many fields in SendBlock",
peer_index
);
nc.ban_peer(
peer_index,
BAD_MESSAGE_BAN_TIME,
String::from(
"send us a malformed message: \
too many fields in SendBlock",
),
);
return;

  • SendBlock is the same before and after CKB2021, so the result of checks is always be true.

    table SendBlock {
    block: Block,
    }

  • The Block could have 1 more field after CKB2021.

    table Block {
    header: Header,
    uncles: UncleBlockVec,
    transactions: TransactionVec,
    proposals: ProposalShortIdVec,
    }

    table BlockV1 {
    header: Header,
    uncles: UncleBlockVec,
    transactions: TransactionVec,
    proposals: ProposalShortIdVec,
    extension: Bytes,
    }

  • As a comparison, the checks of relay message are correct.

    ckb/sync/src/relayer/mod.rs

    Lines 780 to 781 in 5dadcbf

    if let packed::RelayMessageUnionReader::CompactBlock(ref reader) = item {
    if reader.count_extra_fields() > 1 {

    table CompactBlock {
    header: Header,
    short_ids: ProposalShortIdVec,
    prefilled_transactions: IndexTransactionVec,
    uncles: Byte32Vec,
    proposals: ProposalShortIdVec,
    }
    table CompactBlockV1 {
    header: Header,
    short_ids: ProposalShortIdVec,
    prefilled_transactions: IndexTransactionVec,
    uncles: Byte32Vec,
    proposals: ProposalShortIdVec,
    extension: Bytes,
    }

Check List

Tests

  • Unit test
  • Integration test

Release note

Title Only: Include only the PR title in the release note.

@yangby-cryptape yangby-cryptape marked this pull request as ready for review October 13, 2023 08:48
@yangby-cryptape yangby-cryptape requested a review from a team as a code owner October 13, 2023 08:48
@yangby-cryptape yangby-cryptape requested review from quake and removed request for a team October 13, 2023 08:48
@quake quake added this pull request to the merge queue Oct 13, 2023
Merged via the queue into nervosnetwork:develop with commit c9efe08 Oct 13, 2023
34 checks passed
@doitian doitian mentioned this pull request Dec 18, 2023
@yangby-cryptape yangby-cryptape deleted the bugfix/incorrect-checks branch January 9, 2024 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants