Skip to content

Commit

Permalink
Upgrade to latest hive.go modules (iotaledger#1843)
Browse files Browse the repository at this point in the history
* Switch to go 1.20 and start updating to new app module

* Updated database core component

* Updated p2p package

* updated autopeering plugin

* Moved old protocol pkg from hive to hornet

Updated code for hive

* Use event preTrigger to retain the cachedObjects

* Retain the metadata before passing it to the future cone solidifier

* quote go version in yml files so that they are not interpreted as numbers

* Add rocksdb tag to linter

* Linter fixes

* Fixed kvStorable unused warning

* Updated integration tests and gendoc to go 1.20

* Use new event pretrigger option in hive to retain cached objects

* Update pkg/tangle/tangle_processor.go

Co-authored-by: muXxer <[email protected]>

* Fixed review nitpicks

* Fixed hearbeats hook/unhook

* Properly hook and unhook gossip protocol events

* Please the linter

---------

Co-authored-by: muXxer <[email protected]>
  • Loading branch information
alexsporn and muXxer authored Feb 28, 2023
1 parent 1e44da9 commit c9bd548
Show file tree
Hide file tree
Showing 170 changed files with 2,438 additions and 2,401 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_HORNET.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"
id: go

- name: Print Go version
run: go version

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET
run: go build -v .
2 changes: 1 addition & 1 deletion .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET Docker image
run: docker build . --file Dockerfile --tag hornet:latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gendoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"
id: go

- name: Print Go version
run: go version

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Run gendoc
working-directory: tools/gendoc
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
with:
version: v1.49.0
go_version_file: go.mod
version: v1.51.2
github_token: ${{ secrets.GITHUB_TOKEN }}
golangci_lint_flags: "--timeout=10m"
reporter: github-pr-check
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET image
run: docker build -f Dockerfile -t hornet:dev .
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET image
run: docker build -f Dockerfile -t hornet:dev .
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET image
run: docker build -f Dockerfile -t hornet:dev .
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET image
run: docker build -f Dockerfile -t hornet:dev .
Expand Down Expand Up @@ -152,7 +152,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Build HORNET image
run: docker build -f Dockerfile -t hornet:dev .
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_HORNET.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: "1.20"
id: go

- name: Print Go version
Expand All @@ -27,7 +27,7 @@ jobs:
run: sudo apt update && sudo apt install build-essential -y

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Test HORNET
uses: nick-invision/retry@v2
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
run:
tests: true
build-tags:
- rocksdb

linters-settings:
gofmt:
Expand All @@ -17,7 +19,7 @@ linters-settings:
staticcheck:
checks: ["all"]
nlreturn:
block-size: 2
block-size: 3
stylecheck:
initialisms: ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", "IP", "JSON", "QPS", "RAM", "RPC", "SLA", "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", "UDP", "UI", "GID", "UID", "UUID", "URI", "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", "XSS", "SIP", "RTP", "AMQP", "DB", "TS"]

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://hub.docker.com/_/golang
FROM golang:1.19-bullseye AS build
FROM golang:1.20-bullseye AS build

ARG BUILD_TAGS=rocksdb

Expand Down
6 changes: 3 additions & 3 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"os"

"github.com/iotaledger/hive.go/core/app"
"github.com/iotaledger/hive.go/core/app/core/shutdown"
"github.com/iotaledger/hive.go/core/app/plugins/profiling"
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/components/profiling"
"github.com/iotaledger/hive.go/app/components/shutdown"
"github.com/iotaledger/hornet/v2/core/database"
"github.com/iotaledger/hornet/v2/core/gossip"
"github.com/iotaledger/hornet/v2/core/p2p"
Expand Down
36 changes: 9 additions & 27 deletions core/database/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (
flag "github.com/spf13/pflag"
"go.uber.org/dig"

"github.com/iotaledger/hive.go/core/app"
"github.com/iotaledger/hive.go/app"
hivedb "github.com/iotaledger/hive.go/core/database"
"github.com/iotaledger/hive.go/core/events"
"github.com/iotaledger/hornet/v2/pkg/daemon"
"github.com/iotaledger/hornet/v2/pkg/database"
"github.com/iotaledger/hornet/v2/pkg/metrics"
Expand Down Expand Up @@ -54,9 +53,6 @@ var (

deleteDatabase = flag.Bool(CfgTangleDeleteDatabase, false, "whether to delete the database at startup")
deleteAll = flag.Bool(CfgTangleDeleteAll, false, "whether to delete the database and snapshots at startup")

// closures.
onPruningStateChanged *events.Closure
)

type dependencies struct {
Expand All @@ -82,7 +78,7 @@ func initConfigPars(c *dig.Container) error {
}

if err := c.Provide(func() cfgResult {
dbEngine, err := hivedb.EngineFromStringAllowed(ParamsDatabase.Engine, database.AllowedEnginesDefault...)
dbEngine, err := hivedb.EngineFromStringAllowed(ParamsDatabase.Engine, database.AllowedEnginesDefault)
if err != nil {
CoreComponent.LogPanic(err)
}
Expand Down Expand Up @@ -293,36 +289,22 @@ func configure() error {
CoreComponent.LogPanicf("failed to start worker: %s", err)
}

configureEvents()

return nil
}

func run() error {
if err := CoreComponent.Daemon().BackgroundWorker("Database[Events]", func(ctx context.Context) {
attachEvents()
hook := deps.Storage.Events.PruningStateChanged.Hook(func(running bool) {
deps.StorageMetrics.PruningRunning.Store(running)
if running {
deps.StorageMetrics.Prunings.Inc()
}
})
defer hook.Unhook()
<-ctx.Done()
detachEvents()
}, daemon.PriorityMetricsUpdater); err != nil {
CoreComponent.LogPanicf("failed to start worker: %s", err)
}

return nil
}

func configureEvents() {
onPruningStateChanged = events.NewClosure(func(running bool) {
deps.StorageMetrics.PruningRunning.Store(running)
if running {
deps.StorageMetrics.Prunings.Inc()
}
})
}

func attachEvents() {
deps.Storage.Events.PruningStateChanged.Hook(onPruningStateChanged)
}

func detachEvents() {
deps.Storage.Events.PruningStateChanged.Detach(onPruningStateChanged)
}
9 changes: 2 additions & 7 deletions core/database/mapdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ package database

import (
hivedb "github.com/iotaledger/hive.go/core/database"
"github.com/iotaledger/hive.go/core/events"
"github.com/iotaledger/hive.go/core/kvstore/mapdb"
"github.com/iotaledger/hive.go/kvstore/mapdb"
"github.com/iotaledger/hornet/v2/pkg/database"
"github.com/iotaledger/hornet/v2/pkg/metrics"
)

func newMapDB(metrics *metrics.DatabaseMetrics) *database.Database {

return database.New(
"",
mapdb.NewMapDB(),
hivedb.EngineMapDB,
metrics,
&database.Events{
Cleanup: events.NewEvent(database.CleanupCaller),
Compaction: events.NewEvent(events.BoolCaller),
},
database.NewEvents(),
false,
nil,
)
Expand Down
2 changes: 1 addition & 1 deletion core/database/params.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package database

import (
"github.com/iotaledger/hive.go/core/app"
"github.com/iotaledger/hive.go/app"
)

// ParametersDatabase contains the definition of the parameters used by the ParametersDatabase.
Expand Down
9 changes: 2 additions & 7 deletions core/database/pebble.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package database

import (
hivedb "github.com/iotaledger/hive.go/core/database"
"github.com/iotaledger/hive.go/core/events"
"github.com/iotaledger/hive.go/core/kvstore/pebble"
"github.com/iotaledger/hive.go/kvstore/pebble"
"github.com/iotaledger/hornet/v2/pkg/database"
"github.com/iotaledger/hornet/v2/pkg/metrics"
)

func newPebble(path string, metrics *metrics.DatabaseMetrics) *database.Database {

dbEvents := &database.Events{
Cleanup: events.NewEvent(database.CleanupCaller),
Compaction: events.NewEvent(events.BoolCaller),
}
dbEvents := database.NewEvents()

reportCompactionRunning := func(running bool) {
metrics.CompactionRunning.Store(running)
Expand Down
9 changes: 2 additions & 7 deletions core/database/rocksdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ package database

import (
hivedb "github.com/iotaledger/hive.go/core/database"
"github.com/iotaledger/hive.go/core/events"
"github.com/iotaledger/hive.go/core/kvstore/rocksdb"
"github.com/iotaledger/hive.go/kvstore/rocksdb"
"github.com/iotaledger/hornet/v2/pkg/database"
"github.com/iotaledger/hornet/v2/pkg/metrics"
)

func newRocksDB(path string, metrics *metrics.DatabaseMetrics) *database.Database {

dbEvents := &database.Events{
Cleanup: events.NewEvent(database.CleanupCaller),
Compaction: events.NewEvent(events.BoolCaller),
}
dbEvents := database.NewEvents()

rocksDatabase, err := database.NewRocksDB(path)
if err != nil {
Expand Down
Loading

0 comments on commit c9bd548

Please sign in to comment.