@@ -66,29 +66,24 @@ export class LightBlockCache {
66
66
67
67
private async cacheBlocksInner ( ) : Promise < void > {
68
68
const rpc = await ifClient . getClient ( ) ;
69
- // eslint-disable-next-line no-constant-condition
70
- while ( true ) {
71
- const head = await this . getHead ( ) ;
72
- const followChainStreamParams = head
73
- ? { head : head . toString ( "hex" ) }
74
- : { } ;
75
- const stream = await rpc . chain . followChainStream ( {
76
- ...followChainStreamParams ,
77
- serialized : true ,
78
- limit : 100 ,
79
- } ) ;
80
-
81
- for await ( const content of stream . contentStream ( ) ) {
82
- if ( content . type === "connected" ) {
83
- const block = lightBlock ( content ) ;
84
- this . cacheBlock ( block ) ;
85
- } else if ( content . type === "disconnected" ) {
86
- logger . warn ( `Removing block ${ content . block . sequence } ...` ) ;
87
- const block = lightBlock ( content ) ;
88
- await this . putHead ( block . previousBlockHash , block . sequence - 1 ) ;
89
- await this . del ( block . sequence . toString ( ) ) ;
90
- await this . del ( block . hash . toString ( "hex" ) ) ;
91
- }
69
+ const head = await this . getHead ( ) ;
70
+ const followChainStreamParams = head ? { head : head . toString ( "hex" ) } : { } ;
71
+ const stream = await rpc . chain . followChainStream ( {
72
+ ...followChainStreamParams ,
73
+ serialized : true ,
74
+ limit : 100 ,
75
+ } ) ;
76
+
77
+ for await ( const content of stream . contentStream ( ) ) {
78
+ if ( content . type === "connected" ) {
79
+ const block = lightBlock ( content ) ;
80
+ this . cacheBlock ( block ) ;
81
+ } else if ( content . type === "disconnected" ) {
82
+ logger . warn ( `Removing block ${ content . block . sequence } ...` ) ;
83
+ const block = lightBlock ( content ) ;
84
+ await this . putHead ( block . previousBlockHash , block . sequence - 1 ) ;
85
+ await this . del ( block . sequence . toString ( ) ) ;
86
+ await this . del ( block . hash . toString ( "hex" ) ) ;
92
87
}
93
88
}
94
89
}
0 commit comments