-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/worker/consensus: Add public consensus services worker
A public consensus services worker enables any full consensus node to expose light client services to other nodes that may need them (e.g., they are needed to support light clients). The worker can be enabled using --worker.consensus.enabled and is disabled by default. Enabling the public consensus services worker exposes the light consensus client interface over publicly accessible gRPC.
- Loading branch information
Showing
6 changed files
with
146 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
go/worker/consensus: Add public consensus services worker | ||
|
||
A public consensus services worker enables any full consensus node to expose | ||
light client services to other nodes that may need them (e.g., they are needed | ||
to support light clients). | ||
|
||
The worker can be enabled using --worker.consensus.enabled and is disabled by | ||
default. Enabling the public consensus services worker exposes the light | ||
consensus client interface over publicly accessible gRPC. |
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
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,95 @@ | ||
// Package consensus implements publicly accessible consensus services. | ||
package consensus | ||
|
||
import ( | ||
flag "github.com/spf13/pflag" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/oasislabs/oasis-core/go/common/logging" | ||
consensus "github.com/oasislabs/oasis-core/go/consensus/api" | ||
workerCommon "github.com/oasislabs/oasis-core/go/worker/common" | ||
) | ||
|
||
const ( | ||
// CfgWorkerEnabled enables the consensus services worker. | ||
CfgWorkerEnabled = "worker.consensus.enabled" | ||
) | ||
|
||
// Flags has the configuration flags. | ||
var Flags = flag.NewFlagSet("", flag.ContinueOnError) | ||
|
||
// Worker is a worker providing publicly accessible consensus services. | ||
// | ||
// Currently this only exposes the consensus light client service. | ||
type Worker struct { | ||
enabled bool | ||
|
||
commonWorker *workerCommon.Worker | ||
|
||
quitCh chan struct{} | ||
|
||
logger *logging.Logger | ||
} | ||
|
||
// Name returns the service name. | ||
func (w *Worker) Name() string { | ||
return "public consensus services worker" | ||
} | ||
|
||
// Enabled returns if worker is enabled. | ||
func (w *Worker) Enabled() bool { | ||
return w.enabled | ||
} | ||
|
||
// Start starts the worker. | ||
func (w *Worker) Start() error { | ||
if w.enabled { | ||
w.logger.Info("starting public consensus services worker") | ||
} | ||
return nil | ||
} | ||
|
||
// Stop halts the service. | ||
func (w *Worker) Stop() { | ||
close(w.quitCh) | ||
} | ||
|
||
// Quit returns a channel that will be closed when the service terminates. | ||
func (w *Worker) Quit() <-chan struct{} { | ||
return w.quitCh | ||
} | ||
|
||
// Cleanup performs the service specific post-termination cleanup. | ||
func (w *Worker) Cleanup() { | ||
} | ||
|
||
// New creates a new public consensus services worker. | ||
func New(commonWorker *workerCommon.Worker) (*Worker, error) { | ||
w := &Worker{ | ||
enabled: Enabled(), | ||
commonWorker: commonWorker, | ||
quitCh: make(chan struct{}), | ||
logger: logging.GetLogger("worker/consensus"), | ||
} | ||
|
||
if w.enabled { | ||
// Register the consensus light client service. | ||
consensus.RegisterLightService(commonWorker.Grpc.Server(), commonWorker.Consensus) | ||
|
||
// TODO: We could introduce a role bit for nodes providing these public services so that you | ||
// could easily discover suitable nodes to use. | ||
} | ||
|
||
return w, nil | ||
} | ||
|
||
// Enabled reads our enabled flag from viper. | ||
func Enabled() bool { | ||
return viper.GetBool(CfgWorkerEnabled) | ||
} | ||
|
||
func init() { | ||
Flags.Bool(CfgWorkerEnabled, false, "Enable public consensus services worker") | ||
|
||
_ = viper.BindPFlags(Flags) | ||
} |