|
|
@ -173,8 +173,8 @@ type LightChain interface { |
|
|
|
type BlockChain interface { |
|
|
|
type BlockChain interface { |
|
|
|
LightChain |
|
|
|
LightChain |
|
|
|
|
|
|
|
|
|
|
|
// HasBlockAndState verifies block and associated states' presence in the local chain.
|
|
|
|
// HasBlock verifies a block's presence in the local chain.
|
|
|
|
HasBlockAndState(common.Hash, uint64) bool |
|
|
|
HasBlock(common.Hash, uint64) bool |
|
|
|
|
|
|
|
|
|
|
|
// GetBlockByHash retrieves a block from the local chain.
|
|
|
|
// GetBlockByHash retrieves a block from the local chain.
|
|
|
|
GetBlockByHash(common.Hash) *types.Block |
|
|
|
GetBlockByHash(common.Hash) *types.Block |
|
|
@ -582,7 +582,6 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err |
|
|
|
// Figure out the valid ancestor range to prevent rewrite attacks
|
|
|
|
// Figure out the valid ancestor range to prevent rewrite attacks
|
|
|
|
floor, ceil := int64(-1), d.lightchain.CurrentHeader().Number.Uint64() |
|
|
|
floor, ceil := int64(-1), d.lightchain.CurrentHeader().Number.Uint64() |
|
|
|
|
|
|
|
|
|
|
|
p.log.Debug("Looking for common ancestor", "local", ceil, "remote", height) |
|
|
|
|
|
|
|
if d.mode == FullSync { |
|
|
|
if d.mode == FullSync { |
|
|
|
ceil = d.blockchain.CurrentBlock().NumberU64() |
|
|
|
ceil = d.blockchain.CurrentBlock().NumberU64() |
|
|
|
} else if d.mode == FastSync { |
|
|
|
} else if d.mode == FastSync { |
|
|
@ -591,6 +590,8 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err |
|
|
|
if ceil >= MaxForkAncestry { |
|
|
|
if ceil >= MaxForkAncestry { |
|
|
|
floor = int64(ceil - MaxForkAncestry) |
|
|
|
floor = int64(ceil - MaxForkAncestry) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
p.log.Debug("Looking for common ancestor", "local", ceil, "remote", height) |
|
|
|
|
|
|
|
|
|
|
|
// Request the topmost blocks to short circuit binary ancestor lookup
|
|
|
|
// Request the topmost blocks to short circuit binary ancestor lookup
|
|
|
|
head := ceil |
|
|
|
head := ceil |
|
|
|
if head > height { |
|
|
|
if head > height { |
|
|
@ -646,7 +647,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
// Otherwise check if we already know the header or not
|
|
|
|
// Otherwise check if we already know the header or not
|
|
|
|
if (d.mode == FullSync && d.blockchain.HasBlockAndState(headers[i].Hash(), headers[i].Number.Uint64())) || (d.mode != FullSync && d.lightchain.HasHeader(headers[i].Hash(), headers[i].Number.Uint64())) { |
|
|
|
if (d.mode == FullSync && d.blockchain.HasBlock(headers[i].Hash(), headers[i].Number.Uint64())) || (d.mode != FullSync && d.lightchain.HasHeader(headers[i].Hash(), headers[i].Number.Uint64())) { |
|
|
|
number, hash = headers[i].Number.Uint64(), headers[i].Hash() |
|
|
|
number, hash = headers[i].Number.Uint64(), headers[i].Hash() |
|
|
|
|
|
|
|
|
|
|
|
// If every header is known, even future ones, the peer straight out lied about its head
|
|
|
|
// If every header is known, even future ones, the peer straight out lied about its head
|
|
|
@ -711,7 +712,7 @@ func (d *Downloader) findAncestor(p *peerConnection, height uint64) (uint64, err |
|
|
|
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.blockchain.HasBlockAndState(headers[0].Hash(), headers[0].Number.Uint64())) || (d.mode != FullSync && !d.lightchain.HasHeader(headers[0].Hash(), headers[0].Number.Uint64())) { |
|
|
|
if (d.mode == FullSync && !d.blockchain.HasBlock(headers[0].Hash(), headers[0].Number.Uint64())) || (d.mode != FullSync && !d.lightchain.HasHeader(headers[0].Hash(), headers[0].Number.Uint64())) { |
|
|
|
end = check |
|
|
|
end = check |
|
|
|
break |
|
|
|
break |
|
|
|
} |
|
|
|
} |
|
|
|