A cordapp to share deep learning parameters within a group, which contains a roal as miner, a roal as official and several parties.
Parties upload encrypted parameters within the group using Paillier API generated by official, which are then be processed by the miner to become combined parameters. After that, the combined parameters will be downloaded by the parties and decrypted to continue their training procedures.
The contracts module defines the group and param contract that contains the attributes, commands and corresponding verification for transactions. Several flows defined in the cordapp module capture the features mentioned above. Additionally the cordapp also includes a basic web api to interact with a sample deployment.
- Party: Share their parameters
- Miner: Combine all shared result cipher
- Official: Generate Paillier API and is trustworthy
- party join or create a group
- official generate and send Paillier api parameters to parties
- party send param states to miner
- miners send the same updated param states to every party
- party send decrypt share to other parties
- party download decrypt share from other parties
// group state
{
groupId: uuid,
groupOwner: Party,
groupMember: List<Party>,
maxNum: int,
descrition: String,
untilTime: TimeWindow
}
// param state
{
// basic info
param: List<List<BigDecimal>>,
stateType: enum("param", "decrypt share")
sender: Party,
receiverList: List<Party>,
// control info
groupId: uuid,
stateId: uuid,
totalLen: int,
offset: int
}
// public and secret param state
{
// basic info
paramList: List<BigDecimal>,
privateKey: BigDecimal
owner: Party,
receiver: Party,
// control info
stateId: uuid,
groupId: uuid
}
// alpha and g param state
{
// basic info
alphaList: List<BigDecimal>,
gList: List<BigDecimal>,
owner: Party,
groupMembers: Party,
// control info
stateId: uuid,
groupId: uuid
}
You will need the following installed on your machine before you can start:
- JDK 8 installed and available on your path (Minimum version: 1.8_131).
- IntelliJ IDEA (Minimum version 2017.1)
- git
- Optional: h2 web console (download the "platform-independent zip")
For IDE, compilation and JVM version issues, see the Troubleshooting page on the Corda docsite.
To get started, clone this repository with:
git clone https://github.com/Patrickctyyx/deepchain-kotlin.git
And change directories to the newly cloned repo:
cd deepchain-kotlin
- Create Group Flow: creates a group state that are visible to the owner and the designated miner.
- Apply Group Flow: sends a message to the owner for the permission to join the group.
- Approve Group Flow: invoked by Apply Group Flow, approves the applicant's request and invokes a subflow to add the applicant to the state.
- Update Group Flow: updates the group state to add the applicant to the state.
- Send Alpha And G Param Flow: official send alpha and g param to all parties in the group.
- Send Public And Secret Param Flow: official send public and secret param to every party in the group respectively.
- PartyUploadFlow: parties send their params to the designated miner in the group.
- MinerUpdateFlowAuto: miner combine the params in the group and send them back to all the parties.
- CreateDecryptShareFlow: parties send their decrypt share flow to other parties in the group.
Unix:
./gradlew deployNodes
Windows:
gradlew.bat deployNodes
Note: You'll need to re-run this build step after making any changes to the cordapps for these to take effect on the node.
Once the build finishes, change directories to the folder where the newly built nodes are located:
cd build/nodes
The Gradle build script will have created a folder for each node. You'll
see three folders, one for each node and a runnodes
script. You can
run the nodes with:
Unix:
./runnodes --log-to-console --logging-level=DEBUG
Windows:
runnodes.bat --log-to-console --logging-level=DEBUG
You can also start each node individually by changing into the node's directory and running the corda jar.
java -jar corda.jar
You should now have three Corda nodes running on your machine serving the cordapps.
When the nodes have booted up, you should see a message like the following in the console:
Node started up and registered in 5.007 sec
Or you can build the CorDapp and run the nodes at the same time using this command:
Unix:
./run.sh
Windows:
run.bat
The runnodes
script starts up the webservers for each node. However, to
individually start up the web server, run the web server jar from the
node directory.
java -jar corda-webserver.jar
Run deepchain-kotlin\deepchain-cordapp\src\test\kotlin\com\deepchain\flows\DriverBasedProcedureTest.kt
,
of course you should change the file path to your own's.
Use a tool such as Postman or curl (command line), to view data as well as run the various flows.
You can check the identity of node for each webserver using the
identity
endpoint.
curl http://localhost:10007/api/info/identity
To see all peers in the network use:
curl http://localhost:10007/api/info/participants
To see available states in the node's vault use:
curl http://localhost:10007/api/group/vault
Here are sample commands for the flows:
Unix:
curl --header "Content-Type: application/json" --request POST --data '{ "miner": "Miner", "official": "Official", "maxNum": 2, "description": "Make me great again", "untilTime": "2558629725" }' http://localhost:10010/api/group/create-group
Windows:
curl --header "Content-Type: application/json" --request POST --data "{ \"miner\": \"Miner\", \"official\": \"Official\", \"maxNum\": 2, \"description\": \"Make me great again\", \"untilTime\": \"2558629725\" }" http://localhost:10010/api/group/create-group
You should see a message similar to one below:
Added a new group report for linear id 7acc52eb-84d5-4815-a45a-fc3d39dc6d69 in transaction FB6028B72BA14174F1E759AE601C001B0AEAAC59A4310336B6F1070DEDDD0A59 committed to ledger.
Unix:
curl --header "Content-Type: application/json" --request POST --data '{ "groupId" : "23562a68-51ba-412d-bd89-82c0f1405e1c", "ownerParty" : "O=Party B,L=Guangzhou,C=CN" }' http://localhost:10007/api/group/join-group
Windows:
curl --header "Content-Type: application/json" --request POST --data "{ \"groupId\" : \"23562a68-51ba-412d-bd89-82c0f1405e1c\", \"ownerParty\" : \"O=Party B,L=Guangzhou,C=CN\" }" http://localhost:10007/api/group/join-group
You should see a message similar to one below:
Join group successfully report for state id 23562a68-51ba-412d-bd89-82c0f1405e1c.
Approve Group Flow and Update Group Flow are invoked during the Apply Group Flow and will not be directly invoked using web apis.
curl --request GET http://localhost:10019/api/official/init?groupId=88e64231-3176-46d8-a176-efc8f3643b60
curl --request GET http://localhost:10007/api/param/encrypt-upload?filePath=C:\Users\lenovo\Desktop\deepchain-kotlin\data\worker 6\worker 2.txt&groupId=88e64231-3176-46d8-a176-efc8f3643b60
curl --request GET http://localhost:10013/api/param/download-update?groupId=88e64231-3176-46d8-a176-efc8f3643b60
curl --request GET http://localhost:10007/api/param/upload-share?groupId=88e64231-3176-46d8-a176-efc8f3643b60
curl --request GET http://localhost:10007/api/param/decrypt?groupId=88e64231-3176-46d8-a176-efc8f3643b60&?filePath=C:\Users\lenovo\Desktop\deepchain-kotlin\data\output\worker 1.txt
Final decrypted result is stored in the file path designated in this api.