Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
add measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
musalbas committed Apr 24, 2019
1 parent 66eca98 commit fff0a59
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app_registrar.go
Expand Up @@ -12,6 +12,7 @@ type Registrar struct {
state MapStore
currency *Currency
owner []byte
namespace [namespaceSize]byte
}

func NewRegistrar(state MapStore, currency *Currency, owner []byte) Application {
Expand Down Expand Up @@ -56,9 +57,17 @@ func (app *Registrar) ProcessMessage(message Message) {
}

func (app *Registrar) Namespace() [namespaceSize]byte {
var namespace [namespaceSize]byte
copy(namespace[:], append([]byte("reggie"), app.owner[:namespaceSize-6]...))
return namespace
var empty [namespaceSize]byte
if app.namespace == empty {
var namespace [namespaceSize]byte
copy(namespace[:], []byte("reggie"))
return namespace
}
return app.namespace
}

func (app *Registrar) SetNamespace(namespace [namespaceSize]byte) {
app.namespace = namespace
}

func (app *Registrar) SetBlockHead(hash []byte) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/lazyledger_measurements_2/main.go
Expand Up @@ -49,7 +49,7 @@ func main() {
}
}

fmt.Println(txes, sbBandwidthMax, pbBandwidthMax)
fmt.Println(txes*txSize, sbBandwidthMax, pbBandwidthMax)
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/lazyledger_measurements_4/.gitignore
@@ -0,0 +1 @@
lazyledger_measurements_4
150 changes: 150 additions & 0 deletions cmd/lazyledger_measurements_4/main.go
@@ -0,0 +1,150 @@
package main

import (
"crypto/rand"
"encoding/binary"
"fmt"

"github.com/musalbas/lazyledger-prototype"
"github.com/libp2p/go-libp2p-crypto"
)

const namespaceSize = 8

func main() {
registrarTxes := 10
txAmounts := []int{128, 256, 384, 512, 640, 768, 896, 1024}
txSize := 256
for _, txes := range txAmounts {
sbBandwidthMax := 0
pbBandwidthMax := 0

for i := 0; i < 10; i++ {
sb, cns, rns := generateSimpleBlock(registrarTxes, txes, txSize)
sbBandwidth := 0
_, _, proofs1, messages1, _ := sb.ApplicationProof(cns)
for _, msg := range *messages1 {
sbBandwidth += len(msg.Marshal())
}
for _, hash := range proofs1 {
sbBandwidth += len(hash)
}
if sbBandwidth > sbBandwidthMax {
sbBandwidthMax = sbBandwidth
}
_, _, proofs1, _, hashes1 := sb.ApplicationProof(rns)
for _, hash := range hashes1 {
sbBandwidth += len(hash)
}
for _, hash := range proofs1 {
sbBandwidth += len(hash)
}
if sbBandwidth > sbBandwidthMax {
sbBandwidthMax = sbBandwidth
}

pb, cns, rns := generateProbabilisticBlock(registrarTxes, txes, txSize)
_, _, proofs2, messages2, _ := pb.ApplicationProof(cns)
pbBandwidth := 0
for _, msg := range *messages2 {
pbBandwidth += len(msg.Marshal())
}
for _, proof := range proofs2 {
for _, hash := range proof {
pbBandwidth += len(hash)
}
}
_, _, proofs2, _, hashes2 := pb.ApplicationProof(rns)
for _, hash := range hashes2 {
pbBandwidth += len(hash)
}
for _, proof := range proofs2 {
for _, hash := range proof {
pbBandwidth += len(hash)
}
}
if pbBandwidth > pbBandwidthMax {
pbBandwidthMax = pbBandwidth
}
}

fmt.Println(txes, sbBandwidthMax, pbBandwidthMax)
}
}

func generateSimpleBlock(registrarTxes int, otherTxes, txSize int) (*lazyledger.SimpleBlock, [namespaceSize]byte, [namespaceSize]byte) {
txSize -= namespaceSize

bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)

sb := lazyledger.NewSimpleBlock([]byte{0})

ms1 := lazyledger.NewSimpleMap()
currencyApp := lazyledger.NewCurrency(ms1, b)
b.RegisterApplication(&currencyApp)

privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubBBytes, _ := pubB.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms1.Put(pubABytes, pubABalanceBytes)

