|
|
@ -113,7 +113,7 @@ type Downloader struct { |
|
|
|
|
|
|
|
|
|
|
|
// Callbacks
|
|
|
|
// Callbacks
|
|
|
|
hasHeader headerCheckFn // Checks if a header is present in the chain
|
|
|
|
hasHeader headerCheckFn // Checks if a header is present in the chain
|
|
|
|
hasBlock blockCheckFn // Checks if a block is present in the chain
|
|
|
|
hasBlockAndState blockAndStateCheckFn // Checks if a block and associated state is present in the chain
|
|
|
|
getHeader headerRetrievalFn // Retrieves a header from the chain
|
|
|
|
getHeader headerRetrievalFn // Retrieves a header from the chain
|
|
|
|
getBlock blockRetrievalFn // Retrieves a block from the chain
|
|
|
|
getBlock blockRetrievalFn // Retrieves a block from the chain
|
|
|
|
headHeader headHeaderRetrievalFn // Retrieves the head header from the chain
|
|
|
|
headHeader headHeaderRetrievalFn // Retrieves the head header from the chain
|
|
|
@ -156,10 +156,10 @@ type Downloader struct { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// New creates a new downloader to fetch hashes and blocks from remote peers.
|
|
|
|
// New creates a new downloader to fetch hashes and blocks from remote peers.
|
|
|
|
func New(stateDb ethdb.Database, mux *event.TypeMux, hasHeader headerCheckFn, hasBlock blockCheckFn, getHeader headerRetrievalFn, |
|
|
|
func New(stateDb ethdb.Database, mux *event.TypeMux, hasHeader headerCheckFn, hasBlockAndState blockAndStateCheckFn, |
|
|
|
getBlock blockRetrievalFn, headHeader headHeaderRetrievalFn, headBlock headBlockRetrievalFn, headFastBlock headFastBlockRetrievalFn, |
|
|
|
getHeader headerRetrievalFn, getBlock blockRetrievalFn, headHeader headHeaderRetrievalFn, headBlock headBlockRetrievalFn, |
|
|
|
commitHeadBlock headBlockCommitterFn, getTd tdRetrievalFn, insertHeaders headerChainInsertFn, insertBlocks blockChainInsertFn, |
|
|
|
headFastBlock headFastBlockRetrievalFn, commitHeadBlock headBlockCommitterFn, getTd tdRetrievalFn, insertHeaders headerChainInsertFn, |
|
|
|
insertReceipts receiptChainInsertFn, rollback chainRollbackFn, dropPeer peerDropFn) *Downloader { |
|
|
|
insertBlocks blockChainInsertFn, insertReceipts receiptChainInsertFn, rollback chainRollbackFn, dropPeer peerDropFn) *Downloader { |
|
|
|
|
|
|
|
|
|
|
|
return &Downloader{ |
|
|
|
return &Downloader{ |
|
|
|
mode: FullSync, |
|
|
|
mode: FullSync, |
|
|
@ -167,7 +167,7 @@ func New(stateDb ethdb.Database, mux *event.TypeMux, hasHeader headerCheckFn, ha |
|
|
|
queue: newQueue(stateDb), |
|
|
|
queue: newQueue(stateDb), |
|
|
|
peers: newPeerSet(), |
|
|
|
peers: newPeerSet(), |
|
|
|
hasHeader: hasHeader, |
|
|
|
hasHeader: hasHeader, |
|
|
|
hasBlock: hasBlock, |
|
|
|
hasBlockAndState: hasBlockAndState, |
|
|
|
getHeader: getHeader, |
|
|
|
getHeader: getHeader, |
|
|
|
getBlock: getBlock, |
|
|
|
getBlock: getBlock, |
|
|
|
headHeader: headHeader, |
|
|
|
headHeader: headHeader, |
|
|
@ -564,7 +564,7 @@ func (d *Downloader) findAncestor61(p *peer) (uint64, error) { |
|
|
|
// Check if a common ancestor was found
|
|
|
|
// Check if a common ancestor was found
|
|
|
|
finished = true |
|
|
|
finished = true |
|
|
|
for i := len(hashes) - 1; i >= 0; i-- { |
|
|
|
for i := len(hashes) - 1; i >= 0; i-- { |
|
|
|
if d.hasBlock(hashes[i]) { |
|
|
|
if d.hasBlockAndState(hashes[i]) { |
|
|
|
number, hash = uint64(from)+uint64(i), hashes[i] |
|
|
|
number, hash = uint64(from)+uint64(i), hashes[i] |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
@ -620,11 +620,11 @@ func (d *Downloader) findAncestor61(p *peer) (uint64, error) { |
|
|
|
arrived = true |
|
|
|
arrived = true |
|
|
|
|
|
|
|
|
|
|
|
// Modify the search interval based on the response
|
|
|
|
// Modify the search interval based on the response
|
|
|
|
block := d.getBlock(hashes[0]) |
|
|
|
if !d.hasBlockAndState(hashes[0]) { |
|
|
|
if block == nil { |
|
|
|
|
|
|
|
end = check |
|
|
|
end = check |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
block := d.getBlock(hashes[0]) // this doesn't check state, hence the above explicit check
|
|
|
|
if block.NumberU64() != check { |
|
|
|
if block.NumberU64() != check { |
|
|
|
glog.V(logger.Debug).Infof("%v: non requested hash #%d [%x…], instead of #%d", p, block.NumberU64(), block.Hash().Bytes()[:4], check) |
|
|
|
glog.V(logger.Debug).Infof("%v: non requested hash #%d [%x…], instead of #%d", p, block.NumberU64(), block.Hash().Bytes()[:4], check) |
|
|
|
return 0, errBadPeer |
|
|
|
return 0, errBadPeer |
|
|
@ -989,7 +989,7 @@ func (d *Downloader) findAncestor(p *peer) (uint64, error) { |
|
|
|
// Check if a common ancestor was found
|
|
|
|
// Check if a common ancestor was found
|
|
|
|
finished = true |
|
|
|
finished = true |
|
|
|
for i := len(headers) - 1; i >= 0; i-- { |
|
|
|
for i := len(headers) - 1; i >= 0; i-- { |
|
|
|
if (d.mode != LightSync && d.hasBlock(headers[i].Hash())) || (d.mode == LightSync && d.hasHeader(headers[i].Hash())) { |
|
|
|
if (d.mode != LightSync && d.hasBlockAndState(headers[i].Hash())) || (d.mode == LightSync && d.hasHeader(headers[i].Hash())) { |
|
|
|
number, hash = headers[i].Number.Uint64(), headers[i].Hash() |
|
|
|
number, hash = headers[i].Number.Uint64(), headers[i].Hash() |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
@ -1045,7 +1045,7 @@ func (d *Downloader) findAncestor(p *peer) (uint64, error) { |
|
|
|
arrived = true |
|
|
|
arrived = true |
|
|
|
|
|
|
|
|
|
|
|
// Modify the search interval based on the response
|
|
|
|
// Modify the search interval based on the response
|
|
|
|
if (d.mode == FullSync && !d.hasBlock(headers[0].Hash())) || (d.mode != FullSync && !d.hasHeader(headers[0].Hash())) { |
|
|
|
if (d.mode == FullSync && !d.hasBlockAndState(headers[0].Hash())) || (d.mode != FullSync && !d.hasHeader(headers[0].Hash())) { |
|
|
|
end = check |
|
|
|
end = check |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|