mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd: polish exportPreimage command
This commit is contained in:
parent
272a0cc6fa
commit
b541aa529d
2 changed files with 20 additions and 18 deletions
|
|
@ -645,7 +645,6 @@ func snapshotExportPreimages(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
root = headBlock.Root()
|
root = headBlock.Root()
|
||||||
}
|
}
|
||||||
|
|
||||||
snapConfig := snapshot.Config{
|
snapConfig := snapshot.Config{
|
||||||
CacheSize: 256,
|
CacheSize: 256,
|
||||||
Recovery: false,
|
Recovery: false,
|
||||||
|
|
@ -656,13 +655,7 @@ func snapshotExportPreimages(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return utils.ExportSnapshotPreimages(chaindb, snaptree, ctx.Args().First(), root)
|
||||||
start := time.Now()
|
|
||||||
if err := utils.ExportSnapshotPreimages(chaindb, snaptree, ctx.Args().First(), root); err != nil {
|
|
||||||
utils.Fatalf("Export error: %v\n", err)
|
|
||||||
}
|
|
||||||
log.Info("Export done", "duration", time.Since(start))
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkAccount iterates the snap data layers, and looks up the given account
|
// checkAccount iterates the snap data layers, and looks up the given account
|
||||||
|
|
|
||||||
|
|
@ -386,14 +386,13 @@ func ExportSnapshotPreimages(chaindb ethdb.Database, snaptree *snapshot.Tree, fn
|
||||||
}
|
}
|
||||||
defer fh.Close()
|
defer fh.Close()
|
||||||
|
|
||||||
|
// Enable gzip compressing if file name has gz suffix.
|
||||||
var writer io.Writer = fh
|
var writer io.Writer = fh
|
||||||
|
|
||||||
if strings.HasSuffix(fn, ".gz") {
|
if strings.HasSuffix(fn, ".gz") {
|
||||||
gz := gzip.NewWriter(writer)
|
gz := gzip.NewWriter(writer)
|
||||||
defer gz.Close()
|
defer gz.Close()
|
||||||
writer = gz
|
writer = gz
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := bufio.NewWriter(writer)
|
buf := bufio.NewWriter(writer)
|
||||||
defer buf.Flush()
|
defer buf.Flush()
|
||||||
writer = buf
|
writer = buf
|
||||||
|
|
@ -404,6 +403,11 @@ func ExportSnapshotPreimages(chaindb ethdb.Database, snaptree *snapshot.Tree, fn
|
||||||
}
|
}
|
||||||
hashCh := make(chan hashAndPreimageSize)
|
hashCh := make(chan hashAndPreimageSize)
|
||||||
|
|
||||||
|
var (
|
||||||
|
start = time.Now()
|
||||||
|
logged = time.Now()
|
||||||
|
preimages int
|
||||||
|
)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(hashCh)
|
defer close(hashCh)
|
||||||
accIt, err := snaptree.AccountIterator(root, common.Hash{})
|
accIt, err := snaptree.AccountIterator(root, common.Hash{})
|
||||||
|
|
@ -413,14 +417,14 @@ func ExportSnapshotPreimages(chaindb ethdb.Database, snaptree *snapshot.Tree, fn
|
||||||
}
|
}
|
||||||
defer accIt.Release()
|
defer accIt.Release()
|
||||||
|
|
||||||
count := 0
|
|
||||||
for accIt.Next() {
|
for accIt.Next() {
|
||||||
acc, err := types.FullAccount(accIt.Account())
|
acc, err := types.FullAccount(accIt.Account())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to get full account", "error", err)
|
log.Error("Failed to get full account", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hashCh <- hashAndPreimageSize{Hash: accIt.Hash(), Size: 20}
|
preimages += 1
|
||||||
|
hashCh <- hashAndPreimageSize{Hash: accIt.Hash(), Size: common.AddressLength}
|
||||||
|
|
||||||
if acc.Root != (common.Hash{}) && acc.Root != types.EmptyRootHash {
|
if acc.Root != (common.Hash{}) && acc.Root != types.EmptyRootHash {
|
||||||
stIt, err := snaptree.StorageIterator(root, accIt.Hash(), common.Hash{})
|
stIt, err := snaptree.StorageIterator(root, accIt.Hash(), common.Hash{})
|
||||||
|
|
@ -429,13 +433,19 @@ func ExportSnapshotPreimages(chaindb ethdb.Database, snaptree *snapshot.Tree, fn
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for stIt.Next() {
|
for stIt.Next() {
|
||||||
hashCh <- hashAndPreimageSize{Hash: stIt.Hash(), Size: 32}
|
preimages += 1
|
||||||
|
hashCh <- hashAndPreimageSize{Hash: stIt.Hash(), Size: common.HashLength}
|
||||||
|
|
||||||
|
if time.Since(logged) > time.Second*8 {
|
||||||
|
logged = time.Now()
|
||||||
|
log.Info("Exporting preimages", "count", preimages, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stIt.Release()
|
stIt.Release()
|
||||||
}
|
}
|
||||||
count++
|
if time.Since(logged) > time.Second*8 {
|
||||||
if count%100000 == 0 {
|
logged = time.Now()
|
||||||
log.Info("Last exported account", "account", accIt.Hash())
|
log.Info("Exporting preimages", "count", preimages, "elapsed", common.PrettyDuration(time.Since(start)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
@ -452,8 +462,7 @@ func ExportSnapshotPreimages(chaindb ethdb.Database, snaptree *snapshot.Tree, fn
|
||||||
return fmt.Errorf("failed to write preimage: %w", err)
|
return fmt.Errorf("failed to write preimage: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Info("Exported preimages", "count", preimages, "elapsed", common.PrettyDuration(time.Since(start)), "file", fn)
|
||||||
log.Info("Exported preimages", "file", fn)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue