Skip to content

Commit

Permalink
Merge "Fix FAB-578" into v0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed Oct 2, 2016
2 parents 4a78b41 + a96b9ed commit 562a35f
Show file tree
Hide file tree
Showing 75 changed files with 1,644 additions and 2,641 deletions.
1 change: 1 addition & 0 deletions .baseimage-release
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ go-carpet-coverage*
# make node-sdk copied files
sdk/node/lib/protos/*
report.xml
.settings
.project
.gradle
build/
bin/
42 changes: 18 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
# - dist-clean - superset of 'clean' that also removes persistent state

PROJECT_NAME = hyperledger/fabric
BASE_VERSION = 0.6.1-preview
BASE_VERSION = 0.7.0
IS_RELEASE = false

ifneq ($(IS_RELEASE),true)
Expand All @@ -47,13 +47,16 @@ else
PROJECT_VERSION=$(BASE_VERSION)
endif

DOCKER_TAG=$(shell uname -m)-$(PROJECT_VERSION)

PKGNAME = github.com/$(PROJECT_NAME)
GO_LDFLAGS = -X github.com/hyperledger/fabric/metadata.Version=$(PROJECT_VERSION)
CGO_FLAGS = CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy"
UID = $(shell id -u)
ARCH=$(shell uname -m)
CHAINTOOL_RELEASE=v0.9.1
BASEIMAGE_RELEASE=$(shell cat ./.baseimage-release)

DOCKER_TAG=$(ARCH)-$(PROJECT_VERSION)
BASE_DOCKER_TAG=$(ARCH)-$(BASEIMAGE_RELEASE)

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

# Make our baseimage depend on any changes to images/base or scripts/provision
BASEIMAGE_RELEASE = $(shell cat ./images/base/release)
BASEIMAGE_DEPS = $(shell git ls-files images/base scripts/provision)

JAVASHIM_DEPS = $(shell git ls-files core/chaincode/shim/java)
PROJECT_FILES = $(shell git ls-files)
IMAGES = base src ccenv peer membersrvc javaenv
IMAGES = src ccenv peer membersrvc javaenv

all: peer membersrvc checks

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

build/bin/chaintool: Makefile
@echo "Installing chaintool"
Expand Down Expand Up @@ -172,25 +171,19 @@ build/bin/block-listener:
@echo "Binary available as $@"
@touch $@

build/bin/%: build/image/base/.dummy $(PROJECT_FILES)
build/bin/%: $(PROJECT_FILES)
@mkdir -p $(@D)
@echo "$@"
$(CGO_FLAGS) GOBIN=$(abspath $(@D)) go install -ldflags "$(GO_LDFLAGS)" $(PKGNAME)/$(@F)
@echo "Binary available as $@"
@touch $@

# Special override for base-image.
build/image/base/.dummy: $(BASEIMAGE_DEPS)
@echo "Building docker base-image"
@mkdir -p $(@D)
@./scripts/provision/docker.sh $(BASEIMAGE_RELEASE)
@touch $@

# Special override for src-image
build/image/src/.dummy: build/image/base/.dummy $(PROJECT_FILES)
build/image/src/.dummy: $(PROJECT_FILES)
@echo "Building docker src-image"
@mkdir -p $(@D)
@cat images/src/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
@git ls-files | tar -jcT - > $(@D)/gopath.tar.bz2
Expand All @@ -202,6 +195,7 @@ build/image/src/.dummy: build/image/base/.dummy $(PROJECT_FILES)
build/image/ccenv/.dummy: build/image/src/.dummy build/image/ccenv/bin/protoc-gen-go build/image/ccenv/bin/chaintool Makefile
@echo "Building docker ccenv-image"
@cat images/ccenv/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
docker build -t $(PROJECT_NAME)-ccenv $(@D)
Expand All @@ -216,7 +210,10 @@ build/image/ccenv/.dummy: build/image/src/.dummy build/image/ccenv/bin/protoc-ge
build/image/javaenv/.dummy: Makefile $(JAVASHIM_DEPS)
@echo "Building docker javaenv-image"
@mkdir -p $(@D)
@cat images/javaenv/Dockerfile.in > $(@D)/Dockerfile
@cat images/javaenv/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
@git ls-files core/chaincode/shim/java | tar -jcT - > $(@D)/javashimsrc.tar.bz2
@git ls-files protos core/chaincode/shim/table.proto settings.gradle | tar -jcT - > $(@D)/protos.tar.bz2
docker build -t $(PROJECT_NAME)-javaenv $(@D)
Expand All @@ -229,6 +226,7 @@ build/image/%/.dummy: build/image/src/.dummy build/docker/bin/%
@echo "Building docker $(TARGET)-image"
@mkdir -p $(@D)/bin
@cat images/app/Dockerfile.in \
| sed -e 's/_BASE_TAG_/$(BASE_DOCKER_TAG)/g' \
| sed -e 's/_TAG_/$(DOCKER_TAG)/g' \
> $(@D)/Dockerfile
cp build/docker/bin/$(TARGET) $(@D)/bin
Expand All @@ -240,10 +238,6 @@ build/image/%/.dummy: build/image/src/.dummy build/docker/bin/%
protos: gotools
./devenv/compile_protos.sh

base-image-clean:
-docker rmi -f $(PROJECT_NAME)-baseimage
-@rm -rf build/image/base ||:

src-image-clean: ccenv-image-clean peer-image-clean membersrvc-image-clean

%-image-clean:
Expand Down
23 changes: 23 additions & 0 deletions core/chaincode/chaincode_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/golang/protobuf/proto"
logging "github.com/op/go-logging"
"github.com/spf13/viper"
"golang.org/x/net/context"

Expand All @@ -34,6 +35,7 @@ import (
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/crypto"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/flogging"
pb "github.com/hyperledger/fabric/protos"
)

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

viper.SetEnvPrefix("CORE")
viper.AutomaticEnv()
replacer := strings.NewReplacer(".", "_")
viper.SetEnvKeyReplacer(replacer)

chaincodeLogLevelString := viper.GetString("logging.chaincode")
chaincodeLogLevel, err := logging.LogLevel(chaincodeLogLevelString)

if err == nil {
s.chaincodeLogLevel = chaincodeLogLevel.String()
} else {
chaincodeLogger.Infof("chaincode logging level %s is invalid. defaulting to %s\n", chaincodeLogLevelString, flogging.DefaultLoggingLevel().String())
s.chaincodeLogLevel = flogging.DefaultLoggingLevel().String()
}

return s
}

Expand All @@ -172,6 +189,7 @@ type ChaincodeSupport struct {
peerTLSKeyFile string
peerTLSSvrHostOrd string
keepalive time.Duration
chaincodeLogLevel string
}

// DuplicateChaincodeHandlerError returned if attempt to register same chaincodeID while a stream already exists.
Expand Down Expand Up @@ -290,6 +308,11 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cID *pb.ChaincodeID, cLa
} else {
envs = append(envs, "CORE_PEER_TLS_ENABLED=false")
}

if chaincodeSupport.chaincodeLogLevel != "" {
envs = append(envs, "CORE_LOGGING_CHAINCODE="+chaincodeSupport.chaincodeLogLevel)
}

switch cLang {
case pb.ChaincodeSpec_GOLANG, pb.ChaincodeSpec_CAR:
//chaincode executable will be same as the name of the chaincode
Expand Down
18 changes: 4 additions & 14 deletions core/chaincode/chaincodetest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,6 @@ peer:
# networkId: test
networkId: dev

Dockerfile: |
from hyperledger/fabric-baseimage:latest
# Copy GOPATH src and install Peer
COPY src $GOPATH/src
RUN mkdir -p /var/hyperledger/db
WORKDIR $GOPATH/src/github.com/hyperledger/fabric/peer/
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
# The Address this Peer will listen on
listenAddress: 0.0.0.0:21212
# The Address this Peer will bind to for providing services
Expand Down Expand Up @@ -363,17 +354,16 @@ chaincode:
# This is the basis for the Golang Dockerfile. Additional commands will
# be appended depedendent upon the chaincode specification.
Dockerfile: |
from hyperledger/fabric-baseimage
#from utxo:0.1.0
COPY src $GOPATH/src
WORKDIR $GOPATH
FROM hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
COPY src $GOPATH/src
WORKDIR $GOPATH
car:

# This is the basis for the CAR Dockerfile. Additional commands will
# be appended depedendent upon the chaincode specification.
Dockerfile: |
FROM hyperledger/fabric-baseimage
FROM hyperledger/fabric-ccenv:$(ARCH)-$(PROJECT_VERSION)
# timeout in millisecs for starting up a container and waiting for Register
# to come through. 1sec should be plenty for chaincode unit tests
Expand Down
79 changes: 71 additions & 8 deletions core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,18 @@ func TestChaincodeInvokeChaincode(t *testing.T) {

go grpcServer.Serve(lis)

err = chaincodeInvokeChaincode(t, "")
if err != nil {
t.Fail()
t.Logf("Failed chaincode invoke chaincode : %s", err)
closeListenerAndSleep(lis)
return
}

closeListenerAndSleep(lis)
}

func chaincodeInvokeChaincode(t *testing.T, user string) (err error) {
var ctxt = context.Background()

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

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

_, err = deploy(ctxt, spec1)
chaincodeID1 := spec1.ChaincodeID.Name
if err != nil {
t.Fail()
t.Logf("Error initializing chaincode %s(%s)", chaincodeID1, err)
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
closeListenerAndSleep(lis)
return
}

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

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

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

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

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

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

GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec1})
GetChain(DefaultChain).Stop(ctxt, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec2})
closeListenerAndSleep(lis)

return
}

func TestChaincodeInvokeChaincodeWithSec(t *testing.T) {
testDBWrapper.CleanDB(t)
viper.Set("security.enabled", "true")

//Initialize crypto
if err := crypto.Init(); err != nil {
panic(fmt.Errorf("Failed initializing the crypto layer [%s]", err))
}

//set paths for memberservice to pick up
viper.Set("peer.fileSystemPath", filepath.Join(os.TempDir(), "hyperledger", "production"))
viper.Set("server.rootpath", filepath.Join(os.TempDir(), "ca"))

var err error
var memSrvcLis net.Listener
if memSrvcLis, err = initMemSrvc(); err != nil {
t.Fail()
t.Logf("Error registering user %s", err)
return
}

time.Sleep(2 * time.Second)

var peerLis net.Listener
if peerLis, err = initPeer(); err != nil {
finitMemSrvc(memSrvcLis)
t.Fail()
t.Logf("Error registering user %s", err)
return
}

if err = crypto.RegisterClient("jim", nil, "jim", "6avZQLwcUe9b"); err != nil {
finitMemSrvc(memSrvcLis)
finitPeer(peerLis)
t.Fail()
t.Logf("Error registering user %s", err)
return
}

//login as jim and test chaincode-chaincode interaction with security
if err = chaincodeInvokeChaincode(t, "jim"); err != nil {
finitMemSrvc(memSrvcLis)
finitPeer(peerLis)
t.Fail()
t.Logf("Error executing test %s", err)
return
}

//cleanup
finitMemSrvc(memSrvcLis)
finitPeer(peerLis)

}

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

0 comments on commit 562a35f

Please sign in to comment.