@@ -205,9 +205,17 @@ func (dl *downloadTester) newSlowPeer(id string, version int, hashes []common.Ha
205
205
dl .lock .Lock ()
206
206
defer dl .lock .Unlock ()
207
207
208
- err := dl .downloader .RegisterPeer (id , version , hashes [0 ],
209
- dl .peerGetRelHashesFn (id , delay ), dl .peerGetAbsHashesFn (id , delay ), dl .peerGetBlocksFn (id , delay ),
210
- dl .peerGetRelHeadersFn (id , delay ), dl .peerGetAbsHeadersFn (id , delay ), dl .peerGetBodiesFn (id , delay ))
208
+ var err error
209
+ switch version {
210
+ case 61 :
211
+ err = dl .downloader .RegisterPeer (id , version , hashes [0 ], dl .peerGetRelHashesFn (id , delay ), dl .peerGetAbsHashesFn (id , delay ), dl .peerGetBlocksFn (id , delay ), nil , nil , nil )
212
+ case 62 :
213
+ err = dl .downloader .RegisterPeer (id , version , hashes [0 ], nil , nil , nil , dl .peerGetRelHeadersFn (id , delay ), dl .peerGetAbsHeadersFn (id , delay ), dl .peerGetBodiesFn (id , delay ))
214
+ case 63 :
215
+ err = dl .downloader .RegisterPeer (id , version , hashes [0 ], nil , nil , nil , dl .peerGetRelHeadersFn (id , delay ), dl .peerGetAbsHeadersFn (id , delay ), dl .peerGetBodiesFn (id , delay ))
216
+ case 64 :
217
+ err = dl .downloader .RegisterPeer (id , version , hashes [0 ], nil , nil , nil , dl .peerGetRelHeadersFn (id , delay ), dl .peerGetAbsHeadersFn (id , delay ), dl .peerGetBodiesFn (id , delay ))
218
+ }
211
219
if err == nil {
212
220
// Assign the owned hashes and blocks to the peer (deep copy)
213
221
dl .peerHashes [id ] = make ([]common.Hash , len (hashes ))
@@ -618,6 +626,41 @@ func testMultiSynchronisation(t *testing.T, protocol int) {
618
626
}
619
627
}
620
628
629
+ // Tests that synchronisations behave well in multi-version protocol environments
630
+ // and not wreak havok on other nodes in the network.
631
+ func TestMultiProtocolSynchronisation61 (t * testing.T ) { testMultiProtocolSynchronisation (t , 61 ) }
632
+ func TestMultiProtocolSynchronisation62 (t * testing.T ) { testMultiProtocolSynchronisation (t , 62 ) }
633
+ func TestMultiProtocolSynchronisation63 (t * testing.T ) { testMultiProtocolSynchronisation (t , 63 ) }
634
+ func TestMultiProtocolSynchronisation64 (t * testing.T ) { testMultiProtocolSynchronisation (t , 64 ) }
635
+
636
+ func testMultiProtocolSynchronisation (t * testing.T , protocol int ) {
637
+ // Create a small enough block chain to download
638
+ targetBlocks := blockCacheLimit - 15
639
+ hashes , blocks := makeChain (targetBlocks , 0 , genesis )
640
+
641
+ // Create peers of every type
642
+ tester := newTester ()
643
+ tester .newPeer ("peer 61" , 61 , hashes , blocks )
644
+ tester .newPeer ("peer 62" , 62 , hashes , blocks )
645
+ tester .newPeer ("peer 63" , 63 , hashes , blocks )
646
+ tester .newPeer ("peer 64" , 64 , hashes , blocks )
647
+
648
+ // Synchronise with the requestd peer and make sure all blocks were retrieved
649
+ if err := tester .sync (fmt .Sprintf ("peer %d" , protocol ), nil ); err != nil {
650
+ t .Fatalf ("failed to synchronise blocks: %v" , err )
651
+ }
652
+ if imported := len (tester .ownBlocks ); imported != targetBlocks + 1 {
653
+ t .Fatalf ("synchronised block mismatch: have %v, want %v" , imported , targetBlocks + 1 )
654
+ }
655
+ // Check that no peers have been dropped off
656
+ for _ , version := range []int {61 , 62 , 63 , 64 } {
657
+ peer := fmt .Sprintf ("peer %d" , version )
658
+ if _ , ok := tester .peerHashes [peer ]; ! ok {
659
+ t .Errorf ("%s dropped" , peer )
660
+ }
661
+ }
662
+ }
663
+
621
664
// Tests that if a block is empty (i.e. header only), no body request should be
622
665
// made, and instead the header should be assembled into a whole block in itself.
623
666
func TestEmptyBlockShortCircuit62 (t * testing.T ) { testEmptyBlockShortCircuit (t , 62 ) }
0 commit comments