Skip to content

Commit db404bd

Browse files
committed
Allow peer endpoints to be autodetected
The current code generally specifies a default address of the peer as 0.0.0.0:xxxx (e.g. 0.0.0.0:7051). This works as both the listener binding address and (oddly) as the client connect() address for the cases where the peer is running in certain environments (such as devenv). However, in other environments, 0.0.0.0 is not sufficient for properly connecting to an endpoint. This is a critical operation for chaincode since it will require the formation of a connection to the CORE_PEER_ADDRESS in order to function. Part of the problem is that the unit tests employ custom setup logic which does not flow through the common code for establishing the CORE_PEER_ADDRESS. Therefore, these unit-tests do not respect the ADDRESSAUTODETECT feature and are unable to present a valid endpoint in all circumstances. This will become a problem later in the series when we introduce the notion of running the unit-tests within a dockerized environment. The fix here is to mutate the unit-test setup logic to utilize the library operations that process the ADDRESSAUTODETECT feature. A few cases were not easily adaptable, so they were denoted with a FIXME label and left for a future task. Change-Id: Ib5cffb9847be6c9f4125cde9b108709e95d99e71 Signed-off-by: Greg Haskins <[email protected]>
1 parent 26d78ea commit db404bd

File tree

12 files changed

+30
-11
lines changed

12 files changed

+30
-11
lines changed

core/chaincode/chaincodetest.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ peer:
171171
address: 0.0.0.0:21212
172172
# Whether the Peer should programmatically determine the address to bind to.
173173
# This case is useful for docker containers.
174-
addressAutoDetect: false
174+
addressAutoDetect: true
175175

176176
# Peer port to accept connections on
177177
port: 21212

