[BUG]: P2P sync downloads full 500-block chunks without headers-first validation
I maintainer di solito rispondono entro 1 giorno
@anshulchikhale30-p ci sta già lavorando.
Dal 8/11/2026.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- distributed-systems, networking
Direzione di ricerca
Start with main.py handlers request_chain, chain_request, and chain_response, then read minichain/p2p.py and minichain/chain.py to understand current sync and validation. Run the existing test suite and inspect its sync coverage before planning the new tests named in the issue. Done means header-first sync, bounded and rate-limited body requests, peer handling for invalid data, and the stated acceptance criteria are implemented and documented in docs/sync.md.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Description
MiniChain's P2P sync downloads up to 500 full blocks per request and has no headers-first phase or block locator. When a peer's tip is ahead, main.py calls request_chain(network, chain.last_block.index + 1, 500); on a fork it requests up to 50 blocks backward. This works for small local chains but is inefficient and unsafe at scale.
Current behavior:
request_chainbroadcasts achain_requestwithstart_indexandlimit=500.chain_requestserveschain.chain[start_index:start_index+limit]and sends every full block (header + transactions + receipts).chain_responseparses all received blocks into memory and applies them one by one.- There is no
getheaders/headersphase and no block locator, so an invalid chain is only discovered after downloading entire bodies. chain_requestacceptsstart_indexandlimitwithout bounds; a peer can request a very large range or send a very large response.- There is no request ID/response correlation, no maximum response size, and no per-peer sync rate limit.
p2p.pycoverage is 37% (README), so these paths are under-tested.
Impact:
- Slow sync and high memory use on long chains.
- Wasted bandwidth and CPU on invalid or adversarial chains.
- DoS vector via oversized requests/responses or request floods.
- Repeated 50-block backward scans on forks.
- Multi-node research at 10k+ blocks is impractical.
Expected behavior:
- Sync headers first with a locator, validate the header chain (PoW, target, timestamp, parent linkage, cumulative work), then download bodies in bounded batches.
- Bound request/response sizes, add request IDs, unicast to one peer, and rate-limit per peer.
- Disconnect or ban peers that send invalid or oversized data.
Proposed fix:
- Add
getheaderswith a locator (recent block hashes),stop_hash, andmax(e.g. 2000), plus aheadersresponse. - Validate headers before bodies: PoW, target, timestamp, parent linkage, cumulative work.
- Add
getblockby hash or bounded range; fetch bodies in small batches (e.g. 64 blocks) with a maximum number of in-flight requests. - Verify transaction root, receipt root, and state root after executing the bodies.
- Add request IDs, unicast requests to one peer, and deduplicate responses.
- Cap
start_index,limit, and response bytes; add a per-peer token bucket. - Feed invalid or oversized responses into the existing validation counters and ban repeat offenders.
- Add tests for 10k-block sync, 100-block reorg, invalid headers, invalid bodies, oversized requests/responses, restart mid-sync, and rate limiting.
- Document the protocol and limits in
docs/sync.md.
Acceptance criteria:
- 10k-block sync completes within an agreed target and bounded memory.
- Headers are validated before bodies are downloaded.
- Fork detection uses a locator, not repeated 50-block scans.
- Requests and responses are bounded and rate-limited.
- Invalid or oversized peers are disconnected or banned.
- No unbounded queues or response buffers.
-
p2p.pycoverage is at least 65%. - Sync protocol and limits are documented.
Relevant files:
main.py(request_chain,chain_request,chain_response)minichain/p2p.pyminichain/chain.pytests/test_sync.py(new)tests/test_p2p_limits.py(new)
References:
- Bitcoin P2P network guide: https://developer.bitcoin.org/devguide/p2p_network.html
- Bitcoin protocol documentation: https://en.bitcoin.it/wiki/Protocol_documentation
- BIP 152 compact block relay (optional future work): https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
Steps to Reproduce
- Start two nodes on different ports with separate data directories.
- Let one node mine more than 500 blocks.
- Connect the second node to the first node.
- Observe the
hellohandler requestchain_requestwithlimit=500, followed by full-blockchain_responsepayloads. - For the adversarial case, send a
chain_requestwith a very largelimit, or send achain_responsecontaining a very large list of blocks, and observe memory/CPU use.
Logs and Screenshots
Relevant log lines include:
?? Peer ... is ahead (...) . Initiating chunked sync...
?? Peer requested blocks from ... (limit 500).
No screenshots available.
Environment Details
- OS: Windows 11 / Linux
- Python 3.10+
- MiniChain
mainbranch as of 2026-11-08 p2p.pycoverage: 37% (README coverage report)
Impact
High - Major feature is broken (sync works for small chains, but is not safe or efficient at scale).
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
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di StabilityNexus/MiniChain
-
[BUG]: Handle JSON-RPC notifications and empty batches correctlyForse già presa @Muneerali199 l’ha presa 10 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
StabilityNexus/MiniChain#177 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
automatic-copyright-year: keep README copyright currentForse già presa @anshulchikhale30-p l’ha presa 7 giorni fa. Apertadocumentation enhancement
Difficoltà 3/5 Mezza giornata Idoneità per principianti 35/100
StabilityNexus/MiniChain#189 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficulty: bound per-block EMA moves, add a difficulty floor, and preserve state across restartsForse già presa @anshulchikhale30-p l’ha presa 7 giorni fa. Apertabug documentation enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
StabilityNexus/MiniChain#187 ·
I maintainer di solito rispondono entro 1 giorno
-
[BUG]: Blocks on a different parent are classified INVALID and get the sender bannedForse già presa @kansalakshat l’ha presa 7 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
StabilityNexus/MiniChain#185 ·
I maintainer di solito rispondono entro 1 giorno
-
[FEATURE]: Add transaction and receipt lookup RPC methodsForse già presa @Thushara3005 l’ha presa 10 giorni fa. Apertaenhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 58/100
StabilityNexus/MiniChain#176 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di StabilityNexus/MiniChain
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
huggingface/datasets#9128 ·
I maintainer di solito rispondono entro 1 giorno
-
priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
OpenHands/extensions#975 ·
I maintainer di solito rispondono entro 1 giorno
-
Function/dict state handlers can't supply provider-state injected values (`generate.provider_state`)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
pact-foundation/pact-python#1789 ·
I maintainer di solito rispondono entro 9 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
juandresrodca/AdminForge#66 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno