Skip to content

Commit 6012b57

Browse files
committed
go: Avoid coupling of common and registration worker
1 parent ec6b6f4 commit 6012b57

3 files changed

Lines changed: 16 additions & 28 deletions

File tree

go/oasis-node/cmd/node/node.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/oasisprotocol/oasis-core/go/common/grpc"
1414
"github.com/oasisprotocol/oasis-core/go/common/identity"
1515
"github.com/oasisprotocol/oasis-core/go/common/logging"
16+
"github.com/oasisprotocol/oasis-core/go/common/node"
1617
"github.com/oasisprotocol/oasis-core/go/common/persistent"
1718
"github.com/oasisprotocol/oasis-core/go/common/version"
1819
"github.com/oasisprotocol/oasis-core/go/config"
@@ -193,9 +194,18 @@ func (n *Node) startRuntimeServices(genesisDoc *genesisAPI.Document) error {
193194
}
194195

195196
func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
196-
var err error
197+
// Parse sentry configuration.
198+
var sentryAddresses []node.TLSAddress
199+
for _, v := range config.GlobalConfig.Runtime.SentryAddresses {
200+
var tlsAddr node.TLSAddress
201+
if err := tlsAddr.UnmarshalText([]byte(v)); err != nil {
202+
return fmt.Errorf("bad sentry address (%s): %w", v, err)
203+
}
204+
sentryAddresses = append(sentryAddresses, tlsAddr)
205+
}
197206

198207
// Initialize runtime provisioner.
208+
var err error
199209
n.Provisioner, err = provisioner.New(n.dataDir, n.commonStore, n.Identity, n.Consensus, genesisDoc)
200210
if err != nil {
201211
return err
@@ -229,8 +239,6 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
229239
}
230240
n.svcMgr.Register(n.CommonWorker)
231241

232-
workerCommonCfg := n.CommonWorker.GetConfig()
233-
234242
// Initialize the registration worker.
235243
n.RegistrationWorker, err = workerRegistration.New(
236244
n.Consensus.Beacon(),
@@ -239,7 +247,7 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
239247
n.EntityID,
240248
n.Consensus,
241249
n.P2P,
242-
&workerCommonCfg,
250+
sentryAddresses,
243251
n.commonStore,
244252
n, // the delegate to be called on registration shutdown
245253
n.RuntimeRegistry,

go/worker/common/config.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
package common
22

33
import (
4-
"fmt"
5-
64
"github.com/oasisprotocol/oasis-core/go/common/logging"
7-
"github.com/oasisprotocol/oasis-core/go/common/node"
85
"github.com/oasisprotocol/oasis-core/go/config"
96
tpConfig "github.com/oasisprotocol/oasis-core/go/runtime/txpool/config"
107
)
118

129
// Config contains common worker config.
1310
type Config struct {
14-
SentryAddresses []node.TLSAddress
15-
1611
TxPool tpConfig.Config
1712

1813
logger *logging.Logger
1914
}
2015

2116
// NewConfig creates a new worker config.
2217
func NewConfig() (*Config, error) {
23-
// Parse sentry configuration.
24-
var sentryAddresses []node.TLSAddress
25-
for _, v := range config.GlobalConfig.Runtime.SentryAddresses {
26-
var tlsAddr node.TLSAddress
27-
if err := tlsAddr.UnmarshalText([]byte(v)); err != nil {
28-
return nil, fmt.Errorf("worker: bad sentry address (%s): %w", v, err)
29-
}
30-
sentryAddresses = append(sentryAddresses, tlsAddr)
31-
}
32-
3318
cfg := Config{
34-
SentryAddresses: sentryAddresses,
35-
TxPool: config.GlobalConfig.Runtime.TxPool,
36-
logger: logging.GetLogger("worker/config"),
19+
TxPool: config.GlobalConfig.Runtime.TxPool,
20+
logger: logging.GetLogger("worker/config"),
3721
}
3822

3923
return &cfg, nil

go/worker/registration/worker.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
3232
runtimeRegistry "github.com/oasisprotocol/oasis-core/go/runtime/registry"
3333
sentryClient "github.com/oasisprotocol/oasis-core/go/sentry/client"
34-
workerCommon "github.com/oasisprotocol/oasis-core/go/worker/common"
3534
)
3635

3736
const (
@@ -177,8 +176,6 @@ type Worker struct {
177176

178177
enabled bool
179178

180-
workerCommonCfg *workerCommon.Config
181-
182179
store *persistent.ServiceStore
183180
storedDeregister bool
184181
deregRequested uint32
@@ -1010,7 +1007,7 @@ func New(
10101007
entityID *signature.PublicKey,
10111008
consensus consensus.Service,
10121009
p2p p2p.Service,
1013-
workerCommonCfg *workerCommon.Config,
1010+
sentryAddresses []node.TLSAddress,
10141011
store *persistent.CommonStore,
10151012
delegate Delegate,
10161013
runtimeRegistry runtimeRegistry.Registry,
@@ -1026,10 +1023,9 @@ func New(
10261023
}
10271024

10281025
w := &Worker{
1029-
workerCommonCfg: workerCommonCfg,
10301026
store: serviceStore,
10311027
delegate: delegate,
1032-
sentryAddresses: workerCommonCfg.SentryAddresses,
1028+
sentryAddresses: sentryAddresses,
10331029
runtimeRegistry: runtimeRegistry,
10341030
beacon: beacon,
10351031
registry: registry,

0 commit comments

Comments
 (0)