1
1
import { BN } from 'ethereumjs-util'
2
2
import VM from '@ethereumjs/vm'
3
3
import { Peer } from '../net/peer/peer'
4
- import { BoundProtocol } from '../net/protocol'
5
4
import { short } from '../util'
6
5
import { Synchronizer , SynchronizerOptions } from './sync'
7
6
import { BlockFetcher } from './fetcher'
@@ -43,8 +42,6 @@ export class FullSynchronizer extends Synchronizer {
43
42
* Returns true if peer can be used for syncing
44
43
* @return {boolean }
45
44
*/
46
- // TODO: Correct logic for return type (b/c peer.eth is not boolean)
47
- // "Type 'BoundProtocol | undefined' is not assignable to type 'boolean'"
48
45
syncable ( peer : Peer ) : boolean {
49
46
return peer . eth !== undefined
50
47
}
@@ -58,7 +55,7 @@ export class FullSynchronizer extends Synchronizer {
58
55
const peers = this . pool . peers . filter ( this . syncable . bind ( this ) )
59
56
if ( peers . length < this . config . minPeers && ! this . forceSync ) return
60
57
for ( const peer of peers ) {
61
- if ( peer . eth && peer . eth . status ) {
58
+ if ( peer . eth ? .status ) {
62
59
const td = peer . eth . status . td
63
60
if (
64
61
( ! best && td . gte ( ( this . chain . blocks as any ) . td ) ) ||
@@ -76,12 +73,11 @@ export class FullSynchronizer extends Synchronizer {
76
73
* @return {Promise } Resolves with header
77
74
*/
78
75
async latest ( peer : Peer ) {
79
- // @ts -ignore
80
- const headers = await ( peer . eth as BoundProtocol ) . getBlockHeaders ( {
81
- block : ( peer . eth as BoundProtocol ) . status . bestHash ,
76
+ const headers = await peer . eth ?. getBlockHeaders ( {
77
+ block : peer . eth ! . status . bestHash ,
82
78
max : 1 ,
83
79
} )
84
- return headers [ 0 ]
80
+ return headers ?. [ 0 ]
85
81
}
86
82
87
83
/**
@@ -92,8 +88,9 @@ export class FullSynchronizer extends Synchronizer {
92
88
async syncWithPeer ( peer ?: Peer ) : Promise < boolean > {
93
89
if ( ! peer ) return false
94
90
const latest = await this . latest ( peer )
91
+ if ( ! latest ) return false
95
92
const height = new BN ( latest . number )
96
- const first = ( ( this . chain . blocks as any ) . height as BN ) . addn ( 1 )
93
+ const first = this . chain . blocks . height . addn ( 1 )
97
94
const count = height . sub ( first ) . addn ( 1 )
98
95
if ( count . lten ( 0 ) ) return false
99
96
0 commit comments