-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
124 lines (116 loc) · 2.66 KB
/
main.go
File metadata and controls
124 lines (116 loc) · 2.66 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"fmt"
"log"
"os"
"strings"
"sync"
"time"
"github.com/shutter-network/nethermind-tests/config"
"github.com/shutter-network/nethermind-tests/tests"
"github.com/shutter-network/nethermind-tests/utils"
"github.com/shutter-network/nethermind-tests/continuous"
)
func main() {
var modes []string
var cfg config.Config
if len(os.Args[1:]) == 0 {
cfg := config.LoadConfig()
log.Println(cfg.Mode)
mode := cfg.Mode
modes = strings.Split(mode, ",")
} else {
modes = []string{os.Args[1]}
}
utils.EnableExtLoggingFile()
var wg sync.WaitGroup
for _, m := range modes {
switch m {
case "chiado":
wg.Add(1)
go func() {
tests.RunChiadoTransactions(cfg)
wg.Done()
}()
case "gnosis":
wg.Add(1)
go func() {
tests.RunGnosisTransactions(cfg)
wg.Done()
}()
case "send-wait":
wg.Add(1)
go func() {
tests.RunSendAndWaitTest(cfg)
wg.Done()
}()
case "continuous":
wg.Add(1)
go func() {
runContinuous("standard")
wg.Done()
}()
case "continuous-graffiti":
wg.Add(1)
go func() {
runContinuous("graffiti")
wg.Done()
}()
case "collect":
wg.Add(1)
if len(os.Args[2:]) != 2 {
log.Fatalf("Usage: %v %v start-block end-block", os.Args[0], os.Args[1])
}
go func() {
runCollector()
wg.Done()
}()
default:
log.Printf("Unknown mode: %s", m)
}
}
wg.Wait()
}
func runContinuous(mode string) {
cfg, err := continuous.Setup(mode)
if err != nil {
panic(err)
}
// todo: make a global new block subscriber, that will be used by all waiting functions
// this will allow to reduce the number of calls to `eth_subscribe`
fmt.Println("Running continous tx tests...")
lastStats := time.Now().Unix()
cache := continuous.BlockCache{}
go continuous.PrimeBlockCache(&cache, &cfg)
startBlock := uint64(0)
blocks := make(chan continuous.ShutterBlock)
go continuous.QueryAllShutterBlocks(blocks, &cfg, mode)
for block := range blocks {
if startBlock == 0 {
startBlock = uint64(block.Number)
}
continuous.CheckTxInFlight(block.Number, &cfg)
continuous.SendShutterizedTX(block.Number, block.Ts, block.TargetedSlot, &cfg)
now := time.Now().Unix()
if now-lastStats > 12 {
log.Println("running stats")
lastStats = now
err = continuous.CollectContinuousTestStats(startBlock, uint64(block.Number), &cache, &cfg)
if err != nil {
log.Println(err)
}
}
}
}
func runCollector() {
start, end := utils.CollectBlockRangeFromArgs()
cfg, err := continuous.Setup("collect")
if err != nil {
log.Fatal(err)
}
cache := continuous.BlockCache{}
err = continuous.CollectContinuousTestStats(start, end, &cache, &cfg)
if err != nil {
log.Fatal(err)
}
}