Skip to content

Commit

Permalink
Merge pull request #1258 from gohornet/develop
Browse files Browse the repository at this point in the history
Release v1.1.3
  • Loading branch information
alexsporn authored Dec 29, 2021
2 parents 54e0977 + 0a90103 commit 1d93f0b
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 2 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

All notable changes to this project will be documented in this file.

## [1.1.3] - 29.12.2021

### Added
- Add new db-health tool (#1255)

### Config file changes

`config.json`
```diff
"protocol": {
...
"publicKeyRanges": [
...
{
"key": "7bac2209b576ea2235539358c7df8ca4d2f2fc35a663c760449e65eba9f8a6e7",
- "start": 2111060,
+ "start": 2108160,
"end": 3666260
},
...
]
},
```

## [1.1.2] - 22.12.2021

### Changed
Expand Down
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
},
{
"key": "7bac2209b576ea2235539358c7df8ca4d2f2fc35a663c760449e65eba9f8a6e7",
"start": 2111060,
"start": 2108160,
"end": 3666260
},
{
Expand Down
2 changes: 1 addition & 1 deletion core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
Name = "HORNET"

// Version of the app.
Version = "1.1.2"
Version = "1.1.3"
)

var (
Expand Down
15 changes: 15 additions & 0 deletions pkg/model/storage/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ func (s *StoreHealthTracker) IsTainted() (bool, error) {
return contains, nil
}

// DatabaseVersion returns the database version.
func (s *StoreHealthTracker) DatabaseVersion() (int, error) {

value, err := s.store.Get([]byte("dbVersion"))
if err != nil {
return 0, errors.Wrap(NewDatabaseError(err), "failed to read database version")
}

if len(value) < 1 {
return 0, errors.Wrap(NewDatabaseError(err), "failed to read database version")
}

return int(value[0]), nil
}

func (s *StoreHealthTracker) setDatabaseVersion(version byte) error {

_, err := s.store.Get([]byte("dbVersion"))
Expand Down
83 changes: 83 additions & 0 deletions pkg/toolset/database_health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package toolset

import (
"fmt"
"os"
"path"

flag "github.com/spf13/pflag"

"github.com/gohornet/hornet/pkg/database"
"github.com/gohornet/hornet/pkg/model/storage"

"github.com/iotaledger/hive.go/configuration"
)

func databaseHealth(_ *configuration.Configuration, args []string) error {

fs := flag.NewFlagSet("", flag.ExitOnError)
databasePath := fs.String("database", "", "the path to the database folder that should be checked")

fs.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", ToolDatabaseHealth)
fs.PrintDefaults()
}

if err := fs.Parse(args); err != nil {
return err
}

// Check if all parameters were parsed
if len(args) == 0 || fs.NArg() != 0 {
fs.Usage()
os.Exit(2)
}

checkDatabaseHealth := func(path string, name string) error {

dbExists, err := database.DatabaseExists(path)
if err != nil {
return err
}

if !dbExists {
print(fmt.Sprintf("database %s does not exist (%s)!\n", name, path))
return nil
}

dbStore, err := database.StoreWithDefaultSettings(path, false)
if err != nil {
return fmt.Errorf("%s database initialization failed: %w", name, err)
}
defer func() { _ = dbStore.Close() }()

healthTracker := storage.NewStoreHealthTracker(dbStore)

dbVersion, err := healthTracker.DatabaseVersion()
if err != nil {
return err
}

isCorrupted, err := healthTracker.IsCorrupted()
if err != nil {
return err
}

isTainted, err := healthTracker.IsTainted()
if err != nil {
return err
}

print(fmt.Sprintf("Database: '%s', Version: %d, IsCorrupted: %t, IsTainted: %t\n", name, dbVersion, isCorrupted, isTainted))
return nil
}

dbPath := *databasePath
dbName := path.Base(dbPath)

if err := checkDatabaseHealth(dbPath, dbName); err != nil {
return err
}

return nil
}
3 changes: 3 additions & 0 deletions pkg/toolset/toolset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
ToolBenchmarkCPU = "bench-cpu"
ToolDatabaseMigration = "db-migration"
ToolDatabaseLedgerHash = "db-hash"
ToolDatabaseHealth = "db-health"
ToolDatabaseSplit = "db-split"
ToolCoordinatorFixStateFile = "coo-fix-state"
)
Expand Down Expand Up @@ -64,6 +65,7 @@ func HandleTools(nodeConfig *configuration.Configuration) {
ToolBenchmarkCPU: benchmarkCPU,
ToolDatabaseMigration: databaseMigration,
ToolDatabaseLedgerHash: databaseLedgerHash,
ToolDatabaseHealth: databaseHealth,
ToolDatabaseSplit: databaseSplit,
ToolCoordinatorFixStateFile: coordinatorFixStateFile,
}
Expand Down Expand Up @@ -98,6 +100,7 @@ func listTools() {
fmt.Printf("%-20s benchmarks the CPU performance\n", fmt.Sprintf("%s:", ToolBenchmarkCPU))
fmt.Printf("%-20s migrates the database to another engine\n", fmt.Sprintf("%s:", ToolDatabaseMigration))
fmt.Printf("%-20s calculates the sha256 hash of the ledger state of a database\n", fmt.Sprintf("%s:", ToolDatabaseLedgerHash))
fmt.Printf("%-20s checks the health status of the database\n", fmt.Sprintf("%s:", ToolDatabaseHealth))
fmt.Printf("%-20s split a legacy database into `tangle` and `utxo`\n", fmt.Sprintf("%s:", ToolDatabaseSplit))
fmt.Printf("%-20s applies the latest milestone in the database to the coordinator state file\n", fmt.Sprintf("%s:", ToolCoordinatorFixStateFile))
}

0 comments on commit 1d93f0b

Please sign in to comment.