@@ -223,9 +223,10 @@ class Pool extends EventEmitter {
223223
224224 const tip = this . chain . tip ;
225225 if ( this . options . neutrino ) {
226- // this.headerTip = tip;
227- this . headerChain . push ( new HeaderEntry ( tip . hash , tip . height ) ) ;
228- return ;
226+ this . headerChain . push ( new HeaderEntry ( tip . hash , tip . height ) ) ;
227+ this . cfHeaderChain = new List ( ) ;
228+ this . cfHeaderChain . push ( new CFHeaderEntry ( consensus . ZERO_HASH , 0 ) ) ;
229+ return ;
229230 }
230231 if ( tip . height < this . network . lastCheckpoint ) {
231232 this . checkpoints = true ;
@@ -648,7 +649,7 @@ class Pool extends EventEmitter {
648649
649650 peer . loader = true ;
650651 this . peers . load = peer ;
651- this . sendSync ( peer ) ;
652+ this . sendSync ( peer ) ;
652653
653654 this . emit ( 'loader' , peer ) ;
654655 }
@@ -730,8 +731,11 @@ class Pool extends EventEmitter {
730731 return ;
731732
732733 this . filterSyncing = true ;
733- const startHeight = 0 ;
734- const stopHash = await this . chain . getHash ( 29 ) ;
734+ const startHeight = 1 ;
735+ const chainHeight = await this . chain . tip . height ;
736+ console . log ( 'chainHeight' , chainHeight ) ;
737+ const stopHeight = chainHeight > 2000 ? 2000 : chainHeight ;
738+ const stopHash = await this . chain . getHash ( stopHeight ) ;
735739 this . peers . load . sendGetCFHeaders (
736740 common . FILTERS . BASIC ,
737741 startHeight ,
@@ -772,7 +776,7 @@ class Pool extends EventEmitter {
772776 async startHeadersSync ( ) {
773777 if ( ! this . syncing )
774778 return ;
775-
779+ console . log ( 'startHeadersSync' ) ;
776780 let locator ;
777781 try {
778782 locator = await this . chain . getLocator ( ) ;
@@ -2156,7 +2160,7 @@ class Pool extends EventEmitter {
21562160 assert ( stopHash . equals ( this . getcfheadersStopHash ) ) ;
21572161 let previousFilterHeader = packet . previousFilterHeader ;
21582162 const filterHashes = packet . filterHashes ;
2159- assert ( filterHashes . length <= 2000 )
2163+ assert ( filterHashes . length <= 2000 ) ;
21602164 let blockHeight = await this . chain . getHeight ( stopHash )
21612165 - filterHashes . length ;
21622166 const stopHeight = await this . chain . getHeight ( stopHash ) ;
@@ -2165,14 +2169,26 @@ class Pool extends EventEmitter {
21652169 const basicFilter = new BasicFilter ( ) ;
21662170 basicFilter . _hash = filterHash ;
21672171 const filterHeader = basicFilter . header ( previousFilterHeader ) ;
2172+ const lastFilterHeader = this . cfHeaderChain . tail ;
2173+ const cfHeaderEntry = new CFHeaderEntry (
2174+ filterHash , lastFilterHeader . height + 1 ) ;
2175+ this . cfHeaderChain . push ( cfHeaderEntry ) ;
21682176 // todo: verify the filterHeader
21692177 // todo: save the filterHeader
21702178 previousFilterHeader = filterHeader ;
21712179 this . chain . db . neutrinoState . headerHeight = blockHeight ;
21722180 blockHeight ++ ;
21732181 }
21742182 await this . chain . db . saveNeutrinoState ( ) ;
2175- this . emit ( 'cfheaders' ) ;
2183+ if ( this . headerChain . tail . height <= stopHeight )
2184+ this . emit ( 'cfheaders' ) ;
2185+ else {
2186+ const nextStopHeight = stopHeight + 2000 < this . chain . height
2187+ ? stopHeight + 2000 : this . chain . height ;
2188+ const nextStopHash = await this . chain . getHash ( nextStopHeight ) ;
2189+ this . getcfheadersStopHash = nextStopHash ;
2190+ peer . sendGetCFHeaders ( filterType , stopHeight + 1 , nextStopHash ) ;
2191+ }
21762192 }
21772193
21782194 async handleCFilters ( peer , packet ) {
@@ -2191,7 +2207,8 @@ class Pool extends EventEmitter {
21912207 assert ( filterType === this . getcfheadersFilterType ) ;
21922208 const blockHeight = await this . chain . getHeight ( blockHash ) ;
21932209 const stopHeight = await this . chain . getHeight ( this . getcfiltersStopHash ) ;
2194- assert ( blockHeight >= this . getcfiltersStartHeight && blockHeight <= stopHeight ) ;
2210+ assert ( blockHeight >= this . getcfiltersStartHeight
2211+ && blockHeight <= stopHeight ) ;
21952212
21962213 // todo: save the filter
21972214 const basicFilter = new BasicFilter ( ) ;
@@ -2357,7 +2374,6 @@ class Pool extends EventEmitter {
23572374 const last = this . headerChain . tail ;
23582375 const hash = header . hash ( ) ;
23592376 const height = last . height + 1 ;
2360- console . log ( 'header' ) ;
23612377
23622378 if ( ! header . verify ( ) ) {
23632379 this . logger . warning (
@@ -2415,6 +2431,8 @@ class Pool extends EventEmitter {
24152431 }
24162432
24172433 // Request more headers.
2434+ if ( this . chain . synced )
2435+ return ;
24182436 if ( this . options . neutrino )
24192437 peer . sendGetHeaders ( [ node . hash ] ) ;
24202438 else
@@ -4724,6 +4742,20 @@ class HeaderEntry {
47244742 }
47254743}
47264744
4745+ class CFHeaderEntry {
4746+ /**
4747+ * Create cfheader entry.
4748+ * @constructor
4749+ */
4750+
4751+ constructor ( hash , height ) {
4752+ this . hash = hash ;
4753+ this . height = height ;
4754+ this . prev = null ;
4755+ this . next = null ;
4756+ }
4757+ }
4758+
47274759/*
47284760 * Expose
47294761 */
0 commit comments