Skip to content

Commit 562a35f

Browse files
christo4ferrisGerrit Code Review
authored andcommitted
Merge "Fix FAB-578" into v0.6
2 parents 4a78b41 + a96b9ed commit 562a35f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1644
-2641
lines changed

.baseimage-release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ go-carpet-coverage*
2626
# make node-sdk copied files
2727
sdk/node/lib/protos/*
2828
report.xml
29+
.settings
30+
.project
31+
.gradle
32+
build/
33+
bin/

Makefile

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# - dist-clean - superset of 'clean' that also removes persistent state
3838

3939
PROJECT_NAME = hyperledger/fabric
40-
BASE_VERSION = 0.6.1-preview
40+
BASE_VERSION = 0.7.0
4141
IS_RELEASE = false
4242

4343
ifneq ($(IS_RELEASE),true)
@@ -47,13 +47,16 @@ else
4747
PROJECT_VERSION=$(BASE_VERSION)
4848
endif
4949

50-
DOCKER_TAG=$(shell uname -m)-$(PROJECT_VERSION)
51-
5250
PKGNAME = github.com/$(PROJECT_NAME)
5351
GO_LDFLAGS = -X github.com/hyperledger/fabric/metadata.Version=$(PROJECT_VERSION)
5452
CGO_FLAGS = CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy"
5553
UID = $(shell id -u)
54+
ARCH=$(shell uname -m)
5655
CHAINTOOL_RELEASE=v0.9.1
56+
BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)
57+
58+
DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
59+
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)
5760

5861
EXECUTABLES = go docker git curl
5962
K := $(foreach exec,$(EXECUTABLES),\
@@ -63,13 +66,9 @@ K := $(foreach exec,$(EXECUTABLES),\
6366
SUBDIRS = gotools sdk/node
6467
SUBDIRS:=$(strip $(SUBDIRS))
6568

66-
# Make our baseimage depend on any changes to images/base or scripts/provision
67-
BASEIMAGE_RELEASE = $(shell cat ./images/base/release)
68-
BASEIMAGE_DEPS = $(shell git ls-files images/base scripts/provision)
69-
7069
JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
7170
PROJECT_FILES = $(shell git ls-files)
72-
IMAGES = base src ccenv peer membersrvc javaenv
71+
IMAGES = src ccenv peer membersrvc javaenv
7372

7473
all: peer membersrvc checks
7574

@@ -122,14 +121,14 @@ linter: gotools
122121
# we may later inject the binary into a different docker environment
123122
# This is necessary since we cannot guarantee that binaries built
124123
# on the host natively will be compatible with the docker env.
125-
%/bin/protoc-gen-go: build/image/base/.dummy Makefile
124+
%/bin/protoc-gen-go: Makefile
126125
@echo "Building $@"
127126
@mkdir -p $(@D)
128127
@docker run -i \
129128
--user=$(UID) \
130129
-v $(abspath vendor/github.com/golang/protobuf):/opt/gopath/src/github.com/golang/protobuf \
131130
-v $(abspath $(@D)):/opt/gopath/bin \
132-
hyperledger/fabric-baseimage go install github.com/golang/protobuf/protoc-gen-go
131+
hyperledger/fabric-baseimage:$(BASE_DOCKER_TAG) go install github.com/golang/protobuf/protoc-gen-go
133132

134133
build/bin/chaintool: Makefile
135134
@echo "Installing chaintool"
@@ -172,25 +171,19 @@ build/bin/block-listener:
172171
@echo "Binary available as $@"
173172
@touch $@
174173

175-
build/bin/%: build/image/base/.dummy $(PROJECT_FILES)
174+
build/bin/%: $(PROJECT_FILES)
176175
@mkdir -p $(@D)
177176
@echo "$@"
178177
$(CGO_FLAGS) GOBIN=$(abspath $(@D)) go install -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(@F)
179178
@echo "Binary available as $@"
180179
@touch $@
181180

182-
# Special override for base-image.
183-
build/image/base/.dummy: $(BASEIMAGE_DEPS)
184-
@echo "Building docker base-image"
185-
@mkdir -p $(@D)
186-
@./scripts/provision/docker.sh $(BASEIMAGE_RELEASE)
187-
@touch $@
188-
189181
# Special override for src-image
190-
build/image/src/.dummy: build/image/base/.dummy $(PROJECT_FILES)
182+
build/image/src/.dummy: $(PROJECT_FILES)
191183
@echo "Building docker src-image"
192184
@mkdir -p $(@D)
193185
@cat images/src/Dockerfile.in \
186+
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
194187
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
195188
> $(@D)/Dockerfile
196189
@git ls-files | tar -jcT - > $(@D)/gopath.tar.bz2
@@ -202,6 +195,7 @@ build/image/src/.dummy: build/image/base/.dummy $(PROJECT_FILES)
202195
build/image/ccenv/.dummy: build/image/src/.dummy build/image/ccenv/bin/protoc-gen-go build/image/ccenv/bin/chaintool Makefile
203196
@echo "Building docker ccenv-image"
204197
@cat images/ccenv/Dockerfile.in \
198+
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
205199
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
206200
> $(@D)/Dockerfile
207201
docker build -t $(PROJECT_NAME)-ccenv $(@D)
@@ -216,7 +210,10 @@ build/image/ccenv/.dummy: build/image/src/.dummy build/image/ccenv/bin/protoc-ge
216210
build/image/javaenv/.dummy: Makefile $(JAVASHIM_DEPS)
217211
@echo "Building docker javaenv-image"
218212
@mkdir -p $(@D)
219-
@cat images/javaenv/Dockerfile.in > $(@D)/Dockerfile
213+
@cat images/javaenv/Dockerfile.in \
214+
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
215+
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
216+
> $(@D)/Dockerfile
220217
@git ls-files core/chaincode/shim/java | tar -jcT - > $(@D)/javashimsrc.tar.bz2
221218
@git ls-files protos core/chaincode/shim/table.proto settings.gradle | tar -jcT - > $(@D)/protos.tar.bz2
222219
docker build -t $(PROJECT_NAME)-javaenv $(@D)
@@ -229,6 +226,7 @@ build/image/%/.dummy: build/image/src/.dummy build/docker/bin/%
229226
@echo "Building docker $(TARGET)-image"
230227
@mkdir -p $(@D)/bin
231228
@cat images/app/Dockerfile.in \
229+
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
232230
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
233231
> $(@D)/Dockerfile
234232
cp build/docker/bin/$(TARGET) $(@D)/bin
@@ -240,10 +238,6 @@ build/image/%/.dummy: build/image/src/.dummy build/docker/bin/%
240238
protos: gotools
241239
./devenv/compile_protos.sh
242240

243-
base-image-clean:
244-
-docker rmi -f $(PROJECT_NAME)-baseimage
245-
-@rm -rf build/image/base ||:
246-
247241
src-image-clean: ccenv-image-clean peer-image-clean membersrvc-image-clean
248242

249243
%-image-clean:

core/chaincode/chaincode_support.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"time"
2626

2727
"github.com/golang/protobuf/proto"
28+
logging "github.com/op/go-logging"
2829
"github.com/spf13/viper"
2930
"golang.org/x/net/context"
3031

@@ -34,6 +35,7 @@ import (
3435
"github.com/hyperledger/fabric/core/container/ccintf"
3536
"github.com/hyperledger/fabric/core/crypto"
3637
"github.com/hyperledger/fabric/core/ledger"
38+
"github.com/hyperledger/fabric/flogging"
3739
pb "github.com/hyperledger/fabric/protos"
3840
)
3941

@@ -147,6 +149,21 @@ func NewChaincodeSupport(chainname ChainName, getPeerEndpoint func() (*pb.PeerEn
147149
s.keepalive = time.Duration(t) * time.Second
148150
}
149151

152+
viper.SetEnvPrefix("CORE")
153+
viper.AutomaticEnv()
154+
replacer := strings.NewReplacer(".", "_")
155+
viper.SetEnvKeyReplacer(replacer)
156+
157+
chaincodeLogLevelString := viper.GetString("logging.chaincode")
158+
chaincodeLogLevel, err := logging.LogLevel(chaincodeLogLevelString)
159+
160+
if err == nil {
161+
s.chaincodeLogLevel = chaincodeLogLevel.String()
162+
} else {
163+
chaincodeLogger.Infof("chaincode logging level %s is invalid. defaulting to %s\n", chaincodeLogLevelString, flogging.DefaultLoggingLevel().String())
164+
s.chaincodeLogLevel = flogging.DefaultLoggingLevel().String()
165+
}
166+
150167
return s
151168
}
152169

@@ -172,6 +189,7 @@ type ChaincodeSupport struct {
172189
peerTLSKeyFile string
173190
peerTLSSvrHostOrd string
174191
keepalive time.Duration
192+
chaincodeLogLevel string
175193
}
176194

177195
// DuplicateChaincodeHandlerError returned if attempt to register same chaincodeID while a stream already exists.
@@ -290,6 +308,11 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cID *pb.ChaincodeID, cLa
290308
} else {
291309
envs = append(envs, "CORE_PEER_TLS_ENABLED=false")
292310
}
311+
312+
if chaincodeSupport.chaincodeLogLevel != "" {
313+
envs = append(envs, "CORE_LOGGING_CHAINCODE="+chaincodeSupport.chaincodeLogLevel)
314+
}
315+
293316
switch cLang {
294317
case pb.ChaincodeSpec_GOLANG, pb.ChaincodeSpec_CAR:
295318
//chaincode executable will be same as the name of the chaincode

core/chaincode/chaincodetest.yaml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,6 @@ peer:
165165
# networkId: test
166166
networkId: dev
167167

168-
Dockerfile: |
169-
from hyperledger/fabric-baseimage:latest
170-
# Copy GOPATH src and install Peer
171-
COPY src $GOPATH/src
172-
RUN mkdir -p /var/hyperledger/db
173-
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/peer/
174-
RUN CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install && cp $GOPATH/src/github.com/hyperledger/fabric/peer/core.yaml $GOPATH/bin
175-
176-
177168
# The Address this Peer will listen on
178169
listenAddress: 0.0.0.0:21212
179170
# The Address this Peer will bind to for providing services
@@ -363,17 +354,16 @@ chaincode:
363354
# This is the basis for the Golang Dockerfile. Additional commands will
364355
# be appended depedendent upon the chaincode specification.
365356
Dockerfile: |
366-
from hyperledger/fabric-baseimage
367-
#from utxo:0.1.0
368-
COPY src $GOPATH/src
369-
WORKDIR $GOPATH
357+
FROM hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
358+
COPY src $GOPATH/src
359+
WORKDIR $GOPATH
370360
371361
car:
372362

373363
# This is the basis for the CAR Dockerfile. Additional commands will
374364
# be appended depedendent upon the chaincode specification.
375365
Dockerfile: |
376-
FROM hyperledger/fabric-baseimage
366+
FROM hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
377367
378368
# timeout in millisecs for starting up a container and waiting for Register
379369
# to come through. 1sec should be plenty for chaincode unit tests

core/chaincode/exectransaction_test.go

Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,18 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
827827

828828
go grpcServer.Serve(lis)
829829

830+
err = chaincodeInvokeChaincode(t, "")
831+
if err != nil {
832+
t.Fail()
833+
t.Logf("Failed chaincode invoke chaincode : %s", err)
834+
closeListenerAndSleep(lis)
835+
return
836+
}
837+
838+
closeListenerAndSleep(lis)
839+
}
840+
841+
func chaincodeInvokeChaincode(t *testing.T, user string) (err error) {
830842
var ctxt = context.Background()
831843

832844
// Deploy first chaincode
@@ -836,15 +848,14 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
836848
f := "init"
837849
args := util.ToChaincodeArgs(f, "a", "100", "b", "200")
838850

839-
spec1 := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID1, CtorMsg: &pb.ChaincodeInput{Args: args}}
851+
spec1 := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID1, CtorMsg: &pb.ChaincodeInput{Args: args}, SecureContext: user}
840852

841853
_, err = deploy(ctxt, spec1)
842854
chaincodeID1 := spec1.ChaincodeID.Name
843855
if err != nil {
844856
t.Fail()
845857
t.Logf("Error initializing chaincode %s(%s)", chaincodeID1, err)
846858
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
847-
closeListenerAndSleep(lis)
848859
return
849860
}
850861

@@ -859,7 +870,7 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
859870
f = "init"
860871
args = util.ToChaincodeArgs(f, "e", "0")
861872

862-
spec2 := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID2, CtorMsg: &pb.ChaincodeInput{Args: args}}
873+
spec2 := &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID2, CtorMsg: &pb.ChaincodeInput{Args: args}, SecureContext: user}
863874

864875
_, err = deploy(ctxt, spec2)
865876
chaincodeID2 := spec2.ChaincodeID.Name
@@ -868,7 +879,6 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
868879
t.Logf("Error initializing chaincode %s(%s)", chaincodeID2, err)
869880
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
870881
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec2})
871-
closeListenerAndSleep(lis)
872882
return
873883
}
874884

@@ -878,7 +888,7 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
878888
f = "invoke"
879889
args = util.ToChaincodeArgs(f, "e", "1")
880890

881-
spec2 = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID2, CtorMsg: &pb.ChaincodeInput{Args: args}}
891+
spec2 = &pb.ChaincodeSpec{Type: 1, ChaincodeID: cID2, CtorMsg: &pb.ChaincodeInput{Args: args}, SecureContext: user}
882892
// Invoke chaincode
883893
var uuid string
884894
_, uuid, _, err = invoke(ctxt, spec2, pb.Transaction_CHAINCODE_INVOKE)
@@ -888,7 +898,6 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
888898
t.Logf("Error invoking <%s>: %s", chaincodeID2, err)
889899
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
890900
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec2})
891-
closeListenerAndSleep(lis)
892901
return
893902
}
894903

@@ -899,13 +908,67 @@ func TestChaincodeInvokeChaincode(t *testing.T) {
899908
t.Logf("Incorrect final state after transaction for <%s>: %s", chaincodeID1, err)
900909
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
901910
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec2})
902-
closeListenerAndSleep(lis)
903911
return
904912
}
905913

906914
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
907915
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec2})
908-
closeListenerAndSleep(lis)
916+
917+
return
918+
}
919+
920+
func TestChaincodeInvokeChaincodeWithSec(t *testing.T) {
921+
testDBWrapper.CleanDB(t)
922+
viper.Set("security.enabled", "true")
923+
924+
//Initialize crypto
925+
if err := crypto.Init(); err != nil {
926+
panic(fmt.Errorf("Failed initializing the crypto layer [%s]", err))
927+
}
928+
929+
//set paths for memberservice to pick up
930+
viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))
931+
viper.Set("server.rootpath", filepath.Join(os.TempDir(), "ca"))
932+
933+
var err error
934+
var memSrvcLis net.Listener
935+
if memSrvcLis, err = initMemSrvc(); err != nil {
936+
t.Fail()
937+
t.Logf("Error registering user %s", err)
938+
return
939+
}
940+
941+
time.Sleep(2 * time.Second)
942+
943+
var peerLis net.Listener
944+
if peerLis, err = initPeer(); err != nil {
945+
finitMemSrvc(memSrvcLis)
946+
t.Fail()
947+
t.Logf("Error registering user %s", err)
948+
return
949+
}
950+
951+
if err = crypto.RegisterClient("jim", nil, "jim", "6avZQLwcUe9b"); err != nil {
952+
finitMemSrvc(memSrvcLis)
953+
finitPeer(peerLis)
954+
t.Fail()
955+
t.Logf("Error registering user %s", err)
956+
return
957+
}
958+
959+
//login as jim and test chaincode-chaincode interaction with security
960+
if err = chaincodeInvokeChaincode(t, "jim"); err != nil {
961+
finitMemSrvc(memSrvcLis)
962+
finitPeer(peerLis)
963+
t.Fail()
964+
t.Logf("Error executing test %s", err)
965+
return
966+
}
967+
968+
//cleanup
969+
finitMemSrvc(memSrvcLis)
970+
finitPeer(peerLis)
971+
909972
}
910973

911974
// Test the execution of a chaincode that invokes another chaincode with wrong parameters. Should receive error from

0 commit comments

Comments
 (0)