Skip to content

Commit 681e5f5

Browse files
committed
* Function renaming and code cleaning.
1 parent c1d4f5a commit 681e5f5

5 files changed

Lines changed: 32 additions & 37 deletions

File tree

cmd/config/templates/coordinator.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ validator-committer:
4848
- {{ . }}
4949
{{- end }}
5050

51-
5251
dependency-graph:
5352
num-of-local-dep-constructors: 1
5453
waiting-txs-limit: 10_000

integration/runner/runtime.go

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -191,41 +191,41 @@ func NewRuntime(t *testing.T, conf *Config) *CommitterRuntime {
191191
c.TLSManager = tlsgen.NewSecureCommunicationManager(t)
192192

193193
t.Log("create clients certificates per service")
194-
s.ClientsCreds.Vc = c.createClientCerts(t, "validator-committer")
195-
s.ClientsCreds.Verifier = c.createClientCerts(t, "verifier")
196-
s.ClientsCreds.Coordinator = c.createClientCerts(t, "coordinator")
197-
s.ClientsCreds.Query = c.createClientCerts(t, "query-service")
198-
s.ClientsCreds.Sidecar = c.createClientCerts(t, "sidecar")
194+
s.ClientsCreds.Vc = c.createClientConfigTLS(t, "validator-committer")
195+
s.ClientsCreds.Verifier = c.createClientConfigTLS(t, "verifier")
196+
s.ClientsCreds.Coordinator = c.createClientConfigTLS(t, "coordinator")
197+
s.ClientsCreds.Query = c.createClientConfigTLS(t, "query-service")
198+
s.ClientsCreds.Sidecar = c.createClientConfigTLS(t, "sidecar")
199199

200200
t.Log("Create processes")
201201
c.MockOrderer = newProcess(t, cmdOrderer, s.WithEndpoint(s.Endpoints.Orderer[0]))
202202
for i, e := range s.Endpoints.Verifier {
203203
p := cmdVerifier
204204
p.Name = fmt.Sprintf("%s-%d", p.Name, i)
205205
c.Verifier = append(c.Verifier, newProcess(
206-
t, p, c.createServerCerts(t, e, "verifier")))
206+
t, p, c.createSystemConfigWithServerCerts(t, e, "verifier")))
207207
}
208208

209209
for i, e := range s.Endpoints.VCService {
210210
p := cmdVC
211211
p.Name = fmt.Sprintf("%s-%d", p.Name, i)
212212
c.VcService = append(c.VcService, newProcess(
213-
t, p, c.createServerCerts(t, e, "validator-committer")))
213+
t, p, c.createSystemConfigWithServerCerts(t, e, "validator-committer")))
214214
}
215215

216216
c.Coordinator = newProcess(t,
217217
cmdCoordinator,
218-
c.createServerCerts(t, s.Endpoints.Coordinator, "coordinator"),
218+
c.createSystemConfigWithServerCerts(t, s.Endpoints.Coordinator, "coordinator"),
219219
)
220220

221221
c.QueryService = newProcess(t,
222222
cmdQuery,
223-
c.createServerCerts(t, s.Endpoints.Query, "query-service"),
223+
c.createSystemConfigWithServerCerts(t, s.Endpoints.Query, "query-service"),
224224
)
225225

226226
c.Sidecar = newProcess(t,
227227
cmdSidecar,
228-
c.createServerCerts(t, s.Endpoints.Sidecar, "sidecar"),
228+
c.createSystemConfigWithServerCerts(t, s.Endpoints.Sidecar, "sidecar"),
229229
)
230230

231231
t.Log("Create clients")
@@ -638,25 +638,34 @@ func (c *CommitterRuntime) ensureAtLeastLastCommittedBlockNumber(t *testing.T, b
638638
}, 2*time.Minute, 250*time.Millisecond)
639639
}
640640

641-
func (c *CommitterRuntime) createServerCerts(
641+
func (c *CommitterRuntime) createSystemConfigWithServerCerts(
642642
t *testing.T,
643643
endpoints config.ServiceEndpoints,
644644
serverName string,
645645
) *config.SystemConfig {
646646
t.Helper()
647647
serviceCfg := c.SystemConfig
648-
serviceTLSCertsPath := c.TLSManager.CreateServerCertificate(t, serverName)
649-
serviceCfg.ServiceTLS = c.createTLSConfig(serviceTLSCertsPath, serverName)
648+
serviceCfg.ServiceTLS = c.createServerConfigTLS(t, serverName)
650649
serviceCfg.ServiceEndpoints = endpoints
651650
return &serviceCfg
652651
}
653652

654-
func (c *CommitterRuntime) createClientCerts(t *testing.T, forServer string) connection.ConfigTLS {
653+
func (c *CommitterRuntime) createServerConfigTLS(t *testing.T, asServer string) connection.ConfigTLS {
655654
t.Helper()
656-
return c.createTLSConfig(c.TLSManager.CreateClientCertificate(t), forServer)
655+
// We pass asServer twice: first to generate the server's keys,
656+
// and second to include the server name in the ConfigTLS.
657+
// Note: the Server Name Indication (SNI) is not used when creating
658+
// the server's transport credentials, so passing it during TLS config
659+
// creation is not strictly necessary.
660+
return c.createConfigTLS(c.TLSManager.CreateServerCertificate(t, asServer), asServer)
657661
}
658662

659-
func (c *CommitterRuntime) createTLSConfig(paths map[string]string, serverName string) connection.ConfigTLS {
663+
func (c *CommitterRuntime) createClientConfigTLS(t *testing.T, forServer string) connection.ConfigTLS {
664+
t.Helper()
665+
return c.createConfigTLS(c.TLSManager.CreateClientCertificate(t), forServer)
666+
}
667+
668+
func (c *CommitterRuntime) createConfigTLS(paths map[string]string, serverName string) connection.ConfigTLS {
660669
return test.CreateTLSConfigFromPaths(c.config.TLS, paths, serverName)
661670
}
662671

service/coordinator/coordinator_test.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,8 @@ func newCoordinatorTestEnv(t *testing.T, tConfig *testConfig) *coordinatorTestEn
128128

129129
func (e *coordinatorTestEnv) start(ctx context.Context, t *testing.T) {
130130
t.Helper()
131-
cs := e.coordinator
132-
sc := &connection.ServerConfig{
133-
Endpoint: connection.Endpoint{
134-
Host: "localhost",
135-
Port: 0,
136-
},
137-
}
138-
test.RunServiceAndGrpcForTest(ctx, t, cs, sc, func(server *grpc.Server) {
139-
protocoordinatorservice.RegisterCoordinatorServer(server, cs)
140-
})
141-
142-
e.client = createCoordinatorClientWithTLS(t, &sc.Endpoint, nil)
131+
e.startWithCreds(ctx, t, nil)
132+
e.client = createCoordinatorClientWithTLS(t, &e.coordinator.config.Server.Endpoint, nil)
143133

144134
sCtx, sCancel := context.WithTimeout(ctx, 5*time.Minute)
145135
t.Cleanup(sCancel)

service/sidecar/sidecar.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,23 @@ func (s *Service) Run(ctx context.Context) error {
9494
_ = s.metrics.StartPrometheusServer(pCtx, s.config.Monitoring.Server, s.monitorQueues)
9595
}()
9696

97-
logger.Infof("Create coordinator client and connect to %s", connection.AddressString(
98-
s.config.Committer.Config.Endpoints...),
99-
)
97+
coordinatorEndpoints := connection.AddressString(s.config.Committer.Config.Endpoints...)
98+
logger.Infof("Create coordinator client and connect to %s", coordinatorEndpoints)
10099

101100
committerDialConfig, err := connection.NewLoadBalancedDialConfig(s.config.Committer.Config)
102101
if err != nil {
103102
return errors.Wrapf(err, "could not load coordinator dial config")
104103
}
104+
105105
// connecting to the coordinator.
106106
conn, connErr := connection.Connect(committerDialConfig)
107107
if connErr != nil {
108-
return errors.Wrapf(err, "failed to connect to coordinator")
108+
return errors.Wrapf(connErr, "failed to connect to coordinator")
109109
}
110110
s.coordConn = conn
111111
defer connection.CloseConnectionsLog(conn)
112+
logger.Infof("sidecar connected to coordinator at %s", coordinatorEndpoints)
112113

113-
logger.Infof("sidecar connected to coordinator at %s", connection.AddressString(
114-
s.config.Committer.Config.Endpoints...),
115-
)
116114
// creating coordinator client.
117115
coordClient := protocoordinatorservice.NewCoordinatorClient(conn)
118116

utils/test/secure_connection.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func RunSecureConnectionTest(
4646
secureConnArguments SecureConnectionFunctionArguments,
4747
) {
4848
t.Helper()
49-
5049
tlsMgr := tlsgen.NewSecureCommunicationManager(t)
5150
serverCreds := tlsMgr.CreateServerCertificate(t, secureConnArguments.ServerCN)
5251
serverTLS := CreateTLSConfigFromPaths(connection.TLSMutual, serverCreds, "")

0 commit comments

Comments
 (0)