forked from Hyperledger-TWGC/tape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (65 loc) · 1.91 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
package main
import (
"fmt"
"os"
"strconv"
"time"
"github.com/guoger/stupid/infra"
log "github.com/sirupsen/logrus"
)
const loglevel = "STUPID_LOGLEVEL"
func main() {
logger := log.New()
logger.SetLevel(log.WarnLevel)
if customerLevel, customerSet := os.LookupEnv(loglevel); customerSet {
if lvl, err := log.ParseLevel(customerLevel); err == nil {
logger.SetLevel(lvl)
}
}
if len(os.Args) != 3 {
fmt.Printf("Usage: stupid config.yaml 500\n")
os.Exit(1)
}
config := infra.LoadConfig(os.Args[1])
N, err := strconv.Atoi(os.Args[2])
if err != nil {
panic(err)
}
crypto := config.LoadCrypto()
raw := make(chan *infra.Elements, 100)
signed := make([]chan *infra.Elements, len(config.Endorsers))
processed := make(chan *infra.Elements, 10)
envs := make(chan *infra.Elements, 10)
done := make(chan struct{})
assember := &infra.Assembler{Signer: crypto}
for i := 0; i < len(config.Endorsers); i++ {
signed[i] = make(chan *infra.Elements, 10)
}
for i := 0; i < 5; i++ {
go assember.StartSigner(raw, signed, done)
go assember.StartIntegrator(processed, envs, done)
}
proposor := infra.CreateProposers(config.NumOfConn, config.ClientPerConn, config.Endorsers, crypto, logger)
proposor.Start(signed, processed, done, config)
broadcaster := infra.CreateBroadcasters(config.NumOfConn, config.Orderer.Addr, crypto, logger)
broadcaster.Start(envs, done)
observer := infra.CreateObserver(config.Committer.Addr, config.Channel, crypto, logger)
start := time.Now()
go observer.Start(N, start)
for i := 0; i < N; i++ {
prop := infra.CreateProposal(
crypto,
config.Channel,
config.Chaincode,
config.Version,
config.Args...,
)
raw <- &infra.Elements{Proposal: prop}
}
observer.Wait()
duration := time.Since(start)
close(done)
logger.Infof("Completed processing transactions.")
fmt.Printf("tx: %d, duration: %+v, tps: %f\n", N, duration, float64(N)/duration.Seconds())
os.Exit(0)
}