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
63 lines (51 loc) · 1.73 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
package main
import (
"fmt"
"crypto/rand"
"github.com/lazyledger/lazyledger-prototype"
)
const namespaceSize = 8
func main() {
txAmounts := []int{128, 256, 384, 512, 640, 768, 896, 1024}
txSize := 128
for _, txes := range txAmounts {
sb := generateSimpleBlock(txes, txSize)
sbBandwidth := len(sb.PrevHash()) + len(sb.MessagesRoot()) + txSize * txes
pb := generateProbabilisticBlock(txes, txSize)
req, _ := pb.RequestSamples(10)
res := pb.RespondSamples(req)
pbBandwidth := 0
for _, root := range pb.RowRoots() {
pbBandwidth += len(root)
}
for _, root := range pb.ColumnRoots() {
pbBandwidth += len(root)
}
for _, proof := range res.Proofs {
for _, hash := range proof {
pbBandwidth += len(hash)
}
}
fmt.Println(txes, sbBandwidth, pbBandwidth)
}
}
func generateSimpleBlock(txes int, txSize int) *lazyledger.SimpleBlock {
txSize -= namespaceSize
sb := lazyledger.NewSimpleBlock([]byte{0})
for i := 0; i < txes; i++ {
messageData := make([]byte, txSize)
rand.Read(messageData)
sb.AddMessage(*lazyledger.NewMessage([namespaceSize]byte{0}, messageData))
}
return sb.(*lazyledger.SimpleBlock)
}
func generateProbabilisticBlock(txes int, txSize int) *lazyledger.ProbabilisticBlock {
pb := lazyledger.NewProbabilisticBlock([]byte{0}, txSize)
txSize -= namespaceSize + 2
for i := 0; i < txes; i++ {
messageData := make([]byte, txSize)
rand.Read(messageData)
pb.AddMessage(*lazyledger.NewMessage([namespaceSize]byte{0}, messageData))
}
return pb.(*lazyledger.ProbabilisticBlock)
}