[BUG]: Blocks on a different parent are classified INVALID and get the sender banned

Đang mở
#185 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@kansalakshat đang làm issue này rồi.

Từ ngày 15/11/2026.

  • #186 của @kansalakshat — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
blockchain

Hướng nghiên cứu

Start at minichain/chain.py:184, where _apply_block chooses between INVALID and FAILED based on whether "hash" appears in the exception text, and read the previous-hash, index and timestamp checks around it to see how each raises. Reproduce by building two Blockchain() instances from the same genesis, mining block 1 on each, and passing one chain's block to the other to confirm ValidationStatus.INVALID. Note that PR #186 already proposes a one-line change plus a test, so read it before starting rather than duplicating it; done means a parent mismatch returns FAILED and the existing reject/bann path no longer bans an honest peer.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
Bug Description

Blockchain._apply_block picks the rejection status with INVALID if "hash" in str(exc) else FAILED (minichain/chain.py:184). The previous-hash check raises "invalid previous hash ...", which contains "hash", so a block built on a different parent is classified INVALID. With INVALID_THRESHOLD = 1 the sending peer is banned on the first such block, and the ban is persisted.

So two miners that find a block at the same height ban each other, and a node that is 2+ blocks behind bans the peer that gossips the tip (then main.py asks that same peer for a sync).

Proposed fix: only "invalid hash" and "invalid Proof of Work" stay INVALID; a parent mismatch becomes FAILED, like the index and timestamp checks. I have a one-line patch with a test.

Steps to Reproduce
  1. Create two Blockchain() instances from the same genesis.
  2. Mine block 1 on each.
  3. chain_b.add_block(block1_from_a) returns ValidationStatus.INVALID.

Same result when a fresh node receives the tip of a peer that is 2 blocks ahead.

Logs and Screenshots
[WARNING] [minichain.chain] Block 1 rejected: invalid previous hash 8325...addc != 0000...b6f1
same-height fork block from honest peer: ValidationStatus.INVALID
honest peer 2 blocks ahead, we receive its tip: ValidationStatus.INVALID
Environment Details

main @ e16ae98, Python 3.13

Impact

High - Major feature is broken

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
Ngôn ngữ chính
Python
Star
12
Fork
27
Merge trung bình
2 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của StabilityNexus/MiniChain

Tất cả issue của StabilityNexus/MiniChain

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.