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

Adapt to latest hive.go changes #82

Merged
merged 10 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions .github/workflows/gendoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: "1.21"
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
with:
submodules: 'true'

Expand All @@ -28,7 +28,7 @@ jobs:
run: go mod tidy && go run main.go

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "chore(gendoc): update docs"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
submodules: 'true'

- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
go-version: "1.21"

- name: Build
run: go build -v ./...
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
submodules: 'true'

- name: golangci-lint
uses: reviewdog/action-golangci-lint@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
password: ${{ secrets.IOTALEDGER_DOCKER_PASSWORD }}

- name: Build and push to Dockerhub
uses: docker/build-push-action@v3
uses: docker/build-push-action@v4
with:
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
Expand Down
5 changes: 3 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "core/faucet/frontend"]
path = core/faucet/frontend
[submodule "components/faucet/frontend"]
path = components/faucet/frontend
url = https://github.com/iotaledger/chrysalis-faucet.git
branch = hornet
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ linters:
- containedctx
- contextcheck
- decorder
- depguard
#- depguard
- dogsled
- dupl
- durationcheck
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.21-bullseye AS build

# Ensure ca-certificates are up to date
RUN update-ca-certificates
Expand Down
24 changes: 11 additions & 13 deletions core/app/app.go → components/app/app.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package app

import (
"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/inx-app/core/inx"
"github.com/iotaledger/inx-faucet/core/faucet"
"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/inx-app/components/inx"
"github.com/iotaledger/inx-faucet/components/faucet"
)

