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

Aperta
#185 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@kansalakshat ci sta già lavorando.

Dal 15/11/2026.

  • #186 di @kansalakshat — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
blockchain

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
12
Fork
27
Merge medio
2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di StabilityNexus/MiniChain

Tutte le issue di StabilityNexus/MiniChain

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.