Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ BlockBench comes with both [macro benchmark workloads](src/macro) for evaluating

* [libcurl](https://curl.haxx.se/libcurl/)

* Docker-Container
The `container` folder contains a Dockerfile that creates a Docker
container with all required C++ dependencies. You can use this Container
to build the kvstore workload

### Node.js libraries
Go to [micro](src/micro) directory and use `npm install` to install the dependency libraries
* [Web3.js](https://github.com/ethereum/web3.js/)
Expand All @@ -55,4 +60,4 @@ Go to [micro](src/micro) directory and use `npm install` to install the dependen
* [geth(ethereum)](https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Ubuntu)
* [geth(parity)](https://github.com/paritytech/parity/wiki/Setup)
* [geth(quorum)](https://github.com/jpmorganchase/quorum/wiki/Getting-Set-Up)
* [hyperledger](https://github.com/hyperledger/fabric/tree/v0.6)
* [hyperledger](https://github.com/hyperledger/fabric/tree/v0.6)
83 changes: 83 additions & 0 deletions benchmark/contracts/fabric-v1.4/analytic/analytic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package main

import (
"fmt"
"strconv"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

type Analytic struct {
}

var BALANCE int = 100000

func main() {
err := shim.Start(new(Analytic))
if err != nil {
fmt.Printf("Error starting Analytic: %s", err)
}
}

func (t *Analytic) Init(stub shim.ChaincodeStubInterface) pb.Response {
// nothing to do
return shim.Success(nil)
}

func (t *Analytic) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()

if function == "sendPayment" {
t.sendPayment(stub, args)
} else {
return shim.Error("Unrecognized function " + function)
}

return shim.Success(nil)
}

func (t *Analytic) sendPayment(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var bal1, bal2, amount int
var err error

bal_str1, err := stub.GetState(args[0])
if err != nil {
bal_str1 = []byte(strconv.Itoa(BALANCE))
}
bal_str2, err := stub.GetState(args[1])
if err != nil {
bal_str2 = []byte(strconv.Itoa(BALANCE))
}
amount, err = strconv.Atoi(args[2])

bal1, err = strconv.Atoi(string(bal_str1))
if err != nil {
bal1 = BALANCE
}
bal2, err = strconv.Atoi(string(bal_str2))
if err != nil {
bal2 = BALANCE
}
bal1 -= amount
bal2 += amount

err = stub.PutState(args[0], []byte(strconv.Itoa(bal1)))

if err != nil {
return shim.Error(err.Error())
}

err = stub.PutState(args[1], []byte(strconv.Itoa(bal2)))

if err != nil {
return shim.Error(err.Error())
}

err = stub.PutState("Value", []byte(args[2]))

if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}
27 changes: 27 additions & 0 deletions benchmark/contracts/fabric-v1.4/donothing/donothing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"fmt"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

type DoNothing struct {
}

func main() {
err := shim.Start(new(DoNothing))
if err != nil {
fmt.Printf("Error starting donothing: %s", err)
}
}

func (t *DoNothing) Init(stub shim.ChaincodeStubInterface) pb.Response {
// nothing to do
return shim.Success(nil)
}

func (t *DoNothing) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
122 changes: 122 additions & 0 deletions benchmark/contracts/fabric-v1.4/ioheavy/ioheavy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package main

import (
"fmt"
"strconv"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

const ZEROS = "00000000000000000000"
const ALPHABET = "abcdefghijklmnopqrstuvwxy#$%^&*()_+[]{}|;:,./<>?`~"

func gen_key(k int) string {
ret := strconv.Itoa(k)
ret = ZEROS[:20-len(ret)] + ret
return ret
}

func gen_val(k int) string {
char_pool := ALPHABET + ALPHABET + ALPHABET
return char_pool[(k % 50):(k%50 + 100)]
}

type IoHeavy struct {
}

func main() {
err := shim.Start(new(IoHeavy))
if err != nil {
fmt.Printf("Error starting IoHeavy tester: %s", err)
}
}

func (t *IoHeavy) Init(stub shim.ChaincodeStubInterface) pb.Response {
// nothing to do
return shim.Success(nil)
}

func (t *IoHeavy) Invoke(stub shim.ChaincodeStubInterface) pb.Response {

// write arg2 (k,v) from key arg1
functIoHeavyn, args := stub.GetFunctionAndParameters()
if functIoHeavyn == "write" {
return t.write(stub, args)
// scan arg2 value from key arg1
} else if functIoHeavyn == "read" {
return t.read(stub, args)
} else if functIoHeavyn == "scan" {
return t.scan(stub, args)
}

return shim.Error("Received unknown functIoHeavyn invocatIoHeavyn")
}

func (t *IoHeavy) write(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var start_key, num int
var err error

if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2. name of the key and value to set")
}

start_key, err = strconv.Atoi(args[0])
if err != nil {
return shim.Error(err.Error())
}
num, err = strconv.Atoi(args[1])
if err != nil {
return shim.Error(err.Error())
}
for i := 0; i < num; i++ {
err = stub.PutState(gen_key(start_key+i), []byte(gen_val(start_key+i)))
if err != nil {
return shim.Error(err.Error())
}
}
return shim.Success(nil)
}

func (t *IoHeavy) scan(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var start_key, num int
var err error

if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2. name of the key and value to set")
}

start_key, err = strconv.Atoi(args[0])
if err != nil {
return shim.Error(err.Error())
}
num, err = strconv.Atoi(args[1])
if err != nil {
return shim.Error(err.Error())
}
for i := 0; i < num; i++ {
_, err := stub.GetState(gen_key(start_key + i))
if err != nil {
return shim.Error(err.Error())
}
}
return shim.Success(nil)
}

func (t *IoHeavy) read(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var key, jsonResp string
var err error

if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting name of the key to query")
}

key = args[0]
valAsbytes, err := stub.GetState(key)
if err != nil {
jsonResp = "{\"Error\":\"Failed to get state for " + key + "\"}"
return shim.Error(jsonResp)
}

return shim.Success(valAsbytes)
}
87 changes: 87 additions & 0 deletions benchmark/contracts/fabric-v1.4/kvstore/kvstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package main

import (
"fmt"

"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)

type KVStore struct {
}

func main() {
err := shim.Start(new(KVStore))
if err != nil {
fmt.Printf("Error starting kv-store: %s", err)
}
}

// Init the kv-store
func (t *KVStore) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}

func (t *KVStore) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
if function == "write" {
return t.write(stub, args)
} else if function == "delete" {
return t.del(stub, args)
} else if function == "read" {
return t.read(stub, args)
}

return shim.Error("Received unknown function invocation")
}

func (t *KVStore) write(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var key, value string
var err error

if len(args) != 2 {
return shim.Error("Incorrect number of arguments. Expecting 2. name of the key and value to set")
}

key = args[0]
value = args[1]
err = stub.PutState(key, []byte(value))
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}

func (t *KVStore) del(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var key string
var err error

if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting name of the key to delete")
}

key = args[0]
err = stub.DelState(key)
if err != nil {
return shim.Error(err.Error())
}
return shim.Success(nil)
}

func (t *KVStore) read(stub shim.ChaincodeStubInterface, args []string) pb.Response {
var key, jsonResp string
var err error

if len(args) != 1 {
return shim.Error("Incorrect number of arguments. Expecting name of the key to query")
}

key = args[0]
valAsbytes, err := stub.GetState(key)
if err != nil {
jsonResp = "{\"Error\":\"Failed to get state for " + key + "\"}"
return shim.Error(jsonResp)
}

return shim.Success(valAsbytes)
}
Loading