File tree Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Expand file tree Collapse file tree 3 files changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,10 @@ export class BoundProtocol extends EventEmitter {
167
167
for ( const message of messages ) {
168
168
const name = message . name as string
169
169
const camel = name [ 0 ] . toLowerCase ( ) + name . slice ( 1 )
170
- ; ( this as any ) [ camel ] = async ( args : any [ ] ) => this . request ( name , args )
170
+ ; ( this as any ) [ camel ] = async ( args : any [ ] ) =>
171
+ this . request ( name , args ) . catch ( ( error : Error ) => {
172
+ this . emit ( 'error' , error )
173
+ } )
171
174
}
172
175
}
173
176
}
Original file line number Diff line number Diff line change @@ -73,11 +73,11 @@ export class FullSynchronizer extends Synchronizer {
73
73
* @return {Promise } Resolves with header
74
74
*/
75
75
async latest ( peer : Peer ) {
76
- const headers = await peer . eth ! . getBlockHeaders ( {
76
+ const headers = await peer . eth ? .getBlockHeaders ( {
77
77
block : peer . eth ! . status . bestHash ,
78
78
max : 1 ,
79
79
} )
80
- return headers [ 0 ]
80
+ return headers ?. [ 0 ]
81
81
}
82
82
83
83
/**
@@ -88,8 +88,9 @@ export class FullSynchronizer extends Synchronizer {
88
88
async syncWithPeer ( peer ?: Peer ) : Promise < boolean > {
89
89
if ( ! peer ) return false
90
90
const latest = await this . latest ( peer )
91
+ if ( ! latest ) return false
91
92
const height = new BN ( latest . number )
92
- const first = ( ( this . chain . blocks as any ) . height as BN ) . addn ( 1 )
93
+ const first = this . chain . blocks . height . addn ( 1 )
93
94
const count = height . sub ( first ) . addn ( 1 )
94
95
if ( count . lten ( 0 ) ) return false
95
96
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ tape('[FullSynchronizer]', async (t) => {
76
76
const headers = [ { number : 5 } ]
77
77
td . when ( peer . eth . getBlockHeaders ( { block : 'hash' , max : 1 } ) ) . thenResolve ( headers )
78
78
const latest = await sync . latest ( peer as any )
79
- t . equals ( new BN ( latest . number ) . toNumber ( ) , 5 , 'got height' )
79
+ t . equals ( new BN ( latest ! . number ) . toNumber ( ) , 5 , 'got height' )
80
80
t . end ( )
81
81
} )
82
82
You can’t perform that action at this time.
0 commit comments