-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix externalcl integration for erigon3 #12906
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,7 +222,6 @@ func (e *EngineBlockDownloader) loadDownloadedHeaders(tx kv.RwTx) (fromBlock uin | |
func saveHeader(db kv.RwTx, header *types.Header, hash libcommon.Hash) error { | ||
blockHeight := header.Number.Uint64() | ||
// TODO(yperbasis): do we need to check if the header is already inserted (oldH)? | ||
|
||
parentTd, err := rawdb.ReadTd(db, header.ParentHash, blockHeight-1) | ||
if err != nil || parentTd == nil { | ||
return fmt.Errorf("[saveHeader] parent's total difficulty not found with hash %x and height %d for header %x %d: %v", header.ParentHash, blockHeight-1, hash, blockHeight, err) | ||
|
@@ -235,7 +234,7 @@ func saveHeader(db kv.RwTx, header *types.Header, hash libcommon.Hash) error { | |
return fmt.Errorf("[saveHeader] failed to WriteTd: %w", err) | ||
} | ||
if err = rawdb.WriteCanonicalHash(db, hash, blockHeight); err != nil { | ||
return fmt.Errorf("[saveHeader] failed to canonical hash: %w", err) | ||
return fmt.Errorf("[saveHeader] failed to save canonical hash: %w", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo fix |
||
} | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ import ( | |
execution "github.com/erigontech/erigon-lib/gointerfaces/executionproto" | ||
"github.com/erigontech/erigon-lib/kv/mdbx" | ||
"github.com/erigontech/erigon-lib/kv/membatchwithdb" | ||
"github.com/erigontech/erigon/core/rawdb" | ||
"github.com/erigontech/erigon/core/types" | ||
"github.com/erigontech/erigon/turbo/stages/headerdownload" | ||
) | ||
|
@@ -79,9 +80,17 @@ func (e *EngineBlockDownloader) download(ctx context.Context, hashToDownload lib | |
memoryMutation := membatchwithdb.NewMemoryBatchWithCustomDB(tx, tmpDb, tmpTx) | ||
defer memoryMutation.Rollback() | ||
|
||
if block != nil { | ||
err = rawdb.WriteCanonicalHash(memoryMutation, block.Hash(), block.NumberU64()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. downloading of headers backwards starts with the parent of the |
||
if err != nil { | ||
e.logger.Warn("[EngineBlockDownloader] Could not make leading header canonical", "err", err) | ||
e.status.Store(headerdownload.Idle) | ||
return | ||
} | ||
} | ||
startBlock, endBlock, startHash, err := e.loadDownloadedHeaders(memoryMutation) | ||
if err != nil { | ||
e.logger.Warn("[EngineBlockDownloader] Could load headers", "err", err) | ||
e.logger.Warn("[EngineBlockDownloader] Could not load headers", "err", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo fix |
||
e.status.Store(headerdownload.Idle) | ||
return | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ package bodydownload | |
import ( | ||
"bytes" | ||
"context" | ||
"errors" | ||
"fmt" | ||
"math/big" | ||
|
||
|
@@ -33,19 +32,18 @@ import ( | |
"github.com/erigontech/erigon/eth/stagedsync/stages" | ||
"github.com/erigontech/erigon/turbo/adapter" | ||
"github.com/erigontech/erigon/turbo/services" | ||
"github.com/holiman/uint256" | ||
) | ||
|
||
// UpdateFromDb reads the state of the database and refreshes the state of the body download | ||
func (bd *BodyDownload) UpdateFromDb(db kv.Tx) (headHeight, headTime uint64, headHash libcommon.Hash, headTd256 *uint256.Int, err error) { | ||
func (bd *BodyDownload) UpdateFromDb(db kv.Tx) (err error) { | ||
var headerProgress, bodyProgress uint64 | ||
headerProgress, err = stages.GetStageProgress(db, stages.Headers) | ||
if err != nil { | ||
return 0, 0, libcommon.Hash{}, nil, err | ||
return err | ||
} | ||
bodyProgress, err = stages.GetStageProgress(db, stages.Bodies) | ||
if err != nil { | ||
return 0, 0, libcommon.Hash{}, nil, err | ||
return err | ||
} | ||
bd.maxProgress = headerProgress + 1 | ||
// Resetting for requesting a new range of blocks | ||
|
@@ -58,37 +56,7 @@ func (bd *BodyDownload) UpdateFromDb(db kv.Tx) (headHeight, headTime uint64, hea | |
clear(bd.requests) | ||
clear(bd.peerMap) | ||
bd.ClearBodyCache() | ||
headHeight = bodyProgress | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following code was removed since it computes values that are never used. Also this code was actually producing error messages |
||
var ok bool | ||
headHash, ok, err = bd.br.CanonicalHash(context.Background(), db, headHeight) | ||
if err != nil { | ||
return 0, 0, libcommon.Hash{}, nil, err | ||
} | ||
if !ok { | ||
return 0, 0, libcommon.Hash{}, nil, fmt.Errorf("canonical marker not found: %d", headHeight) | ||
} | ||
var headTd *big.Int | ||
headTd, err = rawdb.ReadTd(db, headHash, headHeight) | ||
if err != nil { | ||
return 0, 0, libcommon.Hash{}, nil, fmt.Errorf("reading total difficulty for head height %d and hash %x: %d, %w", headHeight, headHash, headTd, err) | ||
} | ||
if headTd == nil { | ||
headTd = new(big.Int) | ||
} | ||
headTd256 = new(uint256.Int) | ||
overflow := headTd256.SetFromBig(headTd) | ||
if overflow { | ||
return 0, 0, libcommon.Hash{}, nil, errors.New("headTd higher than 2^256-1") | ||
} | ||
headTime = 0 | ||
headHeader, err := bd.br.Header(context.Background(), db, headHash, headHeight) | ||
if err != nil { | ||
return 0, 0, libcommon.Hash{}, nil, fmt.Errorf("reading header for head height %d and hash %x: %d, %w", headHeight, headHash, headTd, err) | ||
} | ||
if headHeader != nil { | ||
headTime = headHeader.Time | ||
} | ||
return headHeight, headTime, headHash, headTd256, nil | ||
return nil | ||
} | ||
|
||
// RequestMoreBodies - returns nil if nothing to request | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes we get
MDBX_MAP_FULL
error if there are lots of blocks to hold temporarily, this is to fix it