Coder Social home page Coder Social logo

resouer / fabric Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hyperledger-archives/fabric

0.0 1.0 0.0 37.93 MB

Blockchain fabric incubator code

License: Apache License 2.0

Python 1.73% Gherkin 1.91% Go 92.12% Protocol Buffer 1.98% Shell 1.93% Gnuplot 0.11% Ruby 0.19% Makefile 0.05%

fabric's Introduction

Overview

This project contains the core blockchain fabric code, development environment scripts and documents for developers to contribute fabric code or work on their own applications.

License

This software is made available under the Apache License Version 2.0.

Building the the fabric core

Assuming you have followed the development environment getting started instructions

To access your VM, run

vagrant ssh

From within the VM, you can build, run, and test your environment.

1. Go build

cd $GOPATH/src/github.com/hyperledger/fabric
go build -o peer

2. Run

To see what commands are available, simply execute the following command:

cd $GOPATH/src/github.com/hyperledger/fabric
./peer

You should see some output similar to below (NOTE: The root command below is hardcoded in the main.go. Current build will actually create a peer executable file).

    Usage:
      peer [command]

    Available Commands:
      peer        Run peer.
      status      Status of the peer.
      stop        Stops the peer.
      chaincode   Compiles the specified chaincode.
      help        Help about any command

    Flags:
      -h, --help[=false]: help for peer


    Use "peer [command] --help" for more information about a command.

The peer command will run peer process. You can then use the other commands to interact with this peer process. For example, status will show the peer status.

3. Test

New code must be accompanied by test cases both in unit and Behave tests.

3.1 Unit Tests

To run all unit tests, in one window, run ./peer peer. In a second window

cd $GOPATH/src/github.com/hyperledger/fabric
go test -timeout=20m $(go list github.com/hyperledger/fabric/... | grep -v /vendor/ | grep -v /examples/)

Note that the first time the tests are run, they can take some time due to the need to download a docker image that is about 1GB in size. This is why the timeout flag is added to the above command.

To run a specific test use the -run RE flag where RE is a regular expression that matches the test name. To run tests with verbose output use the -v flag. For example, to run TestGetFoo function, change to the directory containing the foo_test.go and enter:

go test -test.v -run=TestGetFoo

3.2 Behave Tests

Behave tests will setup networks of peers with different security and consensus configurations and verify that transactions run properly. To run these tests

cd $GOPATH/src/github.com/hyperledger/fabric/bddtests
behave

Some of the Behave tests run inside Docker containers. If a test fails and you want to have the logs from the Docker containers, run the tests with this option

behave -D logs=Y

Note, you must run the unit tests first to build the necessary Peer and Member Services docker images. These images can also be individually built using the commands

go test github.com/hyperledger/fabric/core/container -run=BuildImage_Peer
go test github.com/hyperledger/fabric/core/container -run=BuildImage_Obcca

Building outside of Vagrant

This is not recommended, however some users may wish to build outside of Vagrant if they use an editor with built in Go tooling. The instructions are

  1. Follow all steps required to setup and run a Vagrant image
  • Make you you have Go 1.6 or later installed
  • Set the maximum number of open files to 10000 or greater for your OS
  • Install RocksDB version 4.1 and it's dependencies:
apt-get install -y libsnappy-dev zlib1g-dev libbz2-dev
cd /tmp
git clone https://github.com/facebook/rocksdb.git
cd rocksdb
git checkout tags/v4.1
PORTABLE=1 make shared_lib
INSTALL_PATH=/usr/local make install-shared
  • Run the following commands:
cd $GOPATH/src/github.com/hyperledger/fabric
CGO_CFLAGS=" " CGO_LDFLAGS="-lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy" go install
  • Make sure that the Docker daemon initialization includes the options
-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
  • Be aware that the Docker bridge (the OPENCHAIN_VM_ENDPOINT) may not come up at the IP address currently assumed by the test environment (172.17.0.1). Use ifconfig or ip addr to find the docker bridge.

Code contributions

We are using the GitHub Flow process to manage code contributions.

Note the following GitHub Flow highlights:

  • Anything in the master branch is deployable
  • To work on something new, create a descriptively-named branch off of your fork (more detail on fork)
  • Commit to that branch locally, and regularly push your work to the same branch on the server
  • When you need feedback or help, or you think the branch is ready for merging, open a pull request (make sure you have first successfully built and tested with the Unit and Behave Tests)
  • After your pull request has been reviewed and signed off, a committer can merge it into the master branch.

We use the same approach—the Developer's Certificate of Origin (DCO)—that the Linux® Kernel community uses to manage code contributions. We simply ask that when submitting a pull request, the developer must include a sign-off statement in the pull request description.

Here is an example Signed-off-by line, which indicates that the submitter accepts the DCO:

Signed-off-by: John Doe <[email protected]>

Communication

We use Slack for communication and Google Hangouts™ for screen sharing between developers. Register with these tools to get connected.

Coding Golang

  • We require a file header in all source code files. Simply copy and paste the header when you create a new file.
  • We code in Go™ and strictly follow the best practices and will not accept any deviations. You must run the following tools against your Go code and fix all errors and warnings:

Writing Chaincode

Since chaincode is written in Go language, you can set up the environment to accommodate the rapid edit-compile-run of your chaincode. Follow the instructions on the Sandbox Setup page, which allows you to run your chaincode off the blockchain.

Setting Up a Network

To set up an development network of several validating peers, follow the instructions on the Devnet Setup page. This network leverage Docker to manage multiple instances of validating peer on the same machine, allowing you to quickly test your chaincode.

Working with CLI, REST, and Node.js

When you are ready to start interacting with the peer node through the available APIs and packages, follow the instructions on the API Documentation page.

Configuration

Configuration utilizes the viper and cobra libraries.

There is an core.yaml file that contains the configuration for the peer process. Many of the configuration settings can be overridden at the command line by setting ENV variables that match the configuration setting, but by prefixing the tree with 'CORE_'. For example, logging level manipulation through the environment is shown below:

CORE_PEER_LOGGING_LEVEL=CRITICAL ./peer

Logging

Logging utilizes the go-logging library.

The available log levels in order of increasing verbosity are: CRITICAL | ERROR | WARNING | NOTICE | INFO | DEBUG

See specific logging control when running peer.

Generating grpc code

If you modify any .proto files, run the following command to generate new .pb.go files.

devenv/compile_protos.sh

Adding or updating a Go packages

The fabric uses Go 1.6 vendoring for package management. This means that all required packages reside in the /vendor folder within the obc-peer project. Go will use packages in this folder instead of the GOPATH when go install or go build is run. To manage the packages in the /vendor folder, we use Govendor. This is installed in the Vagrant environment. The following commands can be used for package management.

# Add external packages.
govendor add +external

# Add a specific package.
govendor add github.com/kardianos/osext

# Update vendor packages.
govendor update +vendor

# Revert back to normal GOPATH packages.
govendor remove +vendor

# List package.
govendor list

fabric's People

Contributors

adecaro avatar alandotcom avatar binhn avatar cblsjtu avatar christo4ferris avatar corecode avatar cp68 avatar ebuchman avatar ghaskins avatar jeffgarratt avatar joshhus avatar jyellick avatar kchristidis avatar lehors avatar mrshah-at-ibm avatar prjayach avatar rameshthoomu avatar srderson avatar thkzrl avatar tuand27613 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.