-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split worker and head node implementations (#178)
* New node packages Node core <=> worker + head node Add handling for a "WorkOrder" message Update head node Topic handling in main instead of in node Start of setting up a common "run" method + minor changes Add description Moving out handlers - install and healtcheck Further trim ported handlers Removing ported config options Remove more ported stuff Offload more common things to the node core Move most of message processing code to the node core Move notifiee code out of "node" package Update node initialization, make node core public/usable outside of worker and head node Add methods for the node API to the new head node impl Fix worker execution Update pBFT execution Worker node - work order tests Add more test cases to work order Update but move the integration tests Move/add integration test for PBFT Move more tests/remove obsolete code Move (uncompleted) last piece of test from the old node codebase Remove file - TBD later Remove obsolete file Head node - simplify roll call/work order request creation Trim down roll call struct - remove "Origin" field * Fix tests to handle libp2p Close() race condition * TODO cleanup * Minor fixed * Use math/rand/v2 everywhere * Update tests to correctly use math/rand/v2 * Fix raft race condition
- Loading branch information
Showing
89 changed files
with
2,893 additions
and
3,438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/blocklessnetwork/b7s/config" | ||
"github.com/blocklessnetwork/b7s/executor" | ||
"github.com/blocklessnetwork/b7s/executor/limits" | ||
"github.com/blocklessnetwork/b7s/fstore" | ||
"github.com/blocklessnetwork/b7s/models/blockless" | ||
"github.com/blocklessnetwork/b7s/node" | ||
"github.com/blocklessnetwork/b7s/node/head" | ||
"github.com/blocklessnetwork/b7s/node/worker" | ||
) | ||
|
||
type Node interface { | ||
Run(context.Context) error | ||
} | ||
|
||
func createWorkerNode(core node.Core, store blockless.Store, cfg *config.Config) (Node, func() error, error) { | ||
|
||
// Create function store. | ||
fstore := fstore.New(log.With().Str("component", "fstore").Logger(), store, cfg.Workspace) | ||
|
||
// Executor options. | ||
execOptions := []executor.Option{ | ||
executor.WithWorkDir(cfg.Workspace), | ||
executor.WithRuntimeDir(cfg.Worker.RuntimePath), | ||
executor.WithExecutableName(cfg.Worker.RuntimeCLI), | ||
} | ||
|
||
shutdown := func() error { | ||
return nil | ||
} | ||
if needLimiter(cfg) { | ||
limiter, err := limits.New(limits.WithCPUPercentage(cfg.Worker.CPUPercentageLimit), limits.WithMemoryKB(cfg.Worker.MemoryLimitKB)) | ||
if err != nil { | ||
return nil, shutdown, fmt.Errorf("could not create resource limiter") | ||
} | ||
|
||
shutdown = func() error { | ||
return limiter.Shutdown() | ||
} | ||
|
||
execOptions = append(execOptions, executor.WithLimiter(limiter)) | ||
} | ||
|
||
// Create an executor. | ||
executor, err := executor.New(log.With().Str("component", "executor").Logger(), execOptions...) | ||
if err != nil { | ||
return nil, shutdown, fmt.Errorf("could not create an executor: %w", err) | ||
} | ||
|
||
worker, err := worker.New(core, fstore, executor, | ||
worker.AttributeLoading(cfg.LoadAttributes), | ||
worker.Workspace(cfg.Workspace), | ||
) | ||
if err != nil { | ||
return nil, shutdown, fmt.Errorf("could not create a worker node: %w", err) | ||
} | ||
|
||
return worker, shutdown, nil | ||
} | ||
|
||
func createHeadNode(core node.Core, cfg *config.Config) (Node, error) { | ||
|
||
head, err := head.New(core) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not create a head node: %w", err) | ||
} | ||
|
||
return head, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.