ms2 := lazyledger.NewSimpleMap()
registrarApp := lazyledger.NewRegistrar(ms2, currencyApp.(*lazyledger.Currency), pubBBytes)
b.RegisterApplication(&registrarApp)

for i := 0; i < registrarTxes; i++ {
sb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}

ms3 := lazyledger.NewSimpleMap()
registrarApp2 := lazyledger.NewRegistrar(ms3, currencyApp.(*lazyledger.Currency), pubBBytes)
b.RegisterApplication(&registrarApp2)

for i := 0; i < otherTxes; i++ {
sb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}

return sb.(*lazyledger.SimpleBlock), currencyApp.Namespace(), registrarApp.Namespace()
}

func generateProbabilisticBlock(registrarTxes int, otherTxes, txSize int) (*lazyledger.ProbabilisticBlock, [namespaceSize]byte, [namespaceSize]byte) {
pb := lazyledger.NewProbabilisticBlock([]byte{0}, txSize)
txSize -= namespaceSize + 2

bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)

ms1 := lazyledger.NewSimpleMap()
currencyApp := lazyledger.NewCurrency(ms1, b)
b.RegisterApplication(&currencyApp)

privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubBBytes, _ := pubB.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms1.Put(pubABytes, pubABalanceBytes)

ms2 := lazyledger.NewSimpleMap()
registrarApp := lazyledger.NewRegistrar(ms2, currencyApp.(*lazyledger.Currency), pubBBytes)
b.RegisterApplication(&registrarApp)

for i := 0; i < registrarTxes; i++ {
pb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}

ms3 := lazyledger.NewSimpleMap()
registrarApp2 := lazyledger.NewRegistrar(ms3, currencyApp.(*lazyledger.Currency), pubBBytes)
b.RegisterApplication(&registrarApp2)

for i := 0; i < otherTxes; i++ {
pb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}

return pb.(*lazyledger.ProbabilisticBlock), currencyApp.Namespace(), registrarApp.Namespace()
}
1 change: 1 addition & 0 deletions cmd/lazyledger_measurements_5/.gitignore
@@ -0,0 +1 @@
lazyledger_measurements_5
178 changes: 178 additions & 0 deletions cmd/lazyledger_measurements_5/main.go
@@ -0,0 +1,178 @@
package main

import (
"crypto/rand"
"encoding/binary"
"fmt"

"github.com/musalbas/lazyledger-prototype"
"github.com/libp2p/go-libp2p-crypto"
)

const namespaceSize = 8

func main() {
registrarTxes := 10
txAmounts := []int{128, 256, 384, 512, 640, 768, 896, 1024}
txSize := 256
for _, txes := range txAmounts {
sbBandwidthMax := 0
pbBandwidthMax := 0

for i := 0; i < 10; i++ {
sb, cns, rns := generateSimpleBlock(registrarTxes, txes, txSize)
sbBandwidth := 0
_, _, proofs1, messages1, _ := sb.ApplicationProof(cns)
for _, msg := range *messages1 {
sbBandwidth += len(msg.Marshal())
}
for _, hash := range proofs1 {
sbBandwidth += len(hash)
}
if sbBandwidth > sbBandwidthMax {
sbBandwidthMax = sbBandwidth
}
_, _, proofs1, messages1, _ = sb.ApplicationProof(rns)
for _, msg := range *messages1 {
sbBandwidth += len(msg.Marshal())
}
for _, hash := range proofs1 {
sbBandwidth += len(hash)
}
if sbBandwidth > sbBandwidthMax {
sbBandwidthMax = sbBandwidth
}

pb, cns, rns := generateProbabilisticBlock(registrarTxes, txes, txSize)
_, _, proofs2, messages2, _ := pb.ApplicationProof(cns)
pbBandwidth := 0
for _, msg := range *messages2 {
pbBandwidth += len(msg.Marshal())
}
for _, proof := range proofs2 {
for _, hash := range proof {
pbBandwidth += len(hash)
}
}
_, _, proofs2, messages2, _ = pb.ApplicationProof(rns)
for _, msg := range *messages2 {
pbBandwidth += len(msg.Marshal())
}
for _, proof := range proofs2 {
for _, hash := range proof {
pbBandwidth += len(hash)
}
}
if pbBandwidth > pbBandwidthMax {
pbBandwidthMax = pbBandwidth
}
}

fmt.Println(txes, sbBandwidthMax, pbBandwidthMax)
}
}

func generateSimpleBlock(registrarTxes int, otherTxes, txSize int) (*lazyledger.SimpleBlock, [namespaceSize]byte, [namespaceSize]byte) {
txSize -= namespaceSize

bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)

sb := lazyledger.NewSimpleBlock([]byte{0})

ms1 := lazyledger.NewSimpleMap()
currencyApp := lazyledger.NewCurrency(ms1, b)
b.RegisterApplication(&currencyApp)

privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubC, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubBBytes, _ := pubB.Bytes()
pubCBytes, _ := pubC.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms1.Put(pubABytes, pubABalanceBytes)

ms2 := lazyledger.NewSimpleMap()
registrarApp := lazyledger.NewRegistrar(ms2, currencyApp.(*lazyledger.Currency), pubBBytes)
var rns1 [namespaceSize]byte
copy(rns1[:], []byte("reg1"))
registrarApp.(*lazyledger.Registrar).SetNamespace(rns1)
b.RegisterApplication(&registrarApp)
sb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 100000, nil))

for i := 0; i < registrarTxes; i++ {
name := make([]byte, 8)
rand.Read(name)
sb.AddMessage(registrarApp.(*lazyledger.Registrar).GenerateTransaction(privA, name))
}

ms3 := lazyledger.NewSimpleMap()
registrarApp2 := lazyledger.NewRegistrar(ms3, currencyApp.(*lazyledger.Currency), pubCBytes)
var rns2 [namespaceSize]byte
copy(rns2[:], []byte("reg2"))
registrarApp2.(*lazyledger.Registrar).SetNamespace(rns2)
b.RegisterApplication(&registrarApp2)
sb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubC, 100000, nil))

for i := 0; i < otherTxes; i++ {
name := make([]byte, 8)
rand.Read(name)
sb.AddMessage(registrarApp2.(*lazyledger.Registrar).GenerateTransaction(privA, name))
}

return sb.(*lazyledger.SimpleBlock), currencyApp.Namespace(), registrarApp.Namespace()
}

func generateProbabilisticBlock(registrarTxes int, otherTxes, txSize int) (*lazyledger.ProbabilisticBlock, [namespaceSize]byte, [namespaceSize]byte) {
pb := lazyledger.NewProbabilisticBlock([]byte{0}, txSize)
txSize -= namespaceSize + 2

bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)

ms1 := lazyledger.NewSimpleMap()
currencyApp := lazyledger.NewCurrency(ms1, b)
b.RegisterApplication(&currencyApp)

privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
_, pubC, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubBBytes, _ := pubB.Bytes()
pubCBytes, _ := pubC.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms1.Put(pubABytes, pubABalanceBytes)

ms2 := lazyledger.NewSimpleMap()
registrarApp := lazyledger.NewRegistrar(ms2, currencyApp.(*lazyledger.Currency), pubBBytes)
var rns1 [namespaceSize]byte
copy(rns1[:], []byte("reg1"))
registrarApp.(*lazyledger.Registrar).SetNamespace(rns1)
b.RegisterApplication(&registrarApp)
pb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 100000, nil))

for i := 0; i < registrarTxes; i++ {
name := make([]byte, 8)
rand.Read(name)
pb.AddMessage(registrarApp.(*lazyledger.Registrar).GenerateTransaction(privA, name))
}

ms3 := lazyledger.NewSimpleMap()
registrarApp2 := lazyledger.NewRegistrar(ms3, currencyApp.(*lazyledger.Currency), pubCBytes)
var rns2 [namespaceSize]byte
copy(rns2[:], []byte("reg2"))
registrarApp2.(*lazyledger.Registrar).SetNamespace(rns2)
b.RegisterApplication(&registrarApp2)
pb.AddMessage(currencyApp.(*lazyledger.Currency).GenerateTransaction(privA, pubC, 100000, nil))

for i := 0; i < otherTxes; i++ {
name := make([]byte, 8)
rand.Read(name)
pb.AddMessage(registrarApp2.(*lazyledger.Registrar).GenerateTransaction(privA, name))
}

return pb.(*lazyledger.ProbabilisticBlock), currencyApp.Namespace(), registrarApp.Namespace()
}

0 comments on commit fff0a59

Please sign in to comment.