diff --git a/examples/ccchecker/ccchecker.go b/examples/ccchecker/ccchecker.go index 66bb9778993..9f93330ad93 100644 --- a/examples/ccchecker/ccchecker.go +++ b/examples/ccchecker/ccchecker.go @@ -90,9 +90,9 @@ func CCCheckerInit() { } //CCCheckerRun main loops that will run the tests and cleanup -func CCCheckerRun(report bool, verbose bool) error { +func CCCheckerRun(orderingEndpoint string, report bool, verbose bool) error { //connect with Broadcast client - bc, err := common.GetBroadcastClient() + bc, err := common.GetBroadcastClient(orderingEndpoint) if err != nil { return err } diff --git a/examples/ccchecker/main.go b/examples/ccchecker/main.go index 138d5f3b75f..f34fdc84500 100644 --- a/examples/ccchecker/main.go +++ b/examples/ccchecker/main.go @@ -40,9 +40,11 @@ var mainCmd = &cobra.Command{ }, } +var orderingEndpoint string + func main() { mainFlags := mainCmd.PersistentFlags() - + mainFlags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint") //initialize the env InitCCCheckerEnv(mainFlags) @@ -56,7 +58,7 @@ func main() { func run(args []string) { CCCheckerInit() //TODO make parameters out of report and verbose - CCCheckerRun(true, true) + CCCheckerRun(orderingEndpoint, true, true) fmt.Printf("Test complete\n") return } diff --git a/peer/chaincode/chaincode.go b/peer/chaincode/chaincode.go index 36d1e0641cc..cf0381d4c22 100644 --- a/peer/chaincode/chaincode.go +++ b/peer/chaincode/chaincode.go @@ -56,6 +56,7 @@ func AddFlags(cmd *cobra.Command) { fmt.Sprint("The name of the endorsement system chaincode to be used for this chaincode")) flags.StringVarP(&vscc, "vscc", "V", common.UndefinedParamValue, fmt.Sprint("The name of the verification system chaincode to be used for this chaincode")) + flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint") } // Cmd returns the cobra command for Chaincode @@ -88,6 +89,7 @@ var ( escc string vscc string policyMarhsalled []byte + orderingEndpoint string ) var chaincodeCmd = &cobra.Command{ diff --git a/peer/chaincode/common.go b/peer/chaincode/common.go index fd46508e3b3..9e1b192b64d 100644 --- a/peer/chaincode/common.go +++ b/peer/chaincode/common.go @@ -229,7 +229,7 @@ func InitCmdFactory() (*ChaincodeCmdFactory, error) { return nil, fmt.Errorf("Error getting default signer: %s", err) } - broadcastClient, err := common.GetBroadcastClient() + broadcastClient, err := common.GetBroadcastClient(orderingEndpoint) if err != nil { return nil, fmt.Errorf("Error getting broadcast client: %s", err) } diff --git a/peer/channel/channel.go b/peer/channel/channel.go index f998c236fd5..78ad05950cf 100644 --- a/peer/channel/channel.go +++ b/peer/channel/channel.go @@ -18,6 +18,7 @@ package channel import ( "fmt" + "strings" "github.com/hyperledger/fabric/msp" "github.com/hyperledger/fabric/peer/common" @@ -25,7 +26,6 @@ import ( pb "github.com/hyperledger/fabric/protos/peer" "github.com/op/go-logging" "github.com/spf13/cobra" - "github.com/spf13/viper" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -39,17 +39,13 @@ var ( genesisBlockPath string // create related variables - chainID string - channelTxFile string + chainID string + channelTxFile string + orderingEndpoint string ) // Cmd returns the cobra command for Node func Cmd(cf *ChannelCmdFactory) *cobra.Command { - //the "peer.committer.enabled" flag should really go away... - //basically we need the orderer for create and join - if !viper.GetBool("peer.committer.enabled") || viper.GetString("peer.committer.ledger.orderer") == "" { - panic("orderer not provided") - } AddFlags(channelCmd) channelCmd.AddCommand(joinCmd(cf)) @@ -66,6 +62,7 @@ func AddFlags(cmd *cobra.Command) { flags.StringVarP(&genesisBlockPath, "blockpath", "b", common.UndefinedParamValue, "Path to file containing genesis block") flags.StringVarP(&chainID, "chain", "c", common.UndefinedParamValue, "In case of a newChain command, the chain ID to create.") flags.StringVarP(&channelTxFile, "file", "f", "", "Configuration transaction file generated by a tool such as configtxgen for submitting to orderer") + flags.StringVarP(&orderingEndpoint, "orderer", "o", "", "Ordering service endpoint") } var channelCmd = &cobra.Command{ @@ -97,7 +94,7 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) { } cmdFact.BroadcastFactory = func() (common.BroadcastClient, error) { - return common.GetBroadcastClient() + return common.GetBroadcastClient(orderingEndpoint) } if err != nil { @@ -111,8 +108,12 @@ func InitCmdFactory(isOrdererRequired bool) (*ChannelCmdFactory, error) { return nil, fmt.Errorf("Error getting endorser client %s: %s", channelFuncName, err) } } else { - orderer := viper.GetString("peer.committer.ledger.orderer") - conn, err := grpc.Dial(orderer, grpc.WithInsecure()) + + if len(strings.Split(orderingEndpoint, ":")) != 2 { + return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint) + } + + conn, err := grpc.Dial(orderingEndpoint, grpc.WithInsecure()) if err != nil { return nil, err } diff --git a/peer/channel/create_test.go b/peer/channel/create_test.go index 90e5f5f1de0..aec313103e3 100644 --- a/peer/channel/create_test.go +++ b/peer/channel/create_test.go @@ -26,6 +26,8 @@ import ( "github.com/golang/protobuf/proto" + "errors" + "github.com/hyperledger/fabric/msp/mgmt/testtools" "github.com/hyperledger/fabric/peer/common" cb "github.com/hyperledger/fabric/protos/common" @@ -103,7 +105,7 @@ func TestCreateChain(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchain} + args := []string{"-c", mockchain, "-o", "localhost:7050"} cmd.SetArgs(args) if err := cmd.Execute(); err != nil { @@ -134,7 +136,7 @@ func TestCreateChainWithDefaultAnchorPeers(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchain} + args := []string{"-c", mockchain, "-o", "localhost:7050"} cmd.SetArgs(args) if err := cmd.Execute(); err != nil { @@ -155,7 +157,7 @@ func TestCreateChainBCFail(t *testing.T) { t.Fatalf("Get default signer error: %v", err) } - sendErr := fmt.Errorf("send create tx failed") + sendErr := errors.New("send create tx failed") mockCF := &ChannelCmdFactory{ BroadcastFactory: func() (common.BroadcastClient, error) { @@ -169,7 +171,7 @@ func TestCreateChainBCFail(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchain} + args := []string{"-c", mockchain, "-o", "localhost:7050"} cmd.SetArgs(args) expectedErrMsg := sendErr.Error() @@ -206,7 +208,7 @@ func TestCreateChainDeliverFail(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchain} + args := []string{"-c", mockchain, "-o", "localhost:7050"} cmd.SetArgs(args) expectedErrMsg := recvErr.Error() @@ -277,7 +279,7 @@ func TestCreateChainFromTx(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchannel, "-f", file} + args := []string{"-c", mockchannel, "-f", file, "-o", "localhost:7050"} cmd.SetArgs(args) if _, err = createTxFile(file, cb.HeaderType_CONFIG_UPDATE, mockchannel); err != nil { @@ -321,7 +323,7 @@ func TestCreateChainInvalidTx(t *testing.T) { AddFlags(cmd) - args := []string{"-c", mockchannel, "-f", file} + args := []string{"-c", mockchannel, "-f", file, "-o", "localhost:7050"} cmd.SetArgs(args) //bad type CONFIG diff --git a/peer/common/ordererclient.go b/peer/common/ordererclient.go index 829e041f4b8..0cbd8132cde 100644 --- a/peer/common/ordererclient.go +++ b/peer/common/ordererclient.go @@ -18,11 +18,11 @@ package common import ( "fmt" + "strings" "time" cb "github.com/hyperledger/fabric/protos/common" ab "github.com/hyperledger/fabric/protos/orderer" - "github.com/spf13/viper" "golang.org/x/net/context" "google.golang.org/grpc" ) @@ -39,14 +39,10 @@ type broadcastClient struct { } // GetBroadcastClient creates a simple instance of the BroadcastClient interface -func GetBroadcastClient() (BroadcastClient, error) { - var orderer string - if viper.GetBool("peer.committer.enabled") { - orderer = viper.GetString("peer.committer.ledger.orderer") - } +func GetBroadcastClient(orderingEndpoint string) (BroadcastClient, error) { - if orderer == "" { - return nil, fmt.Errorf("Can't get orderer address") + if len(strings.Split(orderingEndpoint, ":")) != 2 { + return nil, fmt.Errorf("Ordering service endpoint %s is not valid or missing", orderingEndpoint) } var opts []grpc.DialOption @@ -54,14 +50,14 @@ func GetBroadcastClient() (BroadcastClient, error) { opts = append(opts, grpc.WithTimeout(3*time.Second)) opts = append(opts, grpc.WithBlock()) - conn, err := grpc.Dial(orderer, opts...) + conn, err := grpc.Dial(orderingEndpoint, opts...) if err != nil { - return nil, fmt.Errorf("Error connecting to %s due to %s", orderer, err) + return nil, fmt.Errorf("Error connecting to %s due to %s", orderingEndpoint, err) } client, err := ab.NewAtomicBroadcastClient(conn).Broadcast(context.TODO()) if err != nil { conn.Close() - return nil, fmt.Errorf("Error connecting to %s due to %s", orderer, err) + return nil, fmt.Errorf("Error connecting to %s due to %s", orderingEndpoint, err) } return &broadcastClient{conn: conn, client: client}, nil