From 1b22af94dfec510dc5600fc1ccdce9fae10fa1b9 Mon Sep 17 00:00:00 2001 From: Yoav Tock Date: Mon, 13 May 2024 18:16:06 +0300 Subject: [PATCH] fix GetOrdererEndpointOfChain Signed-off-by: Yoav Tock --- common/channelconfig/api.go | 1 + internal/peer/chaincode/common.go | 4 +++- internal/peer/common/common.go | 18 +++++++++++++++++- .../lifecycle/chaincode/client_connections.go | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/common/channelconfig/api.go b/common/channelconfig/api.go index a074ff1cddc..883c60100f9 100644 --- a/common/channelconfig/api.go +++ b/common/channelconfig/api.go @@ -68,6 +68,7 @@ type Channel interface { BlockDataHashingStructureWidth() uint32 // OrdererAddresses returns the list of valid orderer addresses to connect to invoke Broadcast/Deliver + // Deprecated OrdererAddresses() []string // Capabilities defines the capabilities for a channel diff --git a/internal/peer/chaincode/common.go b/internal/peer/chaincode/common.go index a43efe42c7e..7755e9243e8 100644 --- a/internal/peer/chaincode/common.go +++ b/internal/peer/chaincode/common.go @@ -366,6 +366,8 @@ type ChaincodeCmdFactory struct { // InitCmdFactory init the ChaincodeCmdFactory with default clients func InitCmdFactory(cmdName string, isEndorserRequired, isOrdererRequired bool, cryptoProvider bccsp.BCCSP) (*ChaincodeCmdFactory, error) { + logger.Infof("InitCmdFactory: Entry: %s, %t, %t", cmdName, isEndorserRequired, isOrdererRequired) + var err error var endorserClients []pb.EndorserClient var deliverClients []pb.DeliverClient @@ -416,7 +418,7 @@ func InitCmdFactory(cmdName string, isEndorserRequired, isOrdererRequired bool, return nil, errors.WithMessagef(err, "error getting channel (%s) orderer endpoint", channelID) } if len(orderingEndpoints) == 0 { - return nil, errors.Errorf("no orderer endpoints retrieved for channel %s, pass orderer endpoint with -o flag instead", channelID) + return nil, errors.Errorf("InitCmdFactory: no orderer endpoints retrieved for channel %s, pass orderer endpoint with -o flag instead", channelID) } logger.Infof("Retrieved channel (%s) orderer endpoint: %s", channelID, orderingEndpoints[0]) // override viper env diff --git a/internal/peer/common/common.go b/internal/peer/common/common.go index c3126034985..e431477ab76 100644 --- a/internal/peer/common/common.go +++ b/internal/peer/common/common.go @@ -280,7 +280,23 @@ func GetOrdererEndpointOfChain(chainID string, signer Signer, endorserClient pb. return nil, errors.WithMessage(err, "error loading channel config") } - return bundle.ChannelConfig().OrdererAddresses(), nil + ordererAddresses := bundle.ChannelConfig().OrdererAddresses() + if len(ordererAddresses) > 0 { + logger.Warningf("Deprecated global OrdererAddresses exist: %v; ignoring", ordererAddresses) + } + + ordererConfig, ok := bundle.OrdererConfig() + if !ok { + return nil, errors.New("missing OrdererConfig in channel config") + } + + var orgAddresses []string + for orgName, org := range ordererConfig.Organizations() { + logger.Debugf("Adding endpoints of org `%s`: %v", orgName, org.Endpoints()) + orgAddresses = append(orgAddresses, org.Endpoints()...) + } + + return orgAddresses, nil } // CheckLogLevel checks that a given log level string is valid diff --git a/internal/peer/lifecycle/chaincode/client_connections.go b/internal/peer/lifecycle/chaincode/client_connections.go index 2945a7a87d9..92e279fca95 100644 --- a/internal/peer/lifecycle/chaincode/client_connections.go +++ b/internal/peer/lifecycle/chaincode/client_connections.go @@ -214,7 +214,7 @@ func (c *ClientConnections) setOrdererClient() error { return errors.WithMessagef(err, "error getting channel (%s) orderer endpoint", channelID) } if len(orderingEndpoints) == 0 { - return errors.Errorf("no orderer endpoints retrieved for channel %s, pass orderer endpoint with -o flag instead", channelID) + return errors.Errorf("ClientConnections: no orderer endpoints retrieved for channel %s, pass orderer endpoint with -o flag instead", channelID) } logger.Infof("Retrieved channel (%s) orderer endpoint: %s", channelID, orderingEndpoints[0])