@ -698,6 +698,7 @@ func testInvalidNumberAnnouncement(t *testing.T, light bool) {
badBodyFetcher := tester . makeBodyFetcher ( "bad" , blocks , 0 )
badBodyFetcher := tester . makeBodyFetcher ( "bad" , blocks , 0 )
imported := make ( chan interface { } )
imported := make ( chan interface { } )
announced := make ( chan interface { } )
tester . fetcher . importedHook = func ( header * types . Header , block * types . Block ) {
tester . fetcher . importedHook = func ( header * types . Header , block * types . Block ) {
if light {
if light {
if header == nil {
if header == nil {
@ -712,9 +713,23 @@ func testInvalidNumberAnnouncement(t *testing.T, light bool) {
}
}
}
}
// Announce a block with a bad number, check for immediate drop
// Announce a block with a bad number, check for immediate drop
tester . fetcher . announceChangeHook = func ( hash common . Hash , b bool ) {
announced <- nil
}
tester . fetcher . Notify ( "bad" , hashes [ 0 ] , 2 , time . Now ( ) . Add ( - arriveTimeout ) , badHeaderFetcher , badBodyFetcher )
tester . fetcher . Notify ( "bad" , hashes [ 0 ] , 2 , time . Now ( ) . Add ( - arriveTimeout ) , badHeaderFetcher , badBodyFetcher )
verifyAnnounce := func ( ) {
for i := 0 ; i < 2 ; i ++ {
select {
case <- announced :
continue
case <- time . After ( 1 * time . Second ) :
t . Fatal ( "announce timeout" )
return
}
}
}
verifyAnnounce ( )
verifyImportEvent ( t , imported , false )
verifyImportEvent ( t , imported , false )
tester . lock . RLock ( )
tester . lock . RLock ( )
dropped := tester . drops [ "bad" ]
dropped := tester . drops [ "bad" ]
tester . lock . RUnlock ( )
tester . lock . RUnlock ( )
@ -722,11 +737,11 @@ func testInvalidNumberAnnouncement(t *testing.T, light bool) {
if ! dropped {
if ! dropped {
t . Fatalf ( "peer with invalid numbered announcement not dropped" )
t . Fatalf ( "peer with invalid numbered announcement not dropped" )
}
}
goodHeaderFetcher := tester . makeHeaderFetcher ( "good" , blocks , - gatherSlack )
goodHeaderFetcher := tester . makeHeaderFetcher ( "good" , blocks , - gatherSlack )
goodBodyFetcher := tester . makeBodyFetcher ( "good" , blocks , 0 )
goodBodyFetcher := tester . makeBodyFetcher ( "good" , blocks , 0 )
// Make sure a good announcement passes without a drop
// Make sure a good announcement passes without a drop
tester . fetcher . Notify ( "good" , hashes [ 0 ] , 1 , time . Now ( ) . Add ( - arriveTimeout ) , goodHeaderFetcher , goodBodyFetcher )
tester . fetcher . Notify ( "good" , hashes [ 0 ] , 1 , time . Now ( ) . Add ( - arriveTimeout ) , goodHeaderFetcher , goodBodyFetcher )
verifyAnnounce ( )
verifyImportEvent ( t , imported , true )
verifyImportEvent ( t , imported , true )
tester . lock . RLock ( )
tester . lock . RLock ( )