Skip to content

Commit

Permalink
Added fix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Emyrk committed Jun 17, 2017
1 parent f1f6883 commit 88b57ae
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Utilities/CorrectChainHeads/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

var CheckFloating bool
var UsingAPI bool
var FixIt bool

const level string = "level"
const bolt string = "bolt"
Expand All @@ -27,11 +28,13 @@ func main() {
var (
useApi = flag.Bool("api", false, "Use API instead")
checkFloating = flag.Bool("floating", false, "Check Floating")
fix = flag.Bool("fix", false, "Actually fix head")
)

flag.Parse()
UsingAPI = *useApi
CheckFloating = *checkFloating
FixIt = *fix

fmt.Println("Usage:")
fmt.Println("CorrectChainHeads level/bolt/api DBFileLocation")
Expand Down Expand Up @@ -173,6 +176,9 @@ func FindHeads(f Fetcher) {
fmt.Printf("ERROR: Chainhead found: %s, Expected %s :: For Chain: %s at height %d\n",
ch.String(), eblk.GetKeyMR().String(), eblk.GetChainID().String(), height)
errCount++
if FixIt {
f.SetChainHeads([]interfaces.IHash{eblk.GetKeyMR()}, []interfaces.IHash{eblk.GetChainID()})
}
}
}
}
Expand Down Expand Up @@ -210,7 +216,7 @@ func FindHeads(f Fetcher) {
}
}
}
fmt.Printf("%d Errors found", errCount)
fmt.Printf("%d Errors found checking for bad links\n", errCount)

}

Expand All @@ -220,6 +226,7 @@ type Fetcher interface {
//FetchDBlock(hash interfaces.IHash) (interfaces.IDirectoryBlock, error)
FetchHeadIndexByChainID(chainID interfaces.IHash) (interfaces.IHash, error)
FetchEBlock(hash interfaces.IHash) (interfaces.IEntryBlock, error)
SetChainHeads(primaryIndexes, chainIDs []interfaces.IHash) error
}

func NewDBReader(levelBolt string, path string) *databaseOverlay.Overlay {
Expand Down Expand Up @@ -250,6 +257,10 @@ func NewAPIReader(loc string) *APIReader {
return a
}

func (a *APIReader) SetChainHeads(primaryIndexes, chainIDs []interfaces.IHash) error {
return nil
}

func (a *APIReader) FetchEBlock(hash interfaces.IHash) (interfaces.IEntryBlock, error) {
return nil, fmt.Errorf("Not implemented for api")
}
Expand Down

0 comments on commit 88b57ae

Please sign in to comment.