Skip to content

Commit 1531f63

Browse files
Merge pull request #6481 from oasisprotocol/martin/trivial/registration-worker-signer
go/worker/registration: Clean dead registration signer code
2 parents 59b8f32 + 573fb3c commit 1531f63

14 files changed

Lines changed: 136 additions & 181 deletions

File tree

.changelog/6481.trivial.md

Whitespace-only changes.

go/oasis-node/cmd/debug/byzantine/node.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
1111
"github.com/oasisprotocol/oasis-core/go/common"
1212
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
13+
"github.com/oasisprotocol/oasis-core/go/common/entity"
1314
"github.com/oasisprotocol/oasis-core/go/common/identity"
1415
"github.com/oasisprotocol/oasis-core/go/common/logging"
1516
"github.com/oasisprotocol/oasis-core/go/common/node"
17+
"github.com/oasisprotocol/oasis-core/go/config"
1618
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1719
genesis "github.com/oasisprotocol/oasis-core/go/genesis/file"
1820
cmdCommon "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common"
@@ -124,6 +126,23 @@ func initializeAndRegisterByzantineNode(
124126
"id", b.identity.NodeSigner.Public(),
125127
)
126128

129+
var entityID *signature.PublicKey
130+
if cmdFlags.DebugTestEntity() {
131+
testEntity, _, _ := entity.TestEntity()
132+
entityID = &testEntity.ID
133+
} else {
134+
entityID, err = config.GlobalConfig.Registration.ResolveEntityID()
135+
if err != nil {
136+
return nil, fmt.Errorf("failed to resolve entity ID: %w", err)
137+
}
138+
}
139+
if entityID == nil {
140+
return nil, fmt.Errorf("no entity ID configured")
141+
}
142+
if !entityID.IsValid() {
143+
return nil, fmt.Errorf("invalid entity ID")
144+
}
145+
127146
// Initialize the genesis provider.
128147
genesis := genesis.NewProvider(cmdFlags.GenesisFile())
129148

