diff --git a/services/index/vmblock_index.go b/services/index/vmblock_index.go index 07e8ded0..0b6504d8 100644 --- a/services/index/vmblock_index.go +++ b/services/index/vmblock_index.go @@ -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 } @@ -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) @@ -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") @@ -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") @@ -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) } @@ -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() }