@ -86,7 +86,8 @@ type handlerConfig struct {
BloomCache uint64 // Megabytes to alloc for snap sync bloom
EventMux * event . TypeMux // Legacy event mux, deprecate for `feed`
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 {
@ -115,7 +116,7 @@ type handler struct {
txsSub event . Subscription
minedBlockSub * event . TypeMuxSubscription
whitelist map [ uint64 ] common . Hash
peerRequiredBlocks map [ uint64 ] common . Hash
// channels for fetcher, syncer, txsyncLoop
quitSync chan struct { }
@ -140,7 +141,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
chain : config . Chain ,
peers : newPeerSet ( ) ,
merger : config . Merger ,
whitelist : config . Whitelist ,
peerRequiredBlocks : config . PeerRequiredBlocks ,
quitSync : make ( chan struct { } ) ,
}
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
for number , hash := range h . whitelist {
// If we have any explicit peer required block hashes, request them
for number := range h . peerRequiredBlocks {
resCh := make ( chan * eth . Response )
if _ , err := peer . RequestHeadersByNumber ( number , 1 , 0 , false , resCh ) ; err != nil {
return err
@ -437,25 +438,25 @@ func (h *handler) runEthPeer(peer *eth.Peer, handler eth.Handler) error {
case res := <- resCh :
headers := ( [ ] * types . Header ) ( * res . Res . ( * eth . BlockHeadersPacket ) )
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
res . Done <- nil
return
}
// Validate the header and either drop the peer or continue
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
}
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 )
res . Done <- errors . New ( "whitelist block mismatch" )
peer . Log ( ) . Info ( "Required block mismatch, dropping peer" , "number" , number , "hash" , headers [ 0 ] . Hash ( ) , "want" , hash )
res . Done <- errors . New ( "required block mismatch" )
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
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 ( ) )
}
} ( number , hash )