core/chaincode/exectransaction_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/hyperledger/fabric/core/crypto"
3434
"github.com/hyperledger/fabric/core/ledger"
3535
"github.com/hyperledger/fabric/core/ledger/kvledger"
36+
"github.com/hyperledger/fabric/core/peer"
3637
"github.com/hyperledger/fabric/core/util"
3738
pb "github.com/hyperledger/fabric/protos"
3839
putils "github.com/hyperledger/fabric/protos/utils"
@@ -70,7 +71,10 @@ func initPeer() (net.Listener, error) {
7071

7172
kvledger.Initialize(ledgerPath)
7273

73-
peerAddress := viper.GetString("peer.address")
74+
peerAddress, err := peer.GetLocalAddress()
75+
if err != nil {
76+
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
77+
}
7478
lis, err := net.Listen("tcp", peerAddress)
7579
if err != nil {
7680
return nil, fmt.Errorf("Error starting peer listener %s", err)

core/chaincode/lccc_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func constructDeploymentSpec(name string, path string, initArgs [][]byte) (*pb.C
4747
func initialize() {
4848
//use a different address than what we usually use for "peer"
4949
//we override the peerAddress set in chaincode_support.go
50+
// FIXME: Use peer.GetLocalAddress()
5051
peerAddress := "0.0.0.0:21212"
5152

5253
var opts []grpc.ServerOption

core/chaincode/systemchaincode_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestExecuteDeploySysChaincode(t *testing.T) {
3939

4040
//use a different address than what we usually use for "peer"
4141
//we override the peerAddress set in chaincode_support.go
42+
// FIXME: Use peer.GetLocalAddress()
4243
peerAddress := "0.0.0.0:21726"
4344
lis, err := net.Listen("tcp", peerAddress)
4445
if err != nil {

core/endorser/endorser.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ peer:
180180
address: 0.0.0.0:21212
181181
# Whether the Peer should programmatically determine the address to bind to.
182182
# This case is useful for docker containers.
183-
addressAutoDetect: false
183+
addressAutoDetect: true
184184

185185
# Peer port to accept connections on
186186
port: 21212
@@ -406,13 +406,13 @@ chaincode:
406406
# A value <= 0 turns keepalive off
407407
keepalive: 0
408408

409-
# system chaincodes whitelist. To add system chaincode "myscc" to the
409+
# system chaincodes whitelist. To add system chaincode "myscc" to the
410410
# whitelist, add "myscc: enable" to the list
411411
system:
412412
lccc: enable
413413
escc: enable
414414
vscc: enable
415-
415+
416416
###############################################################################
417417
#
418418
# Ledger section - ledger configuration encompases both the blockchain

core/endorser/endorser_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/hyperledger/fabric/core/crypto"
3232
"github.com/hyperledger/fabric/core/db"
3333
"github.com/hyperledger/fabric/core/ledger/kvledger"
34+
"github.com/hyperledger/fabric/core/peer"
3435
pb "github.com/hyperledger/fabric/protos"
3536
pbutils "github.com/hyperledger/fabric/protos/utils"
3637
"github.com/spf13/viper"
@@ -58,7 +59,10 @@ func initPeer() (net.Listener, error) {
5859

5960
viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))
6061

61-
peerAddress := viper.GetString("peer.address")
62+
peerAddress, err := peer.GetLocalAddress()
63+
if err != nil {
64+
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
65+
}
6266
lis, err := net.Listen("tcp", peerAddress)
6367
if err != nil {
6468
return nil, fmt.Errorf("Error starting peer listener %s", err)

core/rest/rest_test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ peer:
101101
address: 0.0.0.0:7051
102102
# Whether the Peer should programmatically determine the address to bind to.
103103
# This case is useful for docker containers.
104-
addressAutoDetect: false
104+
addressAutoDetect: true
105105

106106
# Setting for runtime.GOMAXPROCS(n). If n < 1, it does not change the current setting
107107
gomaxprocs: -1

examples/chaincode/go/asset_management02/asset.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ peer:
214214
address: 0.0.0.0:40404
215215
# Whether the Peer should programmatically determine the address to bind to.
216216
# This case is useful for docker containers.
217-
addressAutoDetect: false
217+
addressAutoDetect: true
218218

219219
# Peer port to accept connections on
220220
port: 40404

examples/chaincode/go/asset_management02/asset_management02_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/hyperledger/fabric/core/crypto"
3535
"github.com/hyperledger/fabric/core/db"
3636
"github.com/hyperledger/fabric/core/ledger"
37+
"github.com/hyperledger/fabric/core/peer"
3738
"github.com/hyperledger/fabric/core/util"
3839
"github.com/hyperledger/fabric/membersrvc/ca"
3940
pb "github.com/hyperledger/fabric/protos"
@@ -585,7 +586,10 @@ func initVP() {
585586

586587
//use a different address than what we usually use for "peer"
587588
//we override the peerAddress set in chaincode_support.go
588-
peerAddress := "0.0.0.0:40404"
589+
peerAddress, err := peer.GetLocalAddress()
590+
if err != nil {
591+
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
592+
}
589593
var err error
590594
lis, err = net.Listen("tcp", peerAddress)
591595
if err != nil {

examples/chaincode/go/asset_management_with_roles/asset.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ peer:
192192
address: 0.0.0.0:40404
193193
# Whether the Peer should programmatically determine the address to bind to.
194194
# This case is useful for docker containers.
195-
addressAutoDetect: false
195+
addressAutoDetect: true
196196

197197
# Peer port to accept connections on
198198
port: 40404

examples/chaincode/go/asset_management_with_roles/asset_management_with_roles_test.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/hyperledger/fabric/core/crypto"
3434
"github.com/hyperledger/fabric/core/db"
3535
"github.com/hyperledger/fabric/core/ledger"
36+
"github.com/hyperledger/fabric/core/peer"
3637
"github.com/hyperledger/fabric/core/util"
3738
"github.com/hyperledger/fabric/membersrvc/ca"
3839
pb "github.com/hyperledger/fabric/protos"
@@ -420,7 +421,10 @@ func initVP() {
420421

421422
//use a different address than what we usually use for "peer"
422423
//we override the peerAddress set in chaincode_support.go
423-
peerAddress := "0.0.0.0:40404"
424+
peerAddress, err := peer.GetLocalAddress()
425+
if err != nil {
426+
return nil, fmt.Errorf("Error obtaining peer address: %s", err)
427+
}
424428
var err error
425429
lis, err = net.Listen("tcp", peerAddress)
426430
if err != nil {

examples/chaincode/go/rbac_tcerts_no_attrs/rbac_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ func initVP() {
490490

491491
//use a different address than what we usually use for "peer"
492492
//we override the peerAddress set in chaincode_support.go
493+
// FIXME: Use peer.GetLocalAddress()
493494
peerAddress := "0.0.0.0:40404"
494495
var err error
495496
lis, err = net.Listen("tcp", peerAddress)

0 commit comments

Comments
 (0)