Erigon22 - small fixes to reconstitution (#5076)

* Fix db issues

* Fix

* another fix

* Another fix

Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
This commit is contained in:
ledgerwatch 2022-08-16 11:50:04 +01:00 committed by GitHub
parent 8083aaa013
commit 2e50dc9543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -992,9 +992,12 @@ func Recon(genesis *core.Genesis, logger log.Logger) error {
return err return err
} }
plainContractCollector.Close() plainContractCollector.Close()
if err = rwTx.Commit(); err != nil {
return err
}
sentryControlServer, err := sentry.NewMultiClient( sentryControlServer, err := sentry.NewMultiClient(
db, chainDb,
"", "",
chainConfig, chainConfig,
common.Hash{}, common.Hash{},
@ -1013,32 +1016,20 @@ func Recon(genesis *core.Genesis, logger log.Logger) error {
cfg.DeprecatedTxPool.Disable = true cfg.DeprecatedTxPool.Disable = true
cfg.Dirs = datadir2.New(datadir) cfg.Dirs = datadir2.New(datadir)
cfg.Snapshot = allSnapshots.Cfg() cfg.Snapshot = allSnapshots.Cfg()
stagedSync, err := stages2.NewStagedSync(context.Background(), logger, db, p2p.Config{}, &cfg, sentryControlServer, &stagedsync.Notifications{}, nil, allSnapshots, nil, false /* exec22 */, nil) stagedSync, err := stages2.NewStagedSync(context.Background(), logger, chainDb, p2p.Config{}, &cfg, sentryControlServer, &stagedsync.Notifications{}, nil, allSnapshots, nil, false /* exec22 */, nil)
if err != nil { if err != nil {
return err return err
} }
if err != nil {
return err
}
defer func() {
if rwTx != nil {
rwTx.Rollback()
}
}()
execStage, err := stagedSync.StageState(stages.Execution, rwTx, db)
if err != nil {
return err
}
if err = execStage.Update(rwTx, blockNum-1); err != nil {
return err
}
if err = rwTx.Commit(); err != nil {
return err
}
if rwTx, err = chainDb.BeginRw(ctx); err != nil { if rwTx, err = chainDb.BeginRw(ctx); err != nil {
return err return err
} }
execStage, err := stagedSync.StageState(stages.Execution, rwTx, chainDb)
if err != nil {
return err
}
if err = execStage.Update(rwTx, block); err != nil {
return err
}
log.Info("Reconstitution complete", "duration", time.Since(startTime)) log.Info("Reconstitution complete", "duration", time.Since(startTime))
log.Info("Computing hashed state") log.Info("Computing hashed state")
tmpDir := filepath.Join(datadir, "tmp") tmpDir := filepath.Join(datadir, "tmp")
@ -1051,17 +1042,31 @@ func Recon(genesis *core.Genesis, logger log.Logger) error {
if err = rwTx.ClearBucket(kv.ContractCode); err != nil { if err = rwTx.ClearBucket(kv.ContractCode); err != nil {
return err return err
} }
if err = stagedsync.PromoteHashedStateCleanly("recon", rwTx, stagedsync.StageHashStateCfg(db, tmpDir), ctx); err != nil { if err = stagedsync.PromoteHashedStateCleanly("recon", rwTx, stagedsync.StageHashStateCfg(chainDb, tmpDir), ctx); err != nil {
return err
}
hashStage, err := stagedSync.StageState(stages.HashState, rwTx, chainDb)
if err != nil {
return err
}
if err = hashStage.Update(rwTx, block); err != nil {
return err return err
} }
if err = rwTx.Commit(); err != nil { if err = rwTx.Commit(); err != nil {
return err return err
} }
if rwTx, err = db.BeginRw(ctx); err != nil { if rwTx, err = chainDb.BeginRw(ctx); err != nil {
return err return err
} }
var rootHash common.Hash var rootHash common.Hash
if rootHash, err = stagedsync.RegenerateIntermediateHashes("recon", rwTx, stagedsync.StageTrieCfg(db, false /* checkRoot */, false /* saveHashesToDB */, false /* badBlockHalt */, tmpDir, blockReader, nil /* HeaderDownload */), common.Hash{}, make(chan struct{}, 1)); err != nil { if rootHash, err = stagedsync.RegenerateIntermediateHashes("recon", rwTx, stagedsync.StageTrieCfg(chainDb, false /* checkRoot */, true /* saveHashesToDB */, false /* badBlockHalt */, tmpDir, blockReader, nil /* HeaderDownload */), common.Hash{}, make(chan struct{}, 1)); err != nil {
return err
}
trieStage, err := stagedSync.StageState(stages.IntermediateHashes, rwTx, chainDb)
if err != nil {
return err
}
if err = trieStage.Update(rwTx, block); err != nil {
return err return err
} }
if err = rwTx.Commit(); err != nil { if err = rwTx.Commit(); err != nil {