var (
Expand All @@ -19,14 +19,12 @@ var (
func App() *app.App {
return app.New(Name, Version,
app.WithInitComponent(InitComponent),
app.WithCoreComponents([]*app.CoreComponent{
inx.CoreComponent,
faucet.CoreComponent,
shutdown.CoreComponent,
}...),
app.WithPlugins([]*app.Plugin{
profiling.Plugin,
}...),
app.WithComponents(
inx.Component,
faucet.Component,
shutdown.Component,
profiling.Component,
),
)
}

Expand Down
60 changes: 29 additions & 31 deletions core/faucet/component.go → components/faucet/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/iotaledger/hive.go/core/app"
"github.com/iotaledger/hive.go/core/app/pkg/shutdown"
"github.com/iotaledger/hive.go/core/crypto"
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/app/shutdown"
"github.com/iotaledger/hive.go/crypto"
"github.com/iotaledger/hornet/v2/pkg/common"
"github.com/iotaledger/inx-app/pkg/httpserver"
"github.com/iotaledger/inx-app/pkg/nodebridge"
Expand All @@ -34,20 +34,18 @@ const (
)

func init() {
CoreComponent = &app.CoreComponent{
Component: &app.Component{
Name: "Faucet",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
Provide: provide,
Run: run,
},
Component = &app.Component{
Name: "Faucet",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
Provide: provide,
Run: run,
}
}

var (
CoreComponent *app.CoreComponent
deps dependencies
Component *app.Component
deps dependencies
)

type dependencies struct {
Expand All @@ -61,20 +59,20 @@ func provide(c *dig.Container) error {

privateKeys, err := loadEd25519PrivateKeysFromEnvironment("FAUCET_PRV_KEY")
if err != nil {
CoreComponent.LogErrorfAndExit("loading faucet private key failed, err: %s", err)
Component.LogErrorfAndExit("loading faucet private key failed, err: %s", err)
}

if len(privateKeys) == 0 {
CoreComponent.LogErrorAndExit("loading faucet private key failed, err: no private keys given")
Component.LogErrorAndExit("loading faucet private key failed, err: no private keys given")
}

if len(privateKeys) > 1 {
CoreComponent.LogErrorAndExit("loading faucet private key failed, err: too many private keys given")
Component.LogErrorAndExit("loading faucet private key failed, err: too many private keys given")
}

privateKey := privateKeys[0]
if len(privateKey) != ed25519.PrivateKeySize {
CoreComponent.LogErrorAndExit("loading faucet private key failed, err: wrong private key length")
Component.LogErrorAndExit("loading faucet private key failed, err: wrong private key length")
}

publicKey, ok := privateKey.Public().(ed25519.PublicKey)
Expand All @@ -93,7 +91,7 @@ func provide(c *dig.Container) error {
if err := c.Provide(func(deps faucetDeps) (*faucet.Faucet, error) {

fetchMetadata := func(blockID iotago.BlockID) (*faucet.Metadata, error) {
ctx, cancel := context.WithTimeout(CoreComponent.Daemon().ContextStopped(), 5*time.Second)
ctx, cancel := context.WithTimeout(Component.Daemon().ContextStopped(), 5*time.Second)
defer cancel()

metadata, err := deps.NodeBridge.BlockMetadata(ctx, blockID)
Expand All @@ -115,7 +113,7 @@ func provide(c *dig.Container) error {
}, nil
}

ctxIndexer, cancelIndexer := context.WithTimeout(CoreComponent.Daemon().ContextStopped(), indexerPluginAvailableTimeout)
ctxIndexer, cancelIndexer := context.WithTimeout(Component.Daemon().ContextStopped(), indexerPluginAvailableTimeout)
defer cancelIndexer()

indexer, err := deps.NodeBridge.Indexer(ctxIndexer)
Expand All @@ -124,7 +122,7 @@ func provide(c *dig.Container) error {
}

collectOutputs := func(address iotago.Address) ([]faucet.UTXOOutput, error) {
ctxRequest, cancelRequest := context.WithTimeout(CoreComponent.Daemon().ContextStopped(), inxRequestTimeout)
ctxRequest, cancelRequest := context.WithTimeout(Component.Daemon().ContextStopped(), inxRequestTimeout)
defer cancelRequest()

protoParas := deps.NodeBridge.ProtocolParameters()
Expand Down Expand Up @@ -159,7 +157,7 @@ func provide(c *dig.Container) error {
for i := range outputs {
basicOutput, ok := outputs[i].(*iotago.BasicOutput)
if !ok {
CoreComponent.LogWarnf("invalid type: expected *iotago.BasicOutput, got %T", outputs[i])
Component.LogWarnf("invalid type: expected *iotago.BasicOutput, got %T", outputs[i])

continue
}
Expand All @@ -186,15 +184,15 @@ func provide(c *dig.Container) error {
}

return faucet.New(
CoreComponent.Daemon(),
Component.Daemon(),
fetchMetadata,
collectOutputs,
deps.NodeBridge.IsNodeHealthy,
deps.NodeBridge.ProtocolParameters,
&faucetAddress,
faucetSigner,
submitBlock,
faucet.WithLogger(CoreComponent.Logger()),
faucet.WithLogger(Component.Logger()),
faucet.WithTokenName(deps.NodeBridge.NodeConfig.BaseToken.Name),
faucet.WithAmount(ParamsFaucet.Amount),
faucet.WithSmallAmount(ParamsFaucet.SmallAmount),
Expand All @@ -204,7 +202,7 @@ func provide(c *dig.Container) error {
faucet.WithBatchTimeout(ParamsFaucet.BatchTimeout),
), nil
}); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return nil
Expand All @@ -213,7 +211,7 @@ func provide(c *dig.Container) error {
func run() error {

// create a background worker that handles the ledger updates
if err := CoreComponent.Daemon().BackgroundWorker("Faucet[LedgerUpdates]", func(ctx context.Context) {
if err := Component.Daemon().BackgroundWorker("Faucet[LedgerUpdates]", func(ctx context.Context) {
if err := deps.NodeBridge.ListenToLedgerUpdates(ctx, 0, 0, func(update *nodebridge.LedgerUpdate) error {
createdOutputs := iotago.OutputIDs{}
for _, output := range update.Created {
Expand All @@ -234,19 +232,19 @@ func run() error {
deps.ShutdownHandler.SelfShutdown(fmt.Sprintf("Listening to LedgerUpdates failed, error: %s", err), false)
}
}, daemon.PriorityStopFaucetLedgerUpdates); err != nil {
CoreComponent.LogPanicf("failed to start worker: %s", err)
Component.LogPanicf("failed to start worker: %s", err)
}

// create a background worker that handles the enqueued faucet requests
if err := CoreComponent.Daemon().BackgroundWorker("Faucet", func(ctx context.Context) {
if err := Component.Daemon().BackgroundWorker("Faucet", func(ctx context.Context) {
if err := deps.Faucet.RunFaucetLoop(ctx, nil); err != nil && common.IsCriticalError(err) != nil {
deps.ShutdownHandler.SelfShutdown(fmt.Sprintf("faucet plugin hit a critical error: %s", err.Error()), true)
}
}, daemon.PriorityStopFaucet); err != nil {
CoreComponent.LogPanicf("failed to start worker: %s", err)
Component.LogPanicf("failed to start worker: %s", err)
}

e := httpserver.NewEcho(CoreComponent.Logger(), nil, ParamsFaucet.DebugRequestLoggerEnabled)
e := httpserver.NewEcho(Component.Logger(), nil, ParamsFaucet.DebugRequestLoggerEnabled)
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{http.MethodGet, http.MethodPost},
Expand All @@ -255,10 +253,10 @@ func run() error {
setupRoutes(e)

go func() {
CoreComponent.LogInfof("You can now access the faucet website using: http://%s", ParamsFaucet.BindAddress)
Component.LogInfof("You can now access the faucet website using: http://%s", ParamsFaucet.BindAddress)

if err := e.Start(ParamsFaucet.BindAddress); err != nil && !errors.Is(err, http.ErrServerClosed) {
CoreComponent.LogWarnf("Stopped faucet website server due to an error (%s)", err)
Component.LogWarnf("Stopped faucet website server due to an error (%s)", err)
}
}()

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion core/faucet/params.go → components/faucet/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package faucet
import (
"time"

"github.com/iotaledger/hive.go/core/app"
"github.com/iotaledger/hive.go/app"
iotago "github.com/iotaledger/iota.go/v3"
)

Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"disableStacktrace": false,
"stacktraceLevel": "panic",
"encoding": "console",
"encodingConfig": {
"timeEncoder": "rfc3339"
},
"outputPaths": [
"stdout"
],
Expand Down
Loading