@@ -172,6 +191,7 @@ func initializeAndRegisterByzantineNode(
172191
if err = registryRegisterNode(
173192
b.cometbft.service,
174193
b.identity,
194+
*entityID,
175195
b.p2p.service.Addresses(),
176196
b.runtimeID,
177197
b.capabilities,

go/oasis-node/cmd/debug/byzantine/registry.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ import (
1111
"github.com/oasisprotocol/oasis-core/go/common/node"
1212
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1313
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
14-
"github.com/oasisprotocol/oasis-core/go/worker/registration"
1514
)
1615

17-
func registryRegisterNode(svc consensus.Service, id *identity.Identity, p2pAddresses []node.Address, runtimeID common.Namespace, capabilities *node.Capabilities, roles node.RolesMask) error {
18-
entityID, registrationSigner, err := registration.GetRegistrationSigner(id)
19-
if err != nil {
20-
return fmt.Errorf("registration GetRegistrationSigner: %w", err)
21-
}
22-
if registrationSigner == nil {
23-
return fmt.Errorf("nil registrationSigner")
24-
}
25-
16+
func registryRegisterNode(
17+
svc consensus.Service,
18+
id *identity.Identity,
19+
entityID signature.PublicKey,
20+
p2pAddresses []node.Address,
21+
runtimeID common.Namespace,
22+
capabilities *node.Capabilities,
23+
roles node.RolesMask,
24+
) error {
2625
var runtimes []*node.Runtime
2726
if roles&registry.RuntimesRequiredRoles != 0 {
2827
runtimes = []*node.Runtime{
@@ -57,13 +56,15 @@ func registryRegisterNode(svc consensus.Service, id *identity.Identity, p2pAddre
5756
nodeDesc.Runtimes[0].Capabilities = *capabilities
5857
}
5958
if roles&node.RoleValidator != 0 {
60-
if nodeDesc.Consensus.Addresses, err = svc.GetAddresses(); err != nil {
61-
return fmt.Errorf("consensus GetAddresses: %w", err)
59+
addrs, err := svc.GetAddresses()
60+
if err != nil {
61+
return fmt.Errorf("failed to get consensus backend addresses: %w", err)
6262
}
63+
nodeDesc.Consensus.Addresses = addrs
6364
}
6465
signedNode, err := node.MultiSignNode(
6566
[]signature.Signer{
66-
registrationSigner,
67+
id.NodeSigner,
6768
id.P2PSigner,
6869
id.ConsensusSigner,
6970
id.VRFSigner,
@@ -77,7 +78,7 @@ func registryRegisterNode(svc consensus.Service, id *identity.Identity, p2pAddre
7778
}
7879

7980
tx := registry.NewRegisterNodeTx(0, nil, signedNode)
80-
if err := consensus.SignAndSubmitTx(context.Background(), svc, registrationSigner, tx); err != nil {
81+
if err := consensus.SignAndSubmitTx(context.Background(), svc, id.NodeSigner, tx); err != nil {
8182
return fmt.Errorf("consensus RegisterNode tx: %w", err)
8283
}
8384
return nil

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88

99
beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
1010
"github.com/oasisprotocol/oasis-core/go/common/crash"
11+
"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
12+
"github.com/oasisprotocol/oasis-core/go/common/entity"
1113
"github.com/oasisprotocol/oasis-core/go/common/grpc"
1214
"github.com/oasisprotocol/oasis-core/go/common/identity"
1315
"github.com/oasisprotocol/oasis-core/go/common/logging"
16+
"github.com/oasisprotocol/oasis-core/go/common/node"
1417
"github.com/oasisprotocol/oasis-core/go/common/persistent"
1518
"github.com/oasisprotocol/oasis-core/go/common/version"
1619
"github.com/oasisprotocol/oasis-core/go/config"
@@ -72,6 +75,7 @@ type Node struct {
7275

7376
Upgrader upgradeAPI.Backend
7477
Identity *identity.Identity
78+
EntityID *signature.PublicKey
7579
Sentry sentryAPI.Backend
7680

7781
RuntimeRegistry runtimeRegistry.Registry
@@ -190,9 +194,18 @@ func (n *Node) startRuntimeServices(genesisDoc *genesisAPI.Document) error {
190194
}
191195

192196
func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
193-
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+
}
194206

195207
// Initialize runtime provisioner.
208+
var err error
196209
n.Provisioner, err = provisioner.New(n.dataDir, n.commonStore, n.Identity, n.Consensus, genesisDoc)
197210
if err != nil {
198211
return err
@@ -206,9 +219,11 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
206219
n.svcMgr.Register(n.RuntimeRegistry)
207220

208221
// Initialize the common worker.
222+
commonCfg := workerCommon.Config{
223+
TxPool: config.GlobalConfig.Runtime.TxPool,
224+
}
209225
n.CommonWorker, err = workerCommon.New(
210-
n,
211-
n.dataDir,
226+
commonCfg,
212227
n.chainContext,
213228
n.Identity,
214229
n.Consensus,
@@ -226,16 +241,15 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
226241
}
227242
n.svcMgr.Register(n.CommonWorker)
228243

229-
workerCommonCfg := n.CommonWorker.GetConfig()
230-
231244
// Initialize the registration worker.
232245
n.RegistrationWorker, err = workerRegistration.New(
233246
n.Consensus.Beacon(),
234247
n.Consensus.Registry(),
235248
n.Identity,
249+
n.EntityID,
236250
n.Consensus,
237251
n.P2P,
238-
&workerCommonCfg,
252+
sentryAddresses,
239253
n.commonStore,
240254
n, // the delegate to be called on registration shutdown
241255
n.RuntimeRegistry,
@@ -255,7 +269,7 @@ func (n *Node) initRuntimeWorkers(genesisDoc *genesisAPI.Document) error {
255269
n.BeaconWorker, err = workerBeacon.New(
256270
n.Identity,
257271
n.Consensus,
258-
n.RegistrationWorker,
272+
n.EntityID != nil,
259273
)
260274
if err != nil {
261275
return err
@@ -445,6 +459,22 @@ func NewNode() (node *Node, err error) { // nolint: gocyclo
445459
return nil, err
446460
}
447461

462+
// Load the owning node's entity ID.
463+
var entityID *signature.PublicKey
464+
if flags.DebugTestEntity() {
465+
testEntity, _, _ := entity.TestEntity()
466+
entityID = &testEntity.ID
467+
} else {
468+
entityID, err = config.GlobalConfig.Registration.ResolveEntityID()
469+
if err != nil {
470+
return nil, fmt.Errorf("failed to resolve entity ID: %w", err)
471+
}
472+
}
473+
if entityID != nil && !entityID.IsValid() {
474+
return nil, fmt.Errorf("invalid entity ID")
475+
}
476+
node.EntityID = entityID
477+
448478
// Load configured values for all registered crash points.
449479
crash.LoadViperArgValues()
450480

go/worker/beacon/worker.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/oasisprotocol/oasis-core/go/common/identity"
1010
"github.com/oasisprotocol/oasis-core/go/common/logging"
1111
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
12-
"github.com/oasisprotocol/oasis-core/go/worker/registration"
1312
)
1413

1514
const workerName = "worker/beacon"
@@ -60,7 +59,7 @@ func (w *Worker) Name() string {
6059
func New(
6160
identity *identity.Identity,
6261
consensus consensus.Service,
63-
registrationWorker *registration.Worker,
62+
enabled bool,
6463
) (*Worker, error) {
6564
var (
6665
err error
@@ -74,9 +73,8 @@ func New(
7473
}
7574

7675
initLogger := logging.GetLogger(workerName)
77-
if registrationWorker.WillNeverRegister() {
78-
// Some node configurations never register, and that's ok.
79-
initLogger.Info("registration worker disabled, also disabling beacon worker")
76+
if !enabled {
77+
initLogger.Info("beacon worker disabled")
8078
close(w.allQuitCh)
8179
return w, nil
8280
}

go/worker/common/committee/node.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/oasisprotocol/oasis-core/go/common/version"
1616
"github.com/oasisprotocol/oasis-core/go/config"
1717
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
18-
control "github.com/oasisprotocol/oasis-core/go/control/api"
1918
keymanager "github.com/oasisprotocol/oasis-core/go/keymanager/api"
2019
cmmetrics "github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/metrics"
2120
p2pAPI "github.com/oasisprotocol/oasis-core/go/p2p/api"
@@ -56,8 +55,6 @@ type Node struct {
5655
Runtime runtimeRegistry.Runtime
5756
RuntimeRegistry runtimeRegistry.Registry
5857

59-
HostNode control.NodeController
60-
6158
Identity *identity.Identity
6259
KeyManager keymanager.Backend
6360
KeyManagerClient *KeyManagerClientWrapper
@@ -632,7 +629,6 @@ func (n *Node) handleDispatchInfo() {
632629

633630
func NewNode(
634631
chainContext string,
635-
hostNode control.NodeController,
636632
runtime runtimeRegistry.Runtime,
637633
provisioner host.Provisioner,
638634
rtRegistry runtimeRegistry.Registry,
@@ -660,7 +656,6 @@ func NewNode(
660656

661657
n := &Node{
662658
ChainContext: chainContext,
663-
HostNode: hostNode,
664659
Runtime: runtime,
665660
RuntimeRegistry: rtRegistry,
666661
Identity: identity,

go/worker/common/config.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,10 @@
11
package common
22

33
import (
4-
"fmt"
5-
6-
"github.com/oasisprotocol/oasis-core/go/common/logging"
7-
"github.com/oasisprotocol/oasis-core/go/common/node"
8-
"github.com/oasisprotocol/oasis-core/go/config"
94
tpConfig "github.com/oasisprotocol/oasis-core/go/runtime/txpool/config"
105
)
116

127
// Config contains common worker config.
138
type Config struct {
14-
SentryAddresses []node.TLSAddress
15-
169
TxPool tpConfig.Config
17-
18-
logger *logging.Logger
19-
}
20-
21-
// NewConfig creates a new worker config.
22-
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-
33-
cfg := Config{
34-
SentryAddresses: sentryAddresses,
35-
TxPool: config.GlobalConfig.Runtime.TxPool,
36-
logger: logging.GetLogger("worker/config"),
37-
}
38-
39-
return &cfg, nil
4010
}

go/worker/common/worker.go

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package common
22

33
import (
4-
"fmt"
5-
64
"github.com/oasisprotocol/oasis-core/go/common"
75
"github.com/oasisprotocol/oasis-core/go/common/identity"
86
"github.com/oasisprotocol/oasis-core/go/common/logging"
@@ -22,7 +20,6 @@ type Worker struct {
2220
cfg Config
2321

2422
HostNode control.NodeController
25-
DataDir string
2623
ChainContext string
2724
Identity *identity.Identity
2825
Consensus consensus.Service
@@ -131,11 +128,6 @@ func (w *Worker) Initialized() <-chan struct{} {
131128
return w.initCh
132129
}
133130

134-
// GetConfig returns the worker's configuration.
135-
func (w *Worker) GetConfig() Config {
136-
return w.cfg
137-
}
138-
139131
// GetRuntimes returns a map of configured runtimes.
140132
func (w *Worker) GetRuntimes() map[common.Namespace]*committee.Node {
141133
return w.runtimes
@@ -156,7 +148,6 @@ func (w *Worker) registerRuntime(runtime runtimeRegistry.Runtime) error {
156148

157149
node, err := committee.NewNode(
158150
w.ChainContext,
159-
w.HostNode,
160151
runtime,
161152
w.Provisioner,
162153
w.RuntimeRegistry,
@@ -181,8 +172,7 @@ func (w *Worker) registerRuntime(runtime runtimeRegistry.Runtime) error {
181172

182173
// New creates a new worker.
183174
func New(
184-
hostNode control.NodeController,
185-
dataDir string,
175+
cfg Config,
186176
chainContext string,
187177
identity *identity.Identity,
188178
consensus consensus.Service,
@@ -203,16 +193,9 @@ func New(
203193
enabled = true
204194
}
205195

206-
cfg, err := NewConfig()
207-
if err != nil {
208-
return nil, fmt.Errorf("worker/common: failed to initialize config: %w", err)
209-
}
210-
211196
w := &Worker{
212197
enabled: enabled,
213-
cfg: *cfg,
214-
HostNode: hostNode,
215-
DataDir: dataDir,
198+
cfg: cfg,
216199
ChainContext: chainContext,
217200
Identity: identity,
218201
Consensus: consensus,

0 commit comments

Comments
 (0)