mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-27 10:19:28 +00:00
fix: conflicts on merge
This commit is contained in:
parent
b524bd3eb8
commit
bf0d125449
2 changed files with 16 additions and 9 deletions
|
|
@ -541,7 +541,6 @@ func importHistory(ctx *cli.Context) error {
|
||||||
if err := utils.ImportHistory(chain, db, dir, network, from); err != nil {
|
if err := utils.ImportHistory(chain, db, dir, network, from); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Import done in %v\n", time.Since(start))
|
fmt.Printf("Import done in %v\n", time.Since(start))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,9 +249,9 @@ func readList(filename string) ([]string, error) {
|
||||||
return strings.Split(string(b), "\n"), nil
|
return strings.Split(string(b), "\n"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImportHistory imports Era1 files containing historical block information,
|
// ImportHistory imports Era1/Erae files containing historical block information,
|
||||||
// starting from genesis. The assumption is held that the provided chain
|
// starting from genesis. The assumption is held that the provided chain
|
||||||
// segment in Era1 file should all be canonical and verified.
|
// segment in Era1/Erae file should all be canonical and verified.
|
||||||
func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, network string, from func(f era.ReadAtSeekCloser) (era.Era, error)) error {
|
func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, network string, from func(f era.ReadAtSeekCloser) (era.Era, error)) error {
|
||||||
entries, err := era.ReadDir(dir, network)
|
entries, err := era.ReadDir(dir, network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -280,6 +280,7 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
h = sha256.New()
|
h = sha256.New()
|
||||||
buf = bytes.NewBuffer(nil)
|
buf = bytes.NewBuffer(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, file := range entries {
|
for i, file := range entries {
|
||||||
err := func() error {
|
err := func() error {
|
||||||
path := filepath.Join(dir, file)
|
path := filepath.Join(dir, file)
|
||||||
|
|
@ -290,9 +291,10 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
// Peek at era block range to see if we can skip entirely.
|
// Peek at era block range to check if we can skip entirely.
|
||||||
e, err := from(f)
|
e, err := from(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
f.Close()
|
||||||
return fmt.Errorf("error opening era: %w", err)
|
return fmt.Errorf("error opening era: %w", err)
|
||||||
}
|
}
|
||||||
eraStart := e.Start()
|
eraStart := e.Start()
|
||||||
|
|
@ -305,7 +307,12 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate against checksum file in directory.
|
// reopen for checksum + import.
|
||||||
|
f, err = os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("open %s: %w", path, err)
|
||||||
|
}
|
||||||
|
// Validate checksum.
|
||||||
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
||||||
return fmt.Errorf("seek %s: %w", path, err)
|
return fmt.Errorf("seek %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
@ -319,7 +326,7 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
return fmt.Errorf("%s checksum mismatch: have %s want %s", file, got, checksums[i])
|
return fmt.Errorf("%s checksum mismatch: have %s want %s", file, got, checksums[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import all block data from Era1.
|
// Seek back for import.
|
||||||
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
||||||
return fmt.Errorf("seek %s: %w", path, err)
|
return fmt.Errorf("seek %s: %w", path, err)
|
||||||
}
|
}
|
||||||
|
|
@ -333,6 +340,7 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating iterator: %w", err)
|
return fmt.Errorf("error creating iterator: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blocks = make([]*types.Block, 0, importBatchSize)
|
blocks = make([]*types.Block, 0, importBatchSize)
|
||||||
receiptsList = make([]types.Receipts, 0, importBatchSize)
|
receiptsList = make([]types.Receipts, 0, importBatchSize)
|
||||||
|
|
@ -345,15 +353,14 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
return fmt.Errorf("error inserting blocks %d-%d: %w",
|
return fmt.Errorf("error inserting blocks %d-%d: %w",
|
||||||
blocks[0].NumberU64(), blocks[len(blocks)-1].NumberU64(), err)
|
blocks[0].NumberU64(), blocks[len(blocks)-1].NumberU64(), err)
|
||||||
}
|
}
|
||||||
// Track the last successfully imported block for resume support.
|
// Persist tail after each successful batch.
|
||||||
lastBlock := blocks[len(blocks)-1].NumberU64()
|
lastBlock := blocks[len(blocks)-1].NumberU64()
|
||||||
rawdb.WriteEraImportTail(db, lastBlock)
|
rawdb.WriteEraImportTail(db, lastBlock)
|
||||||
resumeBlock = lastBlock
|
resumeBlock = lastBlock
|
||||||
|
|
||||||
imported += len(blocks)
|
imported += len(blocks)
|
||||||
if time.Since(reported) >= 8*time.Second {
|
if time.Since(reported) >= 8*time.Second {
|
||||||
head := blocks[len(blocks)-1].NumberU64()
|
log.Info("Importing Era files", "head", lastBlock, "imported", imported,
|
||||||
log.Info("Importing Era files", "head", head, "imported", imported,
|
|
||||||
"elapsed", common.PrettyDuration(time.Since(start)))
|
"elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
imported = 0
|
imported = 0
|
||||||
reported = time.Now()
|
reported = time.Now()
|
||||||
|
|
@ -363,6 +370,7 @@ func ImportHistory(chain *core.BlockChain, db ethdb.Database, dir string, networ
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
for it.Next() {
|
for it.Next() {
|
||||||
block, err := it.Block()
|
block, err := it.Block()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue