Skip to content

Commit

Permalink
Adapt to latest hive.go changes
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Apr 17, 2023
1 parent 7b5d260 commit bc5345a
Show file tree
Hide file tree
Showing 28 changed files with 920 additions and 961 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"
id: go

- name: Check out code into the Go module directory
Expand Down Expand Up @@ -49,7 +49,7 @@ jobs:
- name: install golang
uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"

- name: Install solc
run: |
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"
id: go

- name: Check out code into the Go module directory
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/heavy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
id: go
uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"


- name: Compile solidity contracts
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
id: go
uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"

- name: Get dependencies
id: go_dependencies
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
id: go
uses: actions/setup-go@v3
with:
go-version: 1.20.2
go-version: "1.20"

- name: install tinygo
id: tinygo
Expand Down
46 changes: 23 additions & 23 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,6 @@
"enabled": true,
"path": "waspdb/wal"
},
"profiling": {
"enabled": false,
"bindAddress": "localhost:6060"
},
"profilingRecorder": {
"enabled": false
},
"prometheus": {
"enabled": true,
"bindAddress": "0.0.0.0:2112",
"nodeMetrics": true,
"blockWALMetrics": true,
"consensusMetrics": true,
"mempoolMetrics": true,
"chainMessagesMetrics": true,
"chainStateMetrics": true,
"chainStateManagerMetrics": true,
"chainNodeConnMetrics": true,
"restAPIMetrics": true,
"goMetrics": true,
"processMetrics": true,
"promhttpMetrics": true
},
"webapi": {
"enabled": true,
"bindAddress": "0.0.0.0:9090",
Expand All @@ -123,5 +100,28 @@
"maxTopicSubscriptionsPerClient": 0
},
"debugRequestLoggerEnabled": false
},
"profiling": {
"enabled": false,
"bindAddress": "localhost:6060"
},
"profilingRecorder": {
"enabled": false
},
"prometheus": {
"enabled": true,
"bindAddress": "0.0.0.0:2112",
"nodeMetrics": true,
"blockWALMetrics": true,
"consensusMetrics": true,
"mempoolMetrics": true,
"chainMessagesMetrics": true,
"chainStateMetrics": true,
"chainStateManagerMetrics": true,
"chainNodeConnMetrics": true,
"restAPIMetrics": true,
"goMetrics": true,
"processMetrics": true,
"promhttpMetrics": true
}
}
38 changes: 18 additions & 20 deletions core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,24 @@ func App() *app.App {
return app.New(Name, Version,
app.WithVersionCheck("iotaledger", "wasp"),
app.WithInitComponent(InitComponent),
app.WithCoreComponents([]*app.CoreComponent{
shutdown.CoreComponent,
nodeconn.CoreComponent,
users.CoreComponent,
logger.CoreComponent,
database.CoreComponent,
registry.CoreComponent,
peering.CoreComponent,
dkg.CoreComponent,
processors.CoreComponent,
wasmtimevm.CoreComponent,
chains.CoreComponent,
publisher.CoreComponent,
}...),
app.WithPlugins([]*app.Plugin{
profiling.Plugin,
profilingrecorder.Plugin,
prometheus.Plugin,
webapi.Plugin,
}...),
app.WithComponents(
shutdown.Component,
nodeconn.Component,
users.Component,
logger.Component,
database.Component,
registry.Component,
peering.Component,
dkg.Component,
processors.Component,
wasmtimevm.Component,
chains.Component,
publisher.Component,
webapi.Component,
profiling.Component,
profilingrecorder.Component,
prometheus.Component,
),
)
}

Expand Down
36 changes: 17 additions & 19 deletions core/chains/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@ import (
)

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

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

