@@ -529,6 +529,27 @@ including service interface, peer discovery, and network protocol interactions.
529529
530530# ### Complete Block Request Flow
531531
532+ The protocol supports two strategies for WantBlock requests,
533+ each with different trade- offs.
534+ Implementations may choose the strategy based on network conditions,
535+ peer availability, and resource constraints.
536+
537+ # #### Strategy 1: Parallel Request (Low Latency)
538+
539+ In this strategy, the requester sends `wantType = wantBlock` to all
540+ discovered peers simultaneously.
541+ This minimizes latency as the first peer to respond with the block
542+ data wins, but it wastes bandwidth since multiple peers may send
543+ the same block data.
544+
545+ ** Trade- offs:**
546+
547+ - ** Pro** : Lowest latency - block arrives as soon as any peer can deliver it
548+ - ** Pro** : More resilient to slow or unresponsive peers
549+ - ** Con** : Bandwidth- wasteful - multiple peers may send duplicate data
550+ - ** Con** : Higher network overhead for the requester
551+ - ** Best for ** : Time- critical data retrieval, unreliable networks
552+
532553```mermaid
533554sequenceDiagram
534555 participant Client
@@ -537,37 +558,115 @@ sequenceDiagram
537558 participant Discovery
538559 participant PeerA
539560 participant PeerB
561+ participant PeerC
540562
541563 Client-> > BlockExchange: requestBlock(address)
542564 BlockExchange-> > LocalStore: checkBlock(address)
565+ LocalStore-- >> BlockExchange: Not found
543566
544- alt Block in local storage
545- LocalStore-- >> BlockExchange: Block found
546- BlockExchange-- >> Client: Return block
547- else Block not local
548- LocalStore-- >> BlockExchange: Not found
549- BlockExchange-> > Discovery: findPeers(address)
550- Discovery-- >> BlockExchange: [PeerA, PeerB]
551-
552- par Send to multiple peers
553- BlockExchange-> > PeerA: Message(wantlist)
554- BlockExchange-> > PeerB: Message(wantlist)
555- end
567+ BlockExchange-> > Discovery: findPeers(address)
568+ Discovery-- >> BlockExchange: [PeerA, PeerB, PeerC]
556569
557- alt PeerA has block
558- PeerA-- >> BlockExchange: Message(blockPresences, payload)
559- BlockExchange-> > BlockExchange: Verify block
560- BlockExchange-> > LocalStore: Store block
561- BlockExchange-> > PeerB: Message(wantlist.cancel)
562- BlockExchange-- >> Client: Return block
563- else PeerA doesn' t have
564- PeerA-- >> BlockExchange: Message(blockPresences.dontHave)
565- PeerB-- >> BlockExchange: Message(payload)
566- BlockExchange-> > BlockExchange: Verify block
567- BlockExchange-> > LocalStore: Store block
568- BlockExchange-- >> Client: Return block
569- end
570+ par Send wantBlock to all peers
571+ BlockExchange-> > PeerA: Message(wantlist: wantBlock)
572+ BlockExchange-> > PeerB: Message(wantlist: wantBlock)
573+ BlockExchange-> > PeerC: Message(wantlist: wantBlock)
574+ end
575+
576+ Note over PeerA,PeerC: All peers start preparing block data
577+
578+ PeerB-- >> BlockExchange: Message(payload: BlockDelivery)
579+ Note over BlockExchange: First response wins
580+
581+ BlockExchange-> > BlockExchange: Verify block
582+ BlockExchange-> > LocalStore: Store block
583+
584+ par Cancel requests to other peers
585+ BlockExchange-> > PeerA: Message(wantlist: cancel)
586+ BlockExchange-> > PeerC: Message(wantlist: cancel)
587+ end
588+
589+ Note over PeerA,PeerC: May have already sent data (wasted bandwidth)
590+
591+ BlockExchange-- >> Client: Return block
592+ ```
593+
594+ # #### Strategy 2: Two-Phase Discovery (Bandwidth Efficient)
595+
596+ In this strategy, the requester first sends `wantType = wantHave` to
597+ discover which peers have the block, then sends `wantType = wantBlock`
598+ only to a single selected peer.
599+ This conserves bandwidth but adds an extra round - trip of latency.
600+
601+ ** Trade- offs:**
602+
603+ - ** Pro** : Bandwidth- efficient - only one peer sends block data
604+ - ** Pro** : Enables price comparison before committing to a peer
605+ - ** Pro** : Allows selection based on peer reputation or proximity
606+ - ** Con** : Higher latency due to extra round - trip for presence check
607+ - ** Con** : Selected peer may become unavailable between phases
608+ - ** Best for ** : Large blocks, paid content, bandwidth- constrained networks
609+
610+ ```mermaid
611+ sequenceDiagram
612+ participant Client
613+ participant BlockExchange
614+ participant LocalStore
615+ participant Discovery
616+ participant PeerA
617+ participant PeerB
618+ participant PeerC
619+
620+ Client-> > BlockExchange: requestBlock(address)
621+ BlockExchange-> > LocalStore: checkBlock(address)
622+ LocalStore-- >> BlockExchange: Not found
623+
624+ BlockExchange-> > Discovery: findPeers(address)
625+ Discovery-- >> BlockExchange: [PeerA, PeerB, PeerC]
626+
627+ Note over BlockExchange: Phase 1 : Discovery
628+
629+ par Send wantHave to all peers
630+ BlockExchange-> > PeerA: Message(wantlist: wantHave)
631+ BlockExchange-> > PeerB: Message(wantlist: wantHave)
632+ BlockExchange-> > PeerC: Message(wantlist: wantHave)
570633 end
634+
635+ PeerA-- >> BlockExchange: BlockPresence(presenceDontHave)
636+ PeerB-- >> BlockExchange: BlockPresence(presenceHave, price = X)
637+ PeerC-- >> BlockExchange: BlockPresence(presenceHave, price = Y)
638+
639+ BlockExchange-> > BlockExchange: Select best peer (PeerB: lower price)
640+
641+ Note over BlockExchange: Phase 2 : Retrieval
642+
643+ BlockExchange-> > PeerB: Message(wantlist: wantBlock)
644+ PeerB-- >> BlockExchange: Message(payload: BlockDelivery)
645+
646+ BlockExchange-> > BlockExchange: Verify block
647+ BlockExchange-> > LocalStore: Store block
648+ BlockExchange-- >> Client: Return block
649+ ```
650+
651+ # #### Hybrid Approach
652+
653+ Implementations MAY combine both strategies:
654+
655+ 1 . Use two- phase discovery for large blocks or paid content
656+ 2 . Use parallel requests for small blocks or time- critical data
657+ 3 . Adaptively switch strategies based on network conditions
658+
659+ ```mermaid
660+ flowchart TD
661+ A[Block Request] -- > B{Block Size? }
662+ B -- > | Small < 64 KiB| C[Parallel Strategy]
663+ B -- > | Large >= 64 KiB| D{Paid Content? }
664+ D -- > | Yes| E[Two- Phase Discovery]
665+ D -- > | No| F{Network Condition? }
666+ F -- > | Reliable| E
667+ F -- > | Unreliable| C
668+ C -- > G[Return Block]
669+ E -- > G
571670```
572671
573672# ### Dataset Block Verification Flow
0 commit comments