-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain.go
168 lines (150 loc) · 4.54 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/flashbots/mempool-dumpster/collector"
"github.com/flashbots/mempool-dumpster/common"
"github.com/lithammer/shortuuid"
"github.com/urfave/cli/v2"
)
var (
version = "dev" // is set during build process
cliFlags = []cli.Flag{
// Collector configuration
&cli.BoolFlag{
Name: "debug",
EnvVars: []string{"DEBUG"},
Usage: "enable debug logging",
Category: "Collector Configuration",
},
&cli.StringFlag{
Name: "out",
EnvVars: []string{"OUT"},
Required: true,
Usage: "output base directory",
Category: "Collector Configuration",
},
&cli.StringFlag{
Name: "uid",
EnvVars: []string{"UID"},
Usage: "collector uid, part of output CSV filenames (default: random)",
Category: "Collector Configuration",
},
&cli.StringFlag{
Name: "check-node",
EnvVars: []string{"CHECK_NODE"},
Usage: "EL node URL to check incoming transactions",
Category: "Collector Configuration",
},
// Sources
&cli.StringSliceFlag{
Name: "node",
Aliases: []string{"nodes"},
EnvVars: []string{"NODE", "NODES"},
Usage: "EL node URL(s)",
Category: "Sources Configuration",
},
&cli.StringSliceFlag{
Name: "blx",
EnvVars: []string{"BLX_AUTH"},
Usage: "bloXroute auth-header (or auth-header@url)",
Category: "Sources Configuration",
},
&cli.StringSliceFlag{
Name: "eden",
EnvVars: []string{"EDEN_AUTH"},
Usage: "Eden auth-header (or auth-header@url)",
Category: "Sources Configuration",
},
&cli.StringSliceFlag{
Name: "chainbound",
EnvVars: []string{"CHAINBOUND_AUTH"},
Usage: "Chainbound API key (or api-key@url)",
Category: "Sources Configuration",
},
// Tx receivers
&cli.StringSliceFlag{
Name: "tx-receivers",
EnvVars: []string{"TX_RECEIVERS"},
Usage: "URL(s) to send transactions to as octet-stream over http",
Category: "Tx Receivers Configuration",
},
&cli.StringSliceFlag{
Name: "tx-receivers-allowed-sources",
EnvVars: []string{"TX_RECEIVERS_ALLOWED_SOURCES"},
Usage: "sources of txs to send to receivers",
Category: "Tx Receivers Configuration",
},
// SSE tx subscription
&cli.StringFlag{
Name: "api-listen-addr",
EnvVars: []string{"API_ADDR"},
Usage: "API listen address (host:port)",
Category: "Tx Receivers Configuration",
},
}
)
func main() {
app := &cli.App{
Name: "mempool-dumpster/collector",
Usage: "Collect mempool transactions from various sources",
Version: version,
Flags: cliFlags,
Action: runCollector,
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func runCollector(cCtx *cli.Context) error {
var (
debug = cCtx.Bool("debug")
outDir = cCtx.String("out")
uid = cCtx.String("uid")
checkNodeURI = cCtx.String("check-node")
nodeURIs = cCtx.StringSlice("node")
blxAuth = cCtx.StringSlice("blx")
edenAuth = cCtx.StringSlice("eden")
chainboundAuth = cCtx.StringSlice("chainbound")
receivers = cCtx.StringSlice("tx-receivers")
receiversAllowedSources = cCtx.StringSlice("tx-receivers-allowed-sources")
apiListenAddr = cCtx.String("api-listen-addr")
)
// Logger setup
log := common.GetLogger(debug, false)
defer func() { _ = log.Sync() }()
if uid == "" {
uid = shortuuid.New()[:6]
}
if len(nodeURIs) == 0 && len(blxAuth) == 0 && len(edenAuth) == 0 && len(chainboundAuth) == 0 {
log.Fatal("No nodes, bloxroute, or eden token set (use -nodes <url1>,<url2> / -blx-token <token> / -eden-token <token>)")
}
log.Infow("Starting mempool-collector", "version", version, "outDir", outDir, "uid", uid)
aliases := common.SourceAliasesFromEnv()
if len(aliases) > 0 {
log.Infow("Using source aliases:", "aliases", aliases)
}
// Start service components
opts := collector.CollectorOpts{
Log: log,
UID: uid,
OutDir: outDir,
CheckNodeURI: checkNodeURI,
Nodes: nodeURIs,
BloxrouteAuth: blxAuth,
EdenAuth: edenAuth,
ChainboundAuth: chainboundAuth,
Receivers: receivers,
ReceiversAllowedSources: receiversAllowedSources,
APIListenAddr: apiListenAddr,
}
collector.Start(&opts)
// Wait for termination signal
exit := make(chan os.Signal, 1)
signal.Notify(exit, os.Interrupt, syscall.SIGTERM)
<-exit
log.Info("bye")
return nil
}