@@ -69,7 +69,6 @@ class Pool extends EventEmitter {
6969 this . connected = false ;
7070 this . disconnecting = false ;
7171 this . syncing = false ;
72- this . filterSyncing = false ;
7372 this . discovering = false ;
7473 this . spvFilter = null ;
7574 this . txFilter = null ;
@@ -81,7 +80,6 @@ class Pool extends EventEmitter {
8180 this . pendingRefill = null ;
8281
8382 this . checkpoints = false ;
84- this . neutrino = false ;
8583 this . headerChain = new List ( ) ;
8684 this . headerNext = null ;
8785 this . headerTip = null ;
@@ -90,10 +88,9 @@ class Pool extends EventEmitter {
9088 this . hosts = new HostList ( this . options ) ;
9189 this . id = 0 ;
9290
93- this . getcfheadersStopHash = null ;
9491 this . requestedFilterType = null ;
9592 this . getcfiltersStartHeight = null ;
96- this . getcfiltersStopHash = null ;
93+ this . requestedStopHash = null ;
9794
9895 if ( this . options . spv ) {
9996 this . spvFilter = BloomFilter . fromRate (
@@ -740,7 +737,6 @@ class Pool extends EventEmitter {
740737 if ( ! this . opened || ! this . connected )
741738 return ;
742739
743- this . filterSyncing = true ;
744740 const cFHeaderHeight = await this . chain . getCFHeaderHeight ( ) ;
745741 const startHeight = cFHeaderHeight
746742 ? cFHeaderHeight + 1 : 1 ;
@@ -749,7 +745,7 @@ class Pool extends EventEmitter {
749745 ? 2000 : chainHeight ;
750746 const stopHash = await this . chain . getHash ( stopHeight ) ;
751747 this . requestedFilterType = common . FILTERS . BASIC ;
752- this . getcfheadersStopHash = stopHash ;
748+ this . requestedStopHash = stopHash ;
753749 await this . peers . load . sendGetCFHeaders (
754750 common . FILTERS . BASIC ,
755751 startHeight ,
@@ -766,7 +762,6 @@ class Pool extends EventEmitter {
766762 if ( ! this . opened || ! this . connected )
767763 return ;
768764
769- this . filterSyncing = true ;
770765 const cFilterHeight = await this . chain . getCFilterHeight ( ) ;
771766 const startHeight = cFilterHeight
772767 ? cFilterHeight + 1 : 1 ;
@@ -776,7 +771,7 @@ class Pool extends EventEmitter {
776771 const stopHash = await this . chain . getHash ( stopHeight ) ;
777772 this . requestedFilterType = common . FILTERS . BASIC ;
778773 this . getcfiltersStartHeight = startHeight ;
779- this . getcfiltersStopHash = stopHash ;
774+ this . requestedStopHash = stopHash ;
780775 await this . peers . load . sendGetCFilters (
781776 common . FILTERS . BASIC ,
782777 startHeight ,
@@ -899,17 +894,6 @@ class Pool extends EventEmitter {
899894 return this . sendLocator ( locator , peer ) ;
900895 }
901896
902- // /**
903- // * Sync the filter headers from peer.
904- // * @method
905- // * @param {Peer } peer
906- // * @returns {void }
907- // */
908- //
909- // syncCompactFiltersCheckPt(peer) {
910- // peer.sendGetCFCheckpt(common.FILTERS.BASIC, this.chain.tip.hash);
911- // }
912-
913897 /**
914898 * Send a chain locator and start syncing from peer.
915899 * @method
@@ -1762,7 +1746,9 @@ class Pool extends EventEmitter {
17621746 return ;
17631747
17641748 if ( this . options . neutrino ) {
1765- this . startSync ( ) ;
1749+ const filterHeight = await this . chain . getCFilterHeight ( ) ;
1750+ if ( filterHeight === this . chain . height )
1751+ this . startSync ( ) ;
17661752 return ;
17671753 }
17681754
@@ -1830,6 +1816,8 @@ class Pool extends EventEmitter {
18301816 */
18311817
18321818 async handleTXInv ( peer , hashes ) {
1819+ if ( this . options . neutrino )
1820+ return ;
18331821 assert ( hashes . length > 0 ) ;
18341822
18351823 if ( this . syncing && ! this . chain . synced )
@@ -2178,13 +2166,15 @@ class Pool extends EventEmitter {
21782166 const filterType = packet . filterType ;
21792167
21802168 if ( filterType !== this . requestedFilterType ) {
2169+ this . logger . warning ( 'Received CFHeaders packet with wrong filterType' ) ;
21812170 peer . ban ( ) ;
21822171 peer . destroy ( ) ;
21832172 return ;
21842173 }
21852174
21862175 const stopHash = packet . stopHash ;
2187- if ( ! stopHash . equals ( this . getcfheadersStopHash ) ) {
2176+ if ( ! stopHash . equals ( this . requestedStopHash ) ) {
2177+ this . logger . warning ( 'Received CFHeaders packet with wrong stopHash' ) ;
21882178 peer . ban ( ) ;
21892179 return ;
21902180 }
@@ -2220,7 +2210,7 @@ class Pool extends EventEmitter {
22202210 const nextStopHeight = stopHeight + 2000 < this . chain . height
22212211 ? stopHeight + 2000 : this . chain . height ;
22222212 const nextStopHash = await this . chain . getHash ( nextStopHeight ) ;
2223- this . getcfheadersStopHash = nextStopHash ;
2213+ this . requestedStopHash = nextStopHash ;
22242214 peer . sendGetCFHeaders ( filterType , stopHeight + 1 , nextStopHash ) ;
22252215 }
22262216 }
@@ -2238,16 +2228,18 @@ class Pool extends EventEmitter {
22382228 const filter = packet . filterBytes ;
22392229
22402230 if ( filterType !== this . requestedFilterType ) {
2231+ this . logger . warning ( 'Received CFilter packet with wrong filterType' ) ;
22412232 peer . ban ( ) ;
22422233 peer . destroy ( ) ;
22432234 return ;
22442235 }
22452236
22462237 const blockHeight = await this . chain . getHeight ( blockHash ) ;
2247- const stopHeight = await this . chain . getHeight ( this . getcfiltersStopHash ) ;
2238+ const stopHeight = await this . chain . getHeight ( this . requestedStopHash ) ;
22482239
22492240 if ( ! ( blockHeight >= this . getcfiltersStartHeight
22502241 && blockHeight <= stopHeight ) ) {
2242+ this . logger . warning ( 'Received CFilter packet with wrong blockHeight' ) ;
22512243 peer . ban ( ) ;
22522244 return ;
22532245 }
@@ -2271,7 +2263,7 @@ class Pool extends EventEmitter {
22712263 nextStopHeight = stopHeight + 1000 ;
22722264 const stopHash = await this . chain . getHash ( nextStopHeight ) ;
22732265 this . getcfiltersStartHeight = startHeight ;
2274- this . getcfiltersStopHash = stopHash ;
2266+ this . requestedStopHash = stopHash ;
22752267 this . peers . load . sendGetCFilters (
22762268 common . FILTERS . BASIC ,
22772269 startHeight ,
@@ -2281,7 +2273,7 @@ class Pool extends EventEmitter {
22812273 nextStopHeight = this . chain . height ;
22822274 const stopHash = await this . chain . getHash ( nextStopHeight ) ;
22832275 this . getcfiltersStartHeight = startHeight ;
2284- this . getcfiltersStopHash = stopHash ;
2276+ this . requestedStopHash = stopHash ;
22852277 this . peers . load . sendGetCFilters (
22862278 common . FILTERS . BASIC ,
22872279 startHeight ,
@@ -2290,7 +2282,7 @@ class Pool extends EventEmitter {
22902282 return ;
22912283 }
22922284 } else if ( cFilterHeight === this . chain . height ) {
2293- this . logger . info ( 'CFilters sync complete ') ;
2285+ this . chain . emit ( 'full ') ;
22942286 }
22952287 }
22962288
0 commit comments