Skip to content

Commit 489ff9b

Browse files
committed
go/worker/common/committee: Add config parameter
1 parent ee1aed0 commit 489ff9b

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

go/worker/common/committee/node.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ type NodeHooks interface {
4747
Initialized() <-chan struct{}
4848
}
4949

50+
// Config contains committee node specific configuration.
51+
type Config struct {
52+
ChainContext string
53+
Identity *identity.Identity
54+
TxPool tpConfig.Config
55+
WillRegisterComputeRuntime bool
56+
}
57+
5058
// Node is a committee node.
5159
type Node struct {
5260
*runtimeRegistry.RuntimeHostNode
@@ -643,17 +651,14 @@ func (n *Node) handleDispatchInfo() {
643651
}
644652

645653
func NewNode(
646-
chainContext string,
654+
cfg Config,
647655
runtime runtimeRegistry.Runtime,
648656
provisioner host.Provisioner,
649657
rtRegistry runtimeRegistry.Registry,
650-
identity *identity.Identity,
651658
keymanager keymanager.Backend,
652659
consensus consensus.Service,
653660
lightProvider consensus.LightProvider,
654661
p2pHost p2pAPI.Service,
655-
txPoolCfg tpConfig.Config,
656-
willRegisterComputeRuntime bool,
657662
) (*Node, error) {
658663
metricsOnce.Do(func() {
659664
prometheus.MustRegister(nodeCollectors...)
@@ -662,25 +667,25 @@ func NewNode(
662667
ctx, cancel := context.WithCancel(context.Background())
663668

664669
// Prepare committee group services.
665-
group, err := NewGroup(ctx, runtime.ID(), identity, consensus, p2pHost)
670+
group, err := NewGroup(ctx, runtime.ID(), cfg.Identity, consensus, p2pHost)
666671
if err != nil {
667672
cancel()
668673
return nil, err
669674
}
670675

671-
txTopic := p2pProtocol.NewTopicKindTxID(chainContext, runtime.ID())
676+
txTopic := p2pProtocol.NewTopicKindTxID(cfg.ChainContext, runtime.ID())
672677

673678
n := &Node{
674-
ChainContext: chainContext,
679+
ChainContext: cfg.ChainContext,
675680
Runtime: runtime,
676681
RuntimeRegistry: rtRegistry,
677-
Identity: identity,
682+
Identity: cfg.Identity,
678683
KeyManager: keymanager,
679684
Consensus: consensus,
680685
LightProvider: lightProvider,
681686
Group: group,
682687
P2P: p2pHost,
683-
willRegisterComputeRuntime: willRegisterComputeRuntime,
688+
willRegisterComputeRuntime: cfg.WillRegisterComputeRuntime,
684689
txTopic: txTopic,
685690
ctx: ctx,
686691
cancelCtx: cancel,
@@ -692,7 +697,7 @@ func NewNode(
692697
}
693698

694699
// Prepare the key manager client wrapper.
695-
n.KeyManagerClient = NewKeyManagerClientWrapper(p2pHost, consensus, chainContext, n.logger)
700+
n.KeyManagerClient = NewKeyManagerClientWrapper(p2pHost, consensus, cfg.ChainContext, n.logger)
696701

697702
// Prepare the runtime host handler.
698703
handler := runtimeRegistry.NewRuntimeHostHandler(&nodeEnvironment{n}, n.Runtime, consensus)
@@ -715,13 +720,13 @@ func NewNode(
715720
n.services = service.NewGroup(notifier, lbNotifier, kmNotifier, n.roflNotifier)
716721

717722
// Prepare transaction pool.
718-
n.TxPool = txpool.New(runtime.ID(), txPoolCfg, rhn.GetHostedRuntime(), runtime.History(), n)
723+
n.TxPool = txpool.New(runtime.ID(), cfg.TxPool, rhn.GetHostedRuntime(), runtime.History(), n)
719724

720725
// Register transaction message handler as that is something that all workers must handle.
721726
p2pHost.RegisterHandler(txTopic, &txMsgHandler{n})
722727

723728
// Register transaction sync service.
724-
p2pHost.RegisterProtocolServer(txsync.NewServer(chainContext, runtime.ID(), n.TxPool))
729+
p2pHost.RegisterProtocolServer(txsync.NewServer(cfg.ChainContext, runtime.ID(), n.TxPool))
725730

726731
return n, nil
727732
}

go/worker/common/worker.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,22 @@ func (w *Worker) registerRuntime(runtime runtimeRegistry.Runtime) error {
146146
"runtime_id", id,
147147
)
148148

149+
cfg := committee.Config{
150+
ChainContext: w.ChainContext,
151+
Identity: w.Identity,
152+
TxPool: w.cfg.TxPool,
153+
WillRegisterComputeRuntime: w.cfg.WillRegisterComputeRuntime,
154+
}
155+
149156
node, err := committee.NewNode(
150-
w.ChainContext,
157+
cfg,
151158
runtime,
152159
w.Provisioner,
153160
w.RuntimeRegistry,
154-
w.Identity,
155161
w.KeyManager,
156162
w.Consensus,
157163
w.LightProvider,
158164
w.P2P,
159-
w.cfg.TxPool,
160-
w.cfg.WillRegisterComputeRuntime,
161165
)
162166
if err != nil {
163167
return err

0 commit comments

Comments
 (0)