Skip to content

Commit

Permalink
fix GetOrdererEndpointOfChain
Browse files Browse the repository at this point in the history
Signed-off-by: Yoav Tock <[email protected]>
  • Loading branch information
tock-ibm committed May 13, 2024
1 parent b0f238b commit 1b22af9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions common/channelconfig/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion internal/peer/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion internal/peer/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/peer/lifecycle/chaincode/client_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 1b22af9

Please sign in to comment.