Uploaded image for project: 'Fabric'
  1. Fabric
  2. FAB-10162

Test: Manually exercise private data chaincode in dev env

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Medium
    • Resolution: Done
    • None
    • v1.2.0
    • fabric-ledger

    Description

      Setup dev environment with latest master.

      All commands run from GOPATH/src/github.com/hyperledger/fabric directory.

      export PATH=$GOPATH/src/github.com/hyperledger/fabric/.build/bin:$PATH
      export FABRIC_CFG_PATH=$GOPATH/src/github.com/hyperledger/fabric/sampleconfig/
      

       

      In ./sampleconfig/configtx.yaml ensure that V1_2 capability is set.

      make docker needed for building chaincode image, make binaries for local execution:

      make docker-clean docker
      
      make configtxgen
      
      make orderer
      
      make peer

       

      Make sure you have fabric-samples with private chaincode sample at ../fabric-samples/chaincode/marbles02_private.

      The fabric-samples uses Org1 and Org2 MSPs, so we'll create our own copy in ./collection.json to use SampleOrg MSP:

      [
       {
           "name": "collectionMarbles",
           "policy": "OR('Org1MSP.member', 'Org2MSP.member','SampleOrg.member')",
           "requiredPeerCount": 0,
           "maxPeerCount": 0,
           "blockToLive":1000000
      },
       {
           "name": "collectionMarblePrivateDetails",
           "policy": "OR('Org1MSP.member','SampleOrg.member')",
           "requiredPeerCount": 0,
           "maxPeerCount": 0,
           "blockToLive":100000
       }
      ]

      Note on above - Org1MSP and Org2MSP are used for e2e. SampleOrg is used for dev env.

       

      Delete any existing Fabric data:

      rm -r /var/hyperledger/

      Use a separate command prompt for 1) orderer 2) peer 3) CLI commands:

      1) start orderer:

      ORDERER_GENERAL_GENESISPROFILE=SampleSingleMSPSolo orderer

      2) start peer:

      CORE_LOGGING_LEVEL=DEBUG peer node start

      or start peer with CouchDB (also stop/restart couchdb container as needed):

      docker stop couchdb
      docker rm couchdb
      docker run --publish 5984:5984 --detach --name couchdb hyperledger/fabric-couchdb
      
      CORE_LOGGING_LEVEL=DEBUG CORE_LEDGER_STATE_STATEDATABASE=CouchDB peer node start

      3) CLI commands:

      Create and Join channel:
       

      peer logging setlevel gossip ERROR
      
      configtxgen -channelID mycp -outputCreateChannelTx mycp.tx -profile SampleSingleMSPChannel
      
      peer channel create -c mycp -o 127.0.0.1:7050 -f mycp.tx
      
      peer channel join -b mycp.block

       
      marbles02 - Install and Instantiate:
       

      peer chaincode install -n marblesp -p github.com/hyperledger/fabric-samples/chaincode/marbles02_private/go -v 1
      
      peer chaincode instantiate -C mycp -n marblesp -c '{"Args":["init"]}' -v 1 -o 127.0.0.1:7050 --collections-config collection.json

      marbles02 - invoke:

      peer chaincode invoke -o 127.0.0.1:7050 -C mycp -n marblesp -c '{"Args":["initMarble","marble1","blue","35","tom","99"]}'

      marbles02 - queries:
       

      peer chaincode query -C mycp -n marblesp -c '{"Args":["readMarble","marble1"]}'
      
      peer chaincode query -C mycp -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}'
      
      peer chaincode query -C mycp -n marblesp -c '{"Args":["getMarblesByRange","marble1","marble8"]}'

       
      marbles02 - couchdb queries:

      peer chaincode query -C mycp -n marblesp -c '{"Args":["queryMarblesByOwner","tom"]}'
      
      peer chaincode query -C mycp -n marblesp -c '{"Args":["queryMarbles","{\"selector\":{\"docType\":\"marble\",\"owner\":\"tom\"}}"]}'

       
      marbles02 - install and instantiate a 2nd chaincode version, change collection config as desired for the test first:
       

      peer chaincode install -n marblesp -p github.com/hyperledger/fabric-samples/chaincode/marbles02_private/go -v 2
      
      peer chaincode upgrade -C mycp -n marblesp -c '{"Args":["init"]}' -v 2 -o 127.0.0.1:7050 --collections-config collection.json

       
      Other test scenarios executed:

      TEST: Invalid collection json - returns error upon instantiate

      TEST: Invalid collection name (special characters) - instantiate/upgrade tran gets invalidated with a good message (would be nice to also return error upon instantiate). "A valid collection name follows the pattern: [A-Za-z0-9_-]+"

      TEST: Invalid collection policy - instantiate/upgrade tran gets invalidated with a good message (would be nice to also return error upon instantiate), as of -----FAB-6526-----.

      TEST: Invalid requiredPeerCount (-1) - instantiate/upgrade tran gets invalidated with a good message (would be nice to also return error upon instantiate)

      TEST: Policy references non channel member - prints Warning in peer log (no error since user may be referencing a future expected channel member), as of -----FAB-6526-----.

      TEST: Attempt to change blockToLive during upgrade - instantiate/upgrade tran gets invalidated with a good message (would be nice to also return error upon instantiate)

      TEST: Attempt to delete (not specify) collection during upgrade - instantiate/upgrade tran gets invalidated with a good message (would be nice to also return error upon instantiate).  The existing message should be improved to indicate which collection does not exist.  Currently message is just "Some existing collection configurations are missing in the new collection configuration package". Opened FAB-10512.

       

      TEST: Test all chaincode private data APIs - works as expected, e.g.:
       

      peer chaincode query -C mycp -n marblesp -c '{"Args":["readMarble","marble1"]}' 
      peer chaincode query -C mycp -n marblesp -c '{"Args":["readMarblePrivateDetails","marble1"]}' 
      peer chaincode query -C mycp -n marblesp -c '{"Args":["getMarblesByRange","marble1","marble8"]}' 
      peer chaincode query -C mycp -n marblesp -c '{"Args":["queryMarblesByOwner","tom"]}'

       
      However, queryMarblesByOwner (CouchDB JSON query) dumps benign error messages in peer log, opened FAB-10559.

       

      TEST: Test transfer of a marble

      peer chaincode invoke -o 127.0.0.1:7050 -C mycp -n marblesp -c '{"Args":["transferMarble","marble1","jerry"]}' 

      The transfer works, but get Warning in logs since the batch update had problems:

      2018-06-06 05:46:01.976 EDT [couchdb] BatchUpdateDocuments -> DEBU 80c Exiting BatchUpdateDocuments() _bulk_docs response=[[{"id":"marble1","error":"conflict","reason":"Document update conflict."}]
      ]
      2018-06-06 05:46:01.976 EDT [statecouchdb] commitUpdates -> WARN 80d CouchDB batch document update encountered an problem. Retrying update for document ID:marble1

      Opened FAB-10558.

       

      TEST: Test query/update transactions - fails as expected (since not all peers can validate private private data result sets), e.g.:

      peer chaincode invoke -o 127.0.0.1:7050 -C mycp -n marblesp -c '{"Args":["transferMarblesBasedOnColor","blue","jerry"]}'

      fails with error message: "Transaction has already performed queries on pvt data. Writes are not allowed"

       

      TEST: Query for private data you don't have access to - fails as expected with error "Private data matching public hash version is not available."

       

      TEST: Test no purging - "blockToLive":null and "blockToLive":0 and missing "blockToLive" all have the same semantic meaning - they indicate to never purge private data.

      TEST: Query for purged private data, set "blockToLive":3 and then do 4 transactions on another key - query fails as expected with error "Marble private details does not exist: marble1".

       

      TEST: Test purging of private write set storage.  Set core.yaml config to override default purgeInterval of 100:

      ledger:
        pvtdataStore:
          purgeInterval: 5

      With blockToLive of 3, create a new marble with each invoke.  In blocks [5] and  [10] you will see purge entries such as:

      2018-06-04 17:37:13.876 EDT [pvtdatastorage] func1 -> INFO 124b Purger started: Purging expired private data till block number [10]
      
      2018-06-04 17:37:13.876 EDT [pvtdatastorage] purgeExpiredData -> DEBU 1253 [5] Entries purged from private data storage
      2018-06-04 17:37:13.876 EDT [pvtdatastorage] func1 -> INFO 1254 Purger finished
      

       

       

      Attachments

        Issue Links

          Activity

            People

              denyeart David Enyeart
              denyeart David Enyeart
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: