This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
108 lines (87 loc) · 3.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"crypto/rand"
"encoding/binary"
"fmt"
"github.com/lazyledger/lazyledger-prototype"
"github.com/libp2p/go-libp2p-crypto"
)
const namespaceSize = 8
func main() {
currencyTxes := 10
txAmounts := []int{128, 256, 384, 512, 640, 768, 896, 1024}
txSize := 1024
for _, txes := range txAmounts {
_, c, d := generateSimpleBlock(currencyTxes, txes, txSize)
sbStoragec := c.StorageSize()
sbStoraged := d.StorageSize()
//_, c, d = generateProbabilisticBlock(currencyTxes, txes, txSize)
//pbStoragec := c.StorageSize()
//pbStoraged := d.StorageSize()
fmt.Println(txes, sbStoragec, sbStoraged)//, pbStoragec, pbStoraged)
}
}
func generateSimpleBlock(currencyTxes int, otherTxes, txSize int) (*lazyledger.SimpleBlock, *lazyledger.Currency, *lazyledger.DummyApp) {
bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)
sb := lazyledger.NewSimpleBlock([]byte{0})
ms := lazyledger.NewSimpleMap()
app := lazyledger.NewCurrency(ms, b)
b.RegisterApplication(&app)
ms2 := lazyledger.NewSimpleMap()
app2 := lazyledger.NewDummyApp(ms2)
b.RegisterApplication(&app2)
privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms.Put(pubABytes, pubABalanceBytes)
for i := 0; i < currencyTxes; i++ {
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
sb.AddMessage(app.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}
for i := 0; i < otherTxes; i++ {
k := make([]byte, txSize / 2)
v := make([]byte, txSize / 2)
puts := make(map[string]string)
rand.Read(k)
rand.Read(v)
puts[string(k)] = string(v)
t := app2.(*lazyledger.DummyApp).GenerateTransaction(puts)
sb.AddMessage(t)
}
b.ProcessBlock(sb)
return sb.(*lazyledger.SimpleBlock), app.(*lazyledger.Currency), app2.(*lazyledger.DummyApp)
}
func generateProbabilisticBlock(currencyTxes int, otherTxes, txSize int) (*lazyledger.ProbabilisticBlock, *lazyledger.Currency, *lazyledger.DummyApp) {
pb := lazyledger.NewProbabilisticBlock([]byte{0}, txSize+20)
bs := lazyledger.NewSimpleBlockStore()
b := lazyledger.NewBlockchain(bs)
ms := lazyledger.NewSimpleMap()
app := lazyledger.NewCurrency(ms, b)
b.RegisterApplication(&app)
privA, pubA, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pubABytes, _ := pubA.Bytes()
pubABalanceBytes := make([]byte, binary.MaxVarintLen64)
binary.BigEndian.PutUint64(pubABalanceBytes, 1000000)
ms.Put(pubABytes, pubABalanceBytes)
ms2 := lazyledger.NewSimpleMap()
app2 := lazyledger.NewDummyApp(ms2)
b.RegisterApplication(&app2)
for i := 0; i < currencyTxes; i++ {
_, pubB, _ := crypto.GenerateSecp256k1Key(rand.Reader)
pb.AddMessage(app.(*lazyledger.Currency).GenerateTransaction(privA, pubB, 1, nil))
}
for i := 0; i < otherTxes; i++ {
k := make([]byte, txSize / 2)
v := make([]byte, txSize / 2)
puts := make(map[string]string)
rand.Read(k)
rand.Read(v)
puts[string(k)] = string(v)
t := app2.(*lazyledger.DummyApp).GenerateTransaction(puts)
pb.AddMessage(t)
}
b.ProcessBlock(pb)
return pb.(*lazyledger.ProbabilisticBlock), app.(*lazyledger.Currency), app2.(*lazyledger.DummyApp)
}