@ -86,7 +86,8 @@ type handlerConfig struct {
BloomCache uint64 // Megabytes to alloc for snap sync bloom
BloomCache uint64 // Megabytes to alloc for snap sync bloom
EventMux * event . TypeMux // Legacy event mux, deprecate for `feed`
EventMux * event . TypeMux // Legacy event mux, deprecate for `feed`
Checkpoint * params . TrustedCheckpoint // Hard coded checkpoint for sync challenges
Checkpoint * params . TrustedCheckpoint // Hard coded checkpoint for sync challenges
Whitelist map [ uint64 ] common . Hash // Hard coded whitelist for sync challenged
PeerRequiredBlocks map [ uint64 ] common . Hash // Hard coded map of required block hashes for sync challenges
}
}
type handler struct {
type handler struct {
@ -115,7 +116,7 @@ type handler struct {
txsSub event . Subscription
txsSub event . Subscription
minedBlockSub * event . TypeMuxSubscription
minedBlockSub * event . TypeMuxSubscription
whitelist map [ uint64 ] common . Hash
peerRequiredBlocks map [ uint64 ] common . Hash
// channels for fetcher, syncer, txsyncLoop
// channels for fetcher, syncer, txsyncLoop
quitSync chan struct { }
quitSync chan struct { }
@ -140,7 +141,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
chain : config . Chain ,
chain : config . Chain ,
peers : newPeerSet ( ) ,
peers : newPeerSet ( ) ,
merger : config . Merger ,
merger : config . Merger ,
whitelist : config . Whitelist ,
peerRequiredBlocks : config . PeerRequiredBlocks ,
quitSync : make ( chan struct { } ) ,
quitSync : make ( chan struct { } ) ,
}
}
if config . Sync == downloader . FullSync {
if config . Sync == downloader . FullSync {
@ -423,8 +424,8 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
}
}
} ( )
} ( )
}
}
// If we have any explicit whitelist block hashes, request them
// If we have any explicit peer required block hashes, request them
for number , hash := range h . whitelist {
for number := range h . peerRequiredBlocks {
resCh := make ( chan * eth . Response )
resCh := make ( chan * eth . Response )
if _ , err := peer . RequestHeadersByNumber ( number , 1 , 0 , false , resCh ) ; err != nil {
if _ , err := peer . RequestHeadersByNumber ( number , 1 , 0 , false , resCh ) ; err != nil {
return err
return err
@ -437,25 +438,25 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
case res := <- resCh :
case res := <- resCh :
headers := ( [ ] * types . Header ) ( * res . Res . ( * eth . BlockHeadersPacket ) )
headers := ( [ ] * types . Header ) ( * res . Res . ( * eth . BlockHeadersPacket ) )
if len ( headers ) == 0 {
if len ( headers ) == 0 {
// Whitelist ed blocks are allowed to be missing if the remote
// Requir ed blocks are allowed to be missing if the remote
// node is not yet synced
// node is not yet synced
res . Done <- nil
res . Done <- nil
return
return
}
}
// Validate the header and either drop the peer or continue
// Validate the header and either drop the peer or continue
if len ( headers ) > 1 {
if len ( headers ) > 1 {
res . Done <- errors . New ( "too many headers in whitelist response" )
res . Done <- errors . New ( "too many headers in required block response" )
return
return
}
}
if headers [ 0 ] . Number . Uint64 ( ) != number || headers [ 0 ] . Hash ( ) != hash {
if headers [ 0 ] . Number . Uint64 ( ) != number || headers [ 0 ] . Hash ( ) != hash {
peer . Log ( ) . Info ( "Whitelist mismatch, dropping peer" , "number" , number , "hash" , headers [ 0 ] . Hash ( ) , "want" , hash )
peer . Log ( ) . Info ( "Required block mismatch, dropping peer" , "number" , number , "hash" , headers [ 0 ] . Hash ( ) , "want" , hash )
res . Done <- errors . New ( "whitelist block mismatch" )
res . Done <- errors . New ( "required block mismatch" )
return
return
}
}
peer . Log ( ) . Debug ( "Whitelist block verified" , "number" , number , "hash" , hash )
peer . Log ( ) . Debug ( "Peer required block verified" , "number" , number , "hash" , hash )
res . Done <- nil
res . Done <- nil
case <- timeout . C :
case <- timeout . C :
peer . Log ( ) . Warn ( "Whitelist challenge timed out, dropping" , "addr" , peer . RemoteAddr ( ) , "type" , peer . Name ( ) )
peer . Log ( ) . Warn ( "Required block challenge timed out, dropping" , "addr" , peer . RemoteAddr ( ) , "type" , peer . Name ( ) )
h . removePeer ( peer . ID ( ) )
h . removePeer ( peer . ID ( ) )
}
}
} ( number , hash )
} ( number , hash )