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

BUG:Invalid vmblock index data update #308

Merged
merged 1 commit into from
Nov 30, 2022
Merged
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
27 changes: 15 additions & 12 deletions services/index/vmblock_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func (idx *VMBlockIndex) Init() error {
// It shows that the data is encounter
bh := bc.GetBlockHashByOrder(uint(tipOrder))
if bh != nil && bh.IsEqual(tipHash) {
return idx.caughtUpFrom(uint(tipOrder+1))
return idx.caughtUpFrom(uint(tipOrder + 1))
}
}
return fmt.Errorf("vm block index(%s:%d) is out of synchronization(%s:%d) and can only be deleted and rebuilt:index --dropvmblock",
tipHash, tipOrder, mainHash, mainOrder)
}
log.Info(fmt.Sprintf("Current vmblock index tip:%s,%d",tipHash.String(),tipOrder))
log.Info(fmt.Sprintf("Current vmblock index tip:%s,%d", tipHash.String(), tipOrder))
}
return nil
}
Expand All @@ -70,9 +70,9 @@ func (idx *VMBlockIndex) caughtUpFrom(startOrder uint) error {
return nil
}
if mainOrder > 0 {
log.Info(fmt.Sprintf("Start caught up vm block index from (order:%d) to tip(hash:%s,order:%d)",startOrder, mainHash, mainOrder))
log.Info(fmt.Sprintf("Start caught up vm block index from (order:%d) to tip(hash:%s,order:%d)", startOrder, mainHash, mainOrder))
logLvl := l.Glogger().GetVerbosity()
bar := progressbar.Default(int64(mainOrder-startOrder), fmt.Sprintf("%s:",idx.Name()))
bar := progressbar.Default(int64(mainOrder-startOrder), fmt.Sprintf("%s:", idx.Name()))
l.Glogger().Verbosity(l.LvlCrit)
for i := uint(startOrder); i <= mainOrder; i++ {
bar.Add(1)
Expand All @@ -87,18 +87,21 @@ func (idx *VMBlockIndex) caughtUpFrom(startOrder uint) error {
if bid == 0 {
continue
}
err:=idx.ConnectBlock(bh,bid)
err := idx.ConnectBlock(bh, bid)
if err != nil {
return err
}
}
l.Glogger().Verbosity(logLvl)
}
log.Info(fmt.Sprintf("Current vmblock index tip:%s,%d",mainHash.String(),mainOrder))
return idx.UpdateMainTip(mainHash,uint64(mainOrder))
log.Info(fmt.Sprintf("Current vmblock index tip:%s,%d", mainHash.String(), mainOrder))
return idx.UpdateMainTip(mainHash, uint64(mainOrder))
}

func (idx *VMBlockIndex) ConnectBlock(bh *hash.Hash,vmbid uint64) error {
func (idx *VMBlockIndex) ConnectBlock(bh *hash.Hash, vmbid uint64) error {
if vmbid == 0 {
return nil
}
vmbiStore := idx.consensus.VMBlockIndexStore()
if vmbiStore == nil {
return fmt.Errorf("No vm block index store")
Expand All @@ -108,7 +111,7 @@ func (idx *VMBlockIndex) ConnectBlock(bh *hash.Hash,vmbid uint64) error {
return staging.CommitAllChanges(idx.consensus.DatabaseContext(), stagingArea)
}

func (idx *VMBlockIndex) DisconnectBlock(bh *hash.Hash,vmbid uint64) error {
func (idx *VMBlockIndex) DisconnectBlock(bh *hash.Hash, vmbid uint64) error {
vmbiStore := idx.consensus.VMBlockIndexStore()
if vmbiStore == nil {
return fmt.Errorf("No vm block index store")
Expand All @@ -118,13 +121,13 @@ func (idx *VMBlockIndex) DisconnectBlock(bh *hash.Hash,vmbid uint64) error {
return staging.CommitAllChanges(idx.consensus.DatabaseContext(), stagingArea)
}

func (idx *VMBlockIndex) UpdateMainTip(bh *hash.Hash,order uint64) error {
func (idx *VMBlockIndex) UpdateMainTip(bh *hash.Hash, order uint64) error {
vmbiStore := idx.consensus.VMBlockIndexStore()
if vmbiStore == nil {
return fmt.Errorf("No vm block index store")
}
stagingArea := model.NewStagingArea()
vmbiStore.StageTip(stagingArea, bh,order)
vmbiStore.StageTip(stagingArea, bh, order)
return staging.CommitAllChanges(idx.consensus.DatabaseContext(), stagingArea)
}

Expand All @@ -148,6 +151,6 @@ func DropVMBlockIndex(db database.DB, interrupt <-chan struct{}) error {
if err != nil {
return err
}
log.Info(fmt.Sprintf("All vmblock index at (%s,%d) will be deleted",tipHash,tipOrder))
log.Info(fmt.Sprintf("All vmblock index at (%s,%d) will be deleted", tipHash, tipOrder))
return vmbiStore.Clean()
}