type dependencies struct {
Expand All @@ -47,7 +45,7 @@ type dependencies struct {
Chains *chains.Chains
}

func initConfigPars(c *dig.Container) error {
func initConfigParams(c *dig.Container) error {
type cfgResult struct {
dig.Out
APICacheTTL time.Duration `name:"apiCacheTTL"`
Expand All @@ -58,7 +56,7 @@ func initConfigPars(c *dig.Container) error {
APICacheTTL: ParamsChains.APICacheTTL,
}
}); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return nil
Expand Down Expand Up @@ -90,7 +88,7 @@ func provide(c *dig.Container) error {
if err := c.Provide(func(deps chainsDeps) chainsResult {
return chainsResult{
Chains: chains.New(
CoreComponent.Logger(),
Component.Logger(),
deps.NodeConnection,
deps.ProcessorsConfig,
ParamsChains.BroadcastUpToNPeers,
Expand All @@ -108,29 +106,29 @@ func provide(c *dig.Container) error {
deps.NodeIdentityProvider,
deps.ConsensusStateRegistry,
deps.ChainListener,
shutdown.NewCoordinator("chains", CoreComponent.Logger().Named("Shutdown")),
shutdown.NewCoordinator("chains", Component.Logger().Named("Shutdown")),
deps.ChainMetricsProvider,
),
}
}); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return nil
}

func run() error {
err := CoreComponent.Daemon().BackgroundWorker(CoreComponent.Name, func(ctx context.Context) {
err := Component.Daemon().BackgroundWorker(Component.Name, func(ctx context.Context) {
if err := deps.Chains.Run(ctx); err != nil {
deps.ShutdownHandler.SelfShutdown(fmt.Sprintf("Starting %s failed, error: %s", CoreComponent.Name, err.Error()), true)
deps.ShutdownHandler.SelfShutdown(fmt.Sprintf("Starting %s failed, error: %s", Component.Name, err.Error()), true)
return
}

<-ctx.Done()
deps.Chains.Close()
}, daemon.PriorityChains)
if err != nil {
CoreComponent.LogError(err)
Component.LogError(err)
return err
}

Expand Down
58 changes: 28 additions & 30 deletions core/database/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@ import (
)

func init() {
CoreComponent = &app.CoreComponent{
Component: &app.Component{
Name: "Database",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
InitConfigPars: initConfigPars,
Provide: provide,
Configure: configure,
},
Component = &app.Component{
Name: "Database",
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Params: params,
InitConfigParams: initConfigParams,
Provide: provide,
Configure: configure,
}
}

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

type dependencies struct {
Expand All @@ -37,7 +35,7 @@ type dependencies struct {
ChainStateDatabaseManager *database.ChainStateDatabaseManager
}

func initConfigPars(c *dig.Container) error {
func initConfigParams(c *dig.Container) error {
type cfgResult struct {
dig.Out
DatabaseEngine hivedb.Engine `name:"databaseEngine"`
Expand All @@ -46,14 +44,14 @@ func initConfigPars(c *dig.Container) error {
if err := c.Provide(func() cfgResult {
dbEngine, err := hivedb.EngineFromStringAllowed(ParamsDatabase.Engine, database.AllowedEnginesDefault)
if err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return cfgResult{
DatabaseEngine: dbEngine,
}
}); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return nil
Expand Down Expand Up @@ -85,14 +83,14 @@ func provide(c *dig.Container) error {
database.WithPath(ParamsDatabase.ChainState.Path),
)
if err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return chainStateDatabaseManagerResult{
ChainStateDatabaseManager: manager,
}
}); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

return nil
Expand All @@ -103,56 +101,56 @@ func configure() error {
// This has to be done in a background worker, because the Daemon could receive
// a shutdown signal during startup. If that is the case, the BackgroundWorker will never be started
// and the database will never be marked as corrupted.
if err := CoreComponent.Daemon().BackgroundWorker("Database Health", func(_ context.Context) {
if err := Component.Daemon().BackgroundWorker("Database Health", func(_ context.Context) {
if err := deps.ChainStateDatabaseManager.MarkStoresCorrupted(); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}
}, daemon.PriorityDatabaseHealth); err != nil {
CoreComponent.LogPanicf("failed to start worker: %s", err)
Component.LogPanicf("failed to start worker: %s", err)
}

storesCorrupted, err := deps.ChainStateDatabaseManager.AreStoresCorrupted()
if err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

if storesCorrupted && !ParamsDatabase.DebugSkipHealthCheck {
CoreComponent.LogPanic(`
Component.LogPanic(`
WASP was not shut down properly, the database may be corrupted.
You need to resolve this situation manually.
`)
}

correctStoresVersion, err := deps.ChainStateDatabaseManager.CheckCorrectStoresVersion()
if err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

if !correctStoresVersion {
storesVersionUpdated, err2 := deps.ChainStateDatabaseManager.UpdateStoresVersion()
if err2 != nil {
CoreComponent.LogPanic(err2)
Component.LogPanic(err2)
}

if !storesVersionUpdated {
CoreComponent.LogPanic("WASP database version mismatch. The database scheme was updated.")
Component.LogPanic("WASP database version mismatch. The database scheme was updated.")
}
}

if err = CoreComponent.Daemon().BackgroundWorker("Close database", func(ctx context.Context) {
if err = Component.Daemon().BackgroundWorker("Close database", func(ctx context.Context) {
<-ctx.Done()

if err = deps.ChainStateDatabaseManager.MarkStoresHealthy(); err != nil {
CoreComponent.LogPanic(err)
Component.LogPanic(err)
}

CoreComponent.LogInfo("Syncing databases to disk ...")
Component.LogInfo("Syncing databases to disk ...")
if err = deps.ChainStateDatabaseManager.FlushAndCloseStores(); err != nil {
CoreComponent.LogPanicf("Syncing databases to disk ... failed: %s", err)
Component.LogPanicf("Syncing databases to disk ... failed: %s", err)
}
CoreComponent.LogInfo("Syncing databases to disk ... done")
Component.LogInfo("Syncing databases to disk ... done")
}, daemon.PriorityCloseDatabase); err != nil {
CoreComponent.LogPanicf("failed to start worker: %s", err)
Component.LogPanicf("failed to start worker: %s", err)
}

return nil
Expand Down
Loading

0 comments on commit bc5345a

Please sign in to comment.