This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"crypto/rand" | ||
|
||
"github.com/musalbas/lazyledger-prototype" | ||
) | ||
|
||
const namespaceSize = 8 | ||
|
||
func main() { | ||
txAmounts := []int{128, 2048} | ||
txSize := 128 | ||
for _, txes := range txAmounts { | ||
sb := generateSimpleBlock(txes, 128) | ||
sbBandwidth := len(sb.PrevHash()) + len(sb.MessagesRoot()) + txSize * txes | ||
|
||
pb := generateProbabilisticBlock(txes, 128) | ||
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 { | ||
txSize -= namespaceSize + 2 | ||
pb := lazyledger.NewProbabilisticBlock([]byte{0}, 128) | ||
|
||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters