[FAB-16296] Fixes for interest rate sample

backporting fixes from master to v1.4 for
interest rate sample

Change-Id: If7648c91c53dff737103de178bd8a09556765951
Signed-off-by: NIKHIL E GUPTA <negupta@us.ibm.com>
This commit is contained in:
NIKHIL E GUPTA 2019-08-13 10:17:40 -04:00
parent e80379a06f
commit 3d364ed082
4 changed files with 316 additions and 59 deletions

View file

@ -70,7 +70,7 @@ The interest-rate swap chaincode provides the following API:
given identifier and swap parameters among the two parties specified. This
function creates the entry for the swap and the corresponding payment. It
also sets the key-level endorsement policies for both keys to the participants
to the swap. In case the swap's prinicpal amount exceeds a certain threshold,
to the swap. In case the swap's principal amount exceeds a certain threshold,
it adds an auditor to the endorsement policy for the keys.
* `calculatePayment(swapID)` - calculate the net payment from party A to party
B and set the payment entry accordingly. If the payment information is negative,
@ -107,22 +107,26 @@ for creating a swap.
The `network` subdirectory contains scripts that will launch a sample network
and run a swap transaction flow from creation to settlement.
### Prerequesites
### Prerequisites
The following prerequisites are needed to run this sample:
* You need to run this sample from your GOPATH. If you have downloaded the
`fabric-samples` directory outside your GOPATH, then you need to copy or
move the interest rate sample into your GOPATH.
* Fabric docker images. By default the `network/network.sh` script will look for
fabric images with the `latest` tag, this can be adapted with the `-i` command
line parameter of the script.
* A local installation of `configtxgen` and `cryptogen` in the `PATH` environment,
or included in `fabric-samples/bin` directory.
* Vendoring the chaincode. In the chaincode directory, run `govendor init` and
* Vendoring the chaincode. In the `chaincode` directory, run `govendor init` and
`govendor add +external` to vendor the shim from your local copy of fabric.
### Bringing up the network
Simply run `network.sh up` to bring up the network. This will spawn docker
containers running a network of 3 "regular" organizations, one auditor
organization and one reference rate provider as well as a solo orderer.
Navigate to the `network` folder. Run the command `./network.sh up` to bring up
the network. This will spawn docker containers running a network of 3 "regular"
organizations, one auditor organization and one reference rate provider as well
as a solo orderer.
An additional CLI container will run `network/scripts/script.sh` to join the
peers to the `irs` channel and deploy the chaincode. In the init parameters it
@ -136,7 +140,7 @@ commands in the following section.
The chaincode is instantiated as follows:
```
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","100000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","1000000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
```
This sets an auditing threshold of 1M, above which the `auditor` organization
needs to be involved. It also specifies the `myrr` reference rate provided by
@ -144,16 +148,16 @@ the `rrprovider` organization.
To set a reference rate:
```
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 -c '{"Args":["setReferenceRate","myrr","3"]}'
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-rrprovider:7051 -c '{"Args":["setReferenceRate","myrr","300"]}'
```
Note that the transaction is endorsed by a peer of the organization we have
specified as providing this reference rate in the init parameters.
To create a swap named "myswap":
```
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":365,\"PrincipalAmount\":10000000,\"FixedRate\":4,\"FloatingRate\":5,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":100000,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
```
Note that the transaction is endorsed by both parties that are part of this
Note that the transaction is endorsed by both parties that are part of this
swap as well as the auditor. Since the principal amount in this case is lower
than the audit threshold we set as init parameters, no auditor will be required
to endorse changes to the payment info or swap details.
@ -173,4 +177,13 @@ peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc `--peer
As an exercise, try to create a new swap above the auditing threshold and see
how validation fails if the auditor is not involved in every operation on the
swap. Also try to calculate payment info before settling a prior payment to a
swap.
swap. You can run the commands yourself using the CLI container by issuing the
command ``docker exec -it cli bash``. You will need to set the corresponding
environment variables for the organization issuing the command. You refer to the
`network/scripts/script.sh` file for more information.
## Clean up
When you are finished using the network, you can bring down the docker images
and remove any artifacts by running the command `./network.sh down` from the
`network` folder.

View file

@ -3,27 +3,57 @@
# SPDX-License-Identifier: Apache-2.0
#
---
################################################################################
#
# Section: Organizations
#
# - This section defines the different organizational identities which will
# be referenced later in the configuration.
#
################################################################################
Organizations:
# SampleOrg defines an MSP using the sampleconfig. It should never be used
# in production but may be used as a template for other definitions
- &orderer
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: orderer
# ID to load the MSP definition as
ID: orderer
# MSPDir is the filesystem path which contains the MSP configuration
MSPDir: crypto-config/ordererOrganizations/example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: OR('orderer.member')
Rule: "OR('orderer.member')"
Writers:
Type: Signature
Rule: OR('orderer.member')
Rule: "OR('orderer.member')"
Admins:
Type: Signature
Rule: OR('orderer.admin')
Rule: "OR('orderer.admin')"
- &partya
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: partya
# ID to load the MSP definition as
ID: partya
MSPDir: crypto-config/peerOrganizations/partya.example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
@ -34,14 +64,28 @@ Organizations:
Admins:
Type: Signature
Rule: OR('partya.admin')
# leave this flag set to true.
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: irs-partya
Port: 7051
- &partyb
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: partyb
# ID to load the MSP definition as
ID: partyb
MSPDir: crypto-config/peerOrganizations/partyb.example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
@ -52,32 +96,61 @@ Organizations:
Admins:
Type: Signature
Rule: OR('partyb.admin')
# leave this flag set to true.
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: irs-partyb
Port: 7051
- &partyc
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: partyc
# ID to load the MSP definition as
ID: partyc
MSPDir: crypto-config/peerOrganizations/partyc.example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: OR('partyc.admin', 'partyc.peer', 'partyc.client')
Rule: "OR('partyc.admin', 'partyc.peer', 'partyc.client')"
Writers:
Type: Signature
Rule: OR('partyc.admin', 'partyc.client')
Rule: "OR('partyc.admin', 'partyc.client')"
Admins:
Type: Signature
Rule: OR('partyc.admin')
Rule: "OR('partyc.admin')"
# leave this flag set to true.
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: irs-partyc
Port: 7051
- &auditor
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: auditor
# ID to load the MSP definition as
ID: auditor
MSPDir: crypto-config/peerOrganizations/auditor.example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
@ -88,90 +161,254 @@ Organizations:
Admins:
Type: Signature
Rule: OR('auditor.admin')
# leave this flag set to true.
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: irs-auditor
Port: 7051
- &rrprovider
# DefaultOrg defines the organization which is used in the sampleconfig
# of the fabric.git development environment
Name: rrprovider
# ID to load the MSP definition as
ID: rrprovider
MSPDir: crypto-config/peerOrganizations/rrprovider.example.com/msp
# Policies defines the set of policies at this level of the config tree
# For organization policies, their canonical path is usually
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
Policies:
Readers:
Type: Signature
Rule: OR('rrprovider.admin', 'rrprovider.peer', 'rrprovider.client')
Rule: "OR('rrprovider.admin', 'rrprovider.peer', 'rrprovider.client')"
Writers:
Type: Signature
Rule: OR('rrprovider.admin', 'rrprovider.client')
Rule: "OR('rrprovider.admin', 'rrprovider.client')"
Admins:
Type: Signature
Rule: OR('rrprovider.admin')
Rule: "OR('rrprovider.admin')"
# leave this flag set to true.
AnchorPeers:
# AnchorPeers defines the location of peers which can be used
# for cross org gossip communication. Note, this value is only
# encoded in the genesis block in the Application section context
- Host: irs-rrprovider
Port: 7051
Channel: &ChannelDefaults
Capabilities:
V1_3: true
################################################################################
#
# SECTION: Capabilities
#
# - This section defines the capabilities of fabric network. This is a new
# concept as of v1.1.0 and should not be utilized in mixed networks with
# v1.0.x peers and orderers. Capabilities define features which must be
# present in a fabric binary for that binary to safely participate in the
# fabric network. For instance, if a new MSP type is added, newer binaries
# might recognize and validate the signatures from this type, while older
# binaries without this support would be unable to validate those
# transactions. This could lead to different versions of the fabric binaries
# having different world states. Instead, defining a capability for a channel
# informs those binaries without this capability that they must cease
# processing transactions until they have been upgraded. For v1.0.x if any
# capabilities are defined (including a map with all capabilities turned off)
# then the v1.0.x peer will deliberately crash.
#
################################################################################
Capabilities:
# Channel capabilities apply to both the orderers and the peers and must be
# supported by both.
# Set the value of the capability to true to require it.
Channel: &ChannelCapabilities
# V1.4.2 for Channel is a catchall flag for behavior which has been
# determined to be desired for all orderers and peers running at the v1.4.2
# level, but which would be incompatible with orderers and peers from
# prior releases.
# Prior to enabling V1.4.2 channel capabilities, ensure that all
# orderers and peers on a channel are at v1.4.2 or later.
V1_4_2: true
# Orderer capabilities apply only to the orderers, and may be safely
# used with prior release peers.
# Set the value of the capability to true to require it.
Orderer: &OrdererCapabilities
# V1.4.2 for Orderer is a catchall flag for behavior which has been
# determined to be desired for all orderers running at the v1.4.2
# level, but which would be incompatible with orderers from prior releases.
# Prior to enabling V1.4.2 orderer capabilities, ensure that all
# orderers on a channel are at v1.4.2 or later.
V1_4_2: true
# Application capabilities apply only to the peer network, and may be safely
# used with prior release orderers.
# Set the value of the capability to true to require it.
Application: &ApplicationCapabilities
# V1.4.2 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.4.2.
V1_4_2: true
# V1.3 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.3.
V1_3: false
# V1.2 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.2 (note, this need not be set if
# later version capabilities are set)
V1_2: false
# V1.1 for Application enables the new non-backwards compatible
# features and fixes of fabric v1.1 (note, this need not be set if
# later version capabilities are set).
V1_1: false
################################################################################
#
# SECTION: Application
#
# - This section defines the values to encode into a config transaction or
# genesis block for application related parameters
#
################################################################################
Application: &ApplicationDefaults
# Organizations is the list of orgs which are defined as participants on
# the application side of the network
Organizations:
# Policies defines the set of policies at this level of the config tree
# For Application policies, their canonical path is
# /Channel/Application/<PolicyName>
Policies:
Readers:
Type: ImplicitMeta
Rule: ANY Readers
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: ANY Writers
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: MAJORITY Admins
Rule: "MAJORITY Admins"
Orderer: &OrdererDefaults
OrdererType: solo
Capabilities:
V1_1: true
<<: *ApplicationCapabilities
################################################################################
#
# SECTION: Orderer
#
# - This section defines the values to encode into a config transaction or
# genesis block for orderer related parameters
#
################################################################################
Orderer: &OrdererDefaults
# Orderer Type: The orderer implementation to start
# Available types are "solo" and "kafka"
OrdererType: solo
Addresses:
- irs-orderer:7050
# Batch Timeout: The amount of time to wait before creating a batch
BatchTimeout: 2s
# Batch Size: Controls the number of messages batched into a block
BatchSize:
# Max Message Count: The maximum number of messages to permit in a batch
MaxMessageCount: 10
# Absolute Max Bytes: The absolute maximum number of bytes allowed for
# the serialized messages in a batch.
AbsoluteMaxBytes: 99 MB
# Preferred Max Bytes: The preferred maximum number of bytes allowed for
# the serialized messages in a batch. A message larger than the preferred
# max bytes will result in a batch larger than preferred max bytes.
PreferredMaxBytes: 512 KB
Kafka:
# Brokers: A list of Kafka brokers to which the orderer connects
# NOTE: Use IP:port notation
Brokers:
- 127.0.0.1:9092
# Organizations is the list of orgs which are defined as participants on
# the orderer side of the network
Organizations:
# Policies defines the set of policies at this level of the config tree
# For Orderer policies, their canonical path is
# /Channel/Orderer/<PolicyName>
Policies:
Readers:
Type: ImplicitMeta
Rule: ANY Readers
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: ANY Writers
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: MAJORITY Admins
Type: ImplicitMeta
Rule: "MAJORITY Admins"
# BlockValidation specifies what signatures must be included in the block
# from the orderer for the peer to validate it.
BlockValidation:
Type: ImplicitMeta
Rule: ANY Writers
Organizations:
Rule: "ANY Writers"
Application: &ApplicationDefaults
Capabilities:
V1_3: true
################################################################################
#
# CHANNEL
#
# This section defines the values to encode into a config transaction or
# genesis block for channel related parameters.
#
################################################################################
Channel: &ChannelDefaults
# Policies defines the set of policies at this level of the config tree
# For Channel policies, their canonical path is
# /Channel/<PolicyName>
Policies:
# Who may invoke the 'Deliver' API
Readers:
Type: ImplicitMeta
Rule: ANY Readers
Type: ImplicitMeta
Rule: "ANY Readers"
# Who may invoke the 'Broadcast' API
Writers:
Type: ImplicitMeta
Rule: ANY Writers
Type: ImplicitMeta
Rule: "ANY Writers"
# By default, who may modify elements at this config level
Admins:
Type: ImplicitMeta
Rule: MAJORITY Admins
Organizations:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
# Capabilities describes the channel level capabilities, see the
# dedicated Capabilities section elsewhere in this file for a full
# description
Capabilities:
<<: *ChannelCapabilities
################################################################################
#
# Profile
#
# - Different configuration profiles may be encoded here to be specified
# as parameters to the configtxgen tool
#
################################################################################
Profiles:
IRSNetGenesis:
<<: *ChannelDefaults
Orderer:
<<: *OrdererDefaults
Organizations:
- *orderer
Capabilities:
<<: *OrdererCapabilities
Consortiums:
SampleConsortium:
Organizations:
@ -182,11 +419,21 @@ Profiles:
- *auditor
IRSChannel:
Consortium: SampleConsortium
<<: *ChannelDefaults
Application:
<<: *ApplicationDefaults
Organizations:
- *partya
- *partyb
- *partyc
- *rrprovider
- *auditor
- *partya
- *partyb
- *partyc
- *rrprovider
- *auditor
Capabilities:
<<: *ApplicationCapabilities
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#

View file

@ -168,7 +168,7 @@ function generateChannelArtifacts() {
echo "######### Generating Orderer Genesis block ##############"
mkdir channel-artifacts
configtxgen -profile IRSNetGenesis -outputBlock ./channel-artifacts/genesis.block
configtxgen -profile IRSNetGenesis -outputBlock ./channel-artifacts/genesis.block -channelID system-channel
res=$?
if [ $res -ne 0 ]; then
echo "Failed to generate orderer genesis block..."
@ -184,9 +184,6 @@ function generateChannelArtifacts() {
fi
}
# Obtain the OS and Architecture string that will be used to select the correct
# native binaries for your platform, e.g., darwin-amd64 or linux-amd64
OS_ARCH=$(echo "$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
CHANNEL_NAME="irs"
COMPOSE_FILE=docker-compose.yaml
COMPOSE_PROJECT_NAME=fabric-irs

View file

@ -46,7 +46,7 @@ instantiateChaincode() {
CORE_PEER_ADDRESS=irs-partya:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/Admin@partya.example.com/msp
echo "===================== Instantiating chaincode ===================== "
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","100000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
peer chaincode instantiate -o irs-orderer:7050 -C irs -n irscc -l golang -v 0 -c '{"Args":["init","auditor","1000000","rrprovider","myrr"]}' -P "AND(OR('partya.peer','partyb.peer','partyc.peer'), 'auditor.peer')"
echo "===================== Chaincode instantiated ===================== "
}
@ -64,7 +64,7 @@ createSwap() {
CORE_PEER_ADDRESS=irs-partya:7051
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/partya.example.com/users/User1@partya.example.com/msp
echo "===================== Invoking chaincode ===================== "
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":10,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
peer chaincode invoke -o irs-orderer:7050 -C irs --waitForEvent -n irscc --peerAddresses irs-partya:7051 --peerAddresses irs-partyb:7051 --peerAddresses irs-auditor:7051 -c '{"Args":["createSwap","myswap","{\"StartDate\":\"2018-09-27T15:04:05Z\",\"EndDate\":\"2018-09-30T15:04:05Z\",\"PaymentInterval\":395,\"PrincipalAmount\":100000,\"FixedRate\":400,\"FloatingRate\":500,\"ReferenceRate\":\"myrr\"}", "partya", "partyb"]}'
echo "===================== Chaincode invoked ===================== "
}