eth/downloader: dynamically move pivot even during chain sync

This commit is contained in:
Péter Szilágyi
2020-09-08 11:13:16 +03:00
parent faba018b29
commit fb835c024c
3 changed files with 192 additions and 72 deletions

View File

@ -427,11 +427,7 @@ func (dlp *downloadTesterPeer) Head() (common.Hash, *big.Int) {
// origin; associated with a particular peer in the download tester. The returned
// function can be used to retrieve batches of headers from the particular peer.
func (dlp *downloadTesterPeer) RequestHeadersByHash(origin common.Hash, amount int, skip int, reverse bool) error {
if reverse {
panic("reverse header requests not supported")
}
result := dlp.chain.headersByHash(origin, amount, skip)
result := dlp.chain.headersByHash(origin, amount, skip, reverse)
go dlp.dl.downloader.DeliverHeaders(dlp.id, result)
return nil
}
@ -440,11 +436,7 @@ func (dlp *downloadTesterPeer) RequestHeadersByHash(origin common.Hash, amount i
// origin; associated with a particular peer in the download tester. The returned
// function can be used to retrieve batches of headers from the particular peer.
func (dlp *downloadTesterPeer) RequestHeadersByNumber(origin uint64, amount int, skip int, reverse bool) error {
if reverse {
panic("reverse header requests not supported")
}
result := dlp.chain.headersByNumber(origin, amount, skip)
result := dlp.chain.headersByNumber(origin, amount, skip, reverse)
go dlp.dl.downloader.DeliverHeaders(dlp.id, result)
return nil
}
@ -1698,7 +1690,7 @@ func testCheckpointEnforcement(t *testing.T, protocol int, mode SyncMode) {
if mode == FastSync || mode == LightSync {
expect = errUnsyncedPeer
}
if err := tester.sync("peer", nil, mode); err != expect {
if err := tester.sync("peer", nil, mode); !errors.Is(err, expect) {
t.Fatalf("block sync error mismatch: have %v, want %v", err, expect)
}
if mode == FastSync || mode == LightSync {