Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove blockchain.InsertChain call from downloader #1674

Merged
merged 1 commit into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, blockNumber uin
}
}

func (d *Downloader) importBlockResults(logPrefix string, results []*fetchResult, execute bool) (uint64, error) {
func (d *Downloader) importBlockResults(logPrefix string, results []*fetchResult) (uint64, error) {
// Check for any early termination requests
if len(results) == 0 {
return 0, nil
Expand All @@ -1545,30 +1545,27 @@ func (d *Downloader) importBlockResults(logPrefix string, results []*fetchResult
for i, result := range results {
blocks[i] = types.NewBlockWithHeader(result.Header).WithBody(result.Transactions, result.Uncles)
}
tx, err2 := d.stateDB.Begin(context.Background(), ethdb.RW)
if err2 != nil {
return 0, err2
}
defer tx.Rollback()

var index int
var stopped bool
var err error
if execute {
index, err = d.blockchain.InsertChain(context.Background(), blocks)
stopped, err = core.InsertBodyChain(logPrefix, context.Background(), tx, blocks, true /* newCanonical */)
if stopped {
index = 0
} else {
tx, err2 := d.stateDB.Begin(context.Background(), ethdb.RW)
if err2 != nil {
return 0, err2
}
defer tx.Rollback()
stopped, err = core.InsertBodyChain(logPrefix, context.Background(), tx, blocks, true /* newCanonical */)
if stopped {
index = 0
} else {
index = len(results)
}
if err == nil {
if err1 := tx.Commit(); err1 != nil {
return 0, err1
}
} else {
tx.Rollback()
index = len(results)
}
if err == nil {
if err1 := tx.Commit(); err1 != nil {
return 0, err1
}
} else {
tx.Rollback()
}
if err != nil {
if index < len(results) {
Expand Down
5 changes: 2 additions & 3 deletions eth/downloader/downloader_stagedsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ func (d *Downloader) SpawnBodyDownloadStage(
h := hashes[prefetchedHashes]
if block := prefetchedBlocks.Pop(h); block != nil {
fr := fetchResultFromBlock(block)
execute := false
_, err := d.importBlockResults(logPrefix, []*fetchResult{fr}, execute)
_, err := d.importBlockResults(logPrefix, []*fetchResult{fr})
if err != nil {
return false, err
}
Expand Down Expand Up @@ -160,7 +159,7 @@ func (d *Downloader) processBodiesStage(logPrefix string, to uint64) error {
if len(results) == 0 {
return nil
}
lastNumber, err := d.importBlockResults(logPrefix, results, false /* execute */)
lastNumber, err := d.importBlockResults(logPrefix, results)
if err != nil {
return err
}
Expand Down