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

fix issues-2016 #2089

Closed
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
9 changes: 4 additions & 5 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
height := rawdb.ReadHeaderNumber(chainDb, rawdb.ReadHeadHeaderHash(chainDb))
log.Debug("read header number from chain db", "height", height)
if height != nil && *height > 0 {
//when last fast syncing fail,we will clean chaindb,wal,snapshotdb
//when last fast syncing fail,we will clean chaindb,wal,snapshotdb
status, err := snapshotBaseDB.GetBaseDB([]byte(downloader.KeyFastSyncStatus))

// systemError
Expand All @@ -154,11 +154,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
//if find sync status,this means last syncing not finish,should clean all db to reinit
//if not find sync status,no need init chain
if err == nil {

// Just commit the new block if there is no stored genesis block.
stored := rawdb.ReadCanonicalHash(chainDb, 0)

log.Info("last fast sync is fail,init db", "status", common.BytesToUint32(status), "prichain", config.Genesis == nil)
log.Info("last fast sync is fail,init db", "status", common.BytesToUint32(status), "prichain", config.Genesis == nil)
chainDb.Close()
if err := snapshotBaseDB.Close(); err != nil {
return nil, err
Expand Down Expand Up @@ -192,15 +191,15 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

//only private net need InitGenesisAndSetEconomicConfig
//only private net need InitGenesisAndSetEconomicConfig
if stored != params.MainnetGenesisHash && config.Genesis == nil {
// private net
config.Genesis = new(core.Genesis)
if err := config.Genesis.InitGenesisAndSetEconomicConfig(stack.GenesisPath()); err != nil {
return nil, err
}
}
log.Info("last fast sync is fail,init db finish")
log.Info("last fast sync is fail,init db finish")
} else {
// Just commit the new block if there is no stored genesis block.
stored := rawdb.ReadCanonicalHash(chainDb, 0)
Expand Down
25 changes: 13 additions & 12 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,8 @@ func (d *Downloader) syncWithPeer(p *peerConnection, hash common.Hash, bn *big.I
}
if mode == FastSync {
if err := d.snapshotDB.SetEmpty(); err != nil {
p.log.Error("set snapshotDB empty fail")
return errors.New("set snapshotDB empty fail:" + err.Error())
p.log.Error("set snapshotDB empty fail")
return errors.New("set snapshotDB empty fail:" + err.Error())
}
if err := d.snapshotDB.SetCurrent(pivoth.Hash(), *pivoth.Number, *pivoth.Number); err != nil {
p.log.Error("set snapshotdb current fail", "err", err)
Expand Down Expand Up @@ -742,11 +742,11 @@ func (d *Downloader) fetchPPOSInfo(p *peerConnection) (latest *types.Header, piv
// if the sync is complete,will del the key
func (d *Downloader) setFastSyncStatus(status uint16) error {
key := []byte(KeyFastSyncStatus)
log.Debug("set fast sync status", "status", status)
log.Debug("set fast sync status", "status", status)
switch status {
case FastSyncDel:
if err := d.snapshotDB.DelBaseDB(key); err != nil {
log.Error("del fast sync status from snapshotdb fail", "err", err)
log.Error("del fast sync status from snapshotdb fail", "err", err)
return err
}
case FastSyncBegin, FastSyncFail:
Expand All @@ -755,7 +755,7 @@ func (d *Downloader) setFastSyncStatus(status uint16) error {
common.Uint16ToBytes(status),
}
if err := d.snapshotDB.WriteBaseDB([][2][]byte{syncStatus}); err != nil {
log.Error("save fast sync status to snapshotdb fail", "err", err)
log.Error("save fast sync status to snapshotdb fail", "err", err)
return err
}
default:
Expand Down Expand Up @@ -852,17 +852,18 @@ func (d *Downloader) spawnSync(fetchers []func() error) error {
}
}
mode := d.getMode()
current := d.blockchain.CurrentBlock().NumberU64()
if mode == FastSync {
if failed {
if err := d.setFastSyncStatus(FastSyncFail); err != nil {
return err
}
if failed && current == 0 {
err = d.setFastSyncStatus(FastSyncFail)
} else {
if err := d.setFastSyncStatus(FastSyncDel); err != nil {
return err
}
err = d.setFastSyncStatus(FastSyncDel)
}
}
if mode == FullSync {
err = d.setFastSyncStatus(FastSyncDel)
}

d.queue.Close()
d.Cancel()
return err
Expand Down
Loading