Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when reading channel config, skip orderer endpoints which are empty #715

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/core-fabric.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ fabric:

ordering:
# number of retries to attempt to send a transaction to an orderer
# If not specified or set to 0, it will default to 3 retries
# If not specified or set to 0, it will default to 3 retries. The orderer is picked randomly for every attempt.
numRetries: 3
# retryInternal specifies the amount of time to wait before retrying a connection to the ordering service, it has no default and must be specified
retryInterval: 3s
# retryInternal specifies the amount of time to wait before retrying a connection to the ordering service, it defaults to 500ms
retryInterval: 500ms
# here is possible to disable tls just for the ordering service.
# if this key is not specified, then the `tls` section is used.
tlsEnabled: true
Expand Down
16 changes: 14 additions & 2 deletions platform/fabric/core/generic/committer/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,10 @@ func (c *Committer) applyBundle(bundle *channelconfig.Bundle) error {
tlsRootCerts = append(tlsRootCerts, msp.GetTLSRootCerts()...)
tlsRootCerts = append(tlsRootCerts, msp.GetTLSIntermediateCerts()...)
for _, endpoint := range org.Endpoints() {
if len(endpoint) == 0 {
c.logger.Debugf("[Channel: %s] empty endpoint for %s, skipping", c.ChannelConfig.ID(), org.MSPID())
continue
}
c.logger.Debugf("[Channel: %s] Adding orderer endpoint: [%s:%s:%s]", c.ChannelConfig.ID(), org.Name(), org.MSPID(), endpoint)
newOrderers = append(newOrderers, &grpc.ConnectionConfig{
Address: endpoint,
Expand All @@ -877,8 +881,16 @@ func (c *Committer) applyBundle(bundle *channelconfig.Bundle) error {
})
}
// 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.
if len(newOrderers) == 0 && len(orgs) == 1 {
for _, endpoint := range bundle.ChannelConfig().OrdererAddresses() {
// This is only here for backwards compatibility and is deprecated in Fabric 3.
// https://hyperledger-fabric.readthedocs.io/en/latest/upgrade_to_newest_version.html#define-ordering-node-endpoint-per-org
addr := bundle.ChannelConfig().OrdererAddresses()
if len(newOrderers) == 0 && len(orgs) == 1 && len(addr) > 0 {
c.logger.Infof("falling back to OrdererAddresses field in channel config (deprecated, please refer to Fabric docs)")
for _, endpoint := range addr {
if len(endpoint) == 0 {
c.logger.Debugf("[Channel: %s] empty orderer address, skipping", c.ChannelConfig.ID())
continue
}
c.logger.Debugf("[Channel: %s] Adding orderer address [%s:%s:%s]", c.ChannelConfig.ID(), org.Name(), org.MSPID(), endpoint)
newOrderers = append(newOrderers, &grpc.ConnectionConfig{
Address: endpoint,
Expand Down
6 changes: 5 additions & 1 deletion platform/fabric/core/generic/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
const (
defaultMSPCacheSize = 3
defaultBroadcastNumRetries = 3
defaultBroadcastRetryInterval = 500 * time.Millisecond
vaultPersistenceOptsKey = "vault.persistence.opts"
defaultOrderingConnectionPoolSize = 10
defaultNumRetries = 3
Expand Down Expand Up @@ -313,7 +314,10 @@ func (s *Service) BroadcastNumRetries() int {
}

func (s *Service) BroadcastRetryInterval() time.Duration {
return s.GetDuration("ordering.retryInterval")
if s.IsSet("ordering.retryInterval") {
return s.GetDuration("ordering.retryInterval")
}
return defaultBroadcastRetryInterval
}

func (s *Service) OrdererConnectionPoolSize() int {
Expand Down
2 changes: 1 addition & 1 deletion platform/fabric/core/generic/delivery/delivery.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (d *Delivery) Run(ctx context.Context) error {
span.AddEvent("connect")
df, err = d.connect(ctx)
if err != nil {
logger.Errorf("failed connecting to delivery service [%s:%s] [%s]. Wait 10 sec before reconnecting", d.NetworkName, d.channel, err)
logger.Errorf("failed connecting to delivery service [%s:%s] [%s]. Wait %.1fs before reconnecting", d.NetworkName, d.channel, err, waitTime.Seconds())
time.Sleep(waitTime)
if logger.IsEnabledFor(zapcore.DebugLevel) {
logger.Debugf("reconnecting to delivery service [%s:%s]", d.NetworkName, d.channel)
Expand Down
2 changes: 1 addition & 1 deletion platform/fabric/core/generic/ordering/cft.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (o *CFTBroadcaster) getConnection(ctx context.Context) (*Connection, error)
oClient, err := client.OrdererClient()
if err != nil {
rpcStatus, _ := status.FromError(err)
return nil, errors.Wrapf(err, "failed to new a broadcast, rpcStatus=%+v", rpcStatus)
return nil, errors.Wrapf(err, "failed to new a broadcast for %s, rpcStatus=%+v", to.Address, rpcStatus)
}

stream, err := oClient.Broadcast(ctx)
Expand Down
3 changes: 3 additions & 0 deletions platform/view/services/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ func (client *Client) SetServerRootCAs(serverRoots [][]byte) error {
// overrides the server name used to verify the hostname on the
// certificate returned by a server when using TLS
func (client *Client) NewConnection(address string, tlsOptions ...TLSOption) (*grpc.ClientConn, error) {
if len(address) == 0 {
return nil, errors.New("address is empty")
}

var dialOpts []grpc.DialOption
dialOpts = append(dialOpts, client.dialOpts...)
Expand Down
Loading