Skip to content

Commit 7e1a04b

Browse files
committed
when reading channel config, skip orderer endpoints which are empty strings
Signed-off-by: Arne Rutjes <arne123@gmail.com>
1 parent 55ffb2e commit 7e1a04b

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

docs/core-fabric.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ fabric:
297297

298298
ordering:
299299
# number of retries to attempt to send a transaction to an orderer
300-
# If not specified or set to 0, it will default to 3 retries
300+
# If not specified or set to 0, it will default to 3 retries. The orderer is picked randomly for every attempt.
301301
numRetries: 3
302-
# retryInternal specifies the amount of time to wait before retrying a connection to the ordering service, it has no default and must be specified
303-
retryInterval: 3s
302+
# retryInternal specifies the amount of time to wait before retrying a connection to the ordering service, it defaults to 500ms
303+
retryInterval: 500ms
304304
# here is possible to disable tls just for the ordering service.
305305
# if this key is not specified, then the `tls` section is used.
306306
tlsEnabled: true

platform/fabric/core/generic/committer/committer.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,10 @@ func (c *Committer) applyBundle(bundle *channelconfig.Bundle) error {
867867
tlsRootCerts = append(tlsRootCerts, msp.GetTLSRootCerts()...)
868868
tlsRootCerts = append(tlsRootCerts, msp.GetTLSIntermediateCerts()...)
869869
for _, endpoint := range org.Endpoints() {
870+
if len(endpoint) == 0 {
871+
c.logger.Debugf("[Channel: %s] empty endpoint for %s, skipping", c.ChannelConfig.ID(), org.MSPID())
872+
continue
873+
}
870874
c.logger.Debugf("[Channel: %s] Adding orderer endpoint: [%s:%s:%s]", c.ChannelConfig.ID(), org.Name(), org.MSPID(), endpoint)
871875
newOrderers = append(newOrderers, &grpc.ConnectionConfig{
872876
Address: endpoint,
@@ -877,8 +881,16 @@ func (c *Committer) applyBundle(bundle *channelconfig.Bundle) error {
877881
})
878882
}
879883
// If the Orderer MSP config omits the Endpoints and there is only one orderer org, we try to get the addresses from another key in the channel config.
880-
if len(newOrderers) == 0 && len(orgs) == 1 {
881-
for _, endpoint := range bundle.ChannelConfig().OrdererAddresses() {
884+
// This is only here for backwards compatibility and is deprecated in Fabric 3.
885+
// https://hyperledger-fabric.readthedocs.io/en/latest/upgrade_to_newest_version.html#define-ordering-node-endpoint-per-org
886+
addr := bundle.ChannelConfig().OrdererAddresses()
887+
if len(newOrderers) == 0 && len(orgs) == 1 && len(addr) > 0 {
888+
c.logger.Infof("falling back to OrdererAddresses field in channel config (deprecated, please refer to Fabric docs)")
889+
for _, endpoint := range addr {
890+
if len(endpoint) == 0 {
891+
c.logger.Debugf("[Channel: %s] empty orderer address, skipping", c.ChannelConfig.ID())
892+
continue
893+
}
882894
c.logger.Debugf("[Channel: %s] Adding orderer address [%s:%s:%s]", c.ChannelConfig.ID(), org.Name(), org.MSPID(), endpoint)
883895
newOrderers = append(newOrderers, &grpc.ConnectionConfig{
884896
Address: endpoint,

platform/fabric/core/generic/config/service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
const (
2424
defaultMSPCacheSize = 3
2525
defaultBroadcastNumRetries = 3
26+
defaultBroadcastRetryInterval = 500 * time.Millisecond
2627
vaultPersistenceOptsKey = "vault.persistence.opts"
2728
defaultOrderingConnectionPoolSize = 10
2829
defaultNumRetries = 3
@@ -313,7 +314,10 @@ func (s *Service) BroadcastNumRetries() int {
313314
}
314315

315316
func (s *Service) BroadcastRetryInterval() time.Duration {
316-
return s.GetDuration("ordering.retryInterval")
317+
if s.IsSet("ordering.retryInterval") {
318+
return s.GetDuration("ordering.retryInterval")
319+
}
320+
return defaultBroadcastRetryInterval
317321
}
318322

319323
func (s *Service) OrdererConnectionPoolSize() int {

platform/fabric/core/generic/delivery/delivery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (d *Delivery) Run(ctx context.Context) error {
148148
span.AddEvent("connect")
149149
df, err = d.connect(ctx)
150150
if err != nil {
151-
logger.Errorf("failed connecting to delivery service [%s:%s] [%s]. Wait 10 sec before reconnecting", d.NetworkName, d.channel, err)
151+
logger.Errorf("failed connecting to delivery service [%s:%s] [%s]. Wait %.1fs before reconnecting", d.NetworkName, d.channel, err, waitTime.Seconds())
152152
time.Sleep(waitTime)
153153
if logger.IsEnabledFor(zapcore.DebugLevel) {
154154
logger.Debugf("reconnecting to delivery service [%s:%s]", d.NetworkName, d.channel)

platform/fabric/core/generic/ordering/cft.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (o *CFTBroadcaster) getConnection(ctx context.Context) (*Connection, error)
123123
oClient, err := client.OrdererClient()
124124
if err != nil {
125125
rpcStatus, _ := status.FromError(err)
126-
return nil, errors.Wrapf(err, "failed to new a broadcast, rpcStatus=%+v", rpcStatus)
126+
return nil, errors.Wrapf(err, "failed to new a broadcast for %s, rpcStatus=%+v", to.Address, rpcStatus)
127127
}
128128

129129
stream, err := oClient.Broadcast(ctx)

platform/view/services/grpc/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ func (client *Client) SetServerRootCAs(serverRoots [][]byte) error {
297297
// overrides the server name used to verify the hostname on the
298298
// certificate returned by a server when using TLS
299299
func (client *Client) NewConnection(address string, tlsOptions ...TLSOption) (*grpc.ClientConn, error) {
300+
if len(address) == 0 {
301+
return nil, errors.New("address is empty")
302+
}
300303

301304
var dialOpts []grpc.DialOption
302305
dialOpts = append(dialOpts, client.dialOpts...)

0 commit comments

Comments
 (0)