-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
159 lines (144 loc) · 4.13 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
package main
import (
"flag"
"net/http"
_ "net/http/pprof"
"os"
"time"
logging "github.com/ipfs/go-log/v2"
"github.com/rs/cors"
"github.com/buidl-labs/filecoin-chain-indexer/chain"
"github.com/buidl-labs/filecoin-chain-indexer/config"
"github.com/buidl-labs/filecoin-chain-indexer/services"
"github.com/buidl-labs/filecoin-chain-indexer/util"
)
var log = logging.Logger("main")
func main() {
if err := logging.SetLogLevel("*", "debug"); err != nil {
log.Fatalf("set log level: %w", err)
}
if err := logging.SetLogLevel("rpc", "error"); err != nil {
log.Fatalf("set rpc log level: %w", err)
}
// if err := logging.SetLogLevel("bufbs", "error"); err != nil {
// log.Fatalf("set bufbs log level: %w", err)
// }
go func() {
log.Info(http.ListenAndServe(":6060", nil))
}()
// log.Infow("infoout of order tipsets",
// "height", 3,
// )
// log.Info("doin nothin")
// log.Infof("ksdjd %s", "skj")
// log.Debugw("debugout of order tipsets", "height", 1)
// log.Errorw("errorout of order tipsets", "height", 2)
go func() {
handler := cors.Default().Handler(http.FileServer(http.Dir(os.Getenv("SERVEDIR"))))
http.Handle("/", handler)
http.ListenAndServe(":80", handler)
}()
var command string
var sfrom int
var sto int
fromenv, _ := util.GetenvInt("FROM")
toenv, _ := util.GetenvInt("TO")
flag.StringVar(&command, "cmd", "", "Command to run")
flag.IntVar(&sfrom, "from", fromenv, "from height")
flag.IntVar(&sto, "to", toenv, "to height")
flag.Parse()
if command == "" {
log.Fatal("Please use a valid command")
}
epoch, _ := util.GetenvInt("EPOCH")
forever, _ := util.GetenvInt("FOREVER")
if sfrom == -1 {
log.Fatal("Please specify a valid FROM epoch")
}
if sto == -1 && forever != 1 {
log.Fatal("Please specify a valid TO epoch")
}
cfg := config.Config{
DBConnStr: os.Getenv("DB"),
FullNodeAPIInfo: os.Getenv("FULLNODE_API_INFO"),
CacheSize: 1, // TODO: Not using chain cache ATM
From: int64(sfrom),
To: int64(sto),
Miner: os.Getenv("MINERID"),
Epoch: int64(epoch),
IndexForever: forever,
}
log.Info("Starting filecoin-chain-indexer")
switch command {
case "migrate", "rollback":
err := services.RunMigrations(cfg, command)
if err != nil {
log.Fatal("Running migrations", err)
}
case chain.MinerTxnsTask:
minertxns := []string{chain.MinerTxnsTask}
start := time.Now()
log.Debugw("MinerTxnsTask", "start", start)
services.Walk(cfg, minertxns, chain.EPOCHS_RANGE, chain.MinerTxnsTask)
end := time.Now()
log.Debugw("MinerTxnsTask", "end", end)
diff := end.Sub(start)
log.Debugw("MinerTxnsTask", "total time", diff)
case chain.ActorCodesTask:
actorcodes := []string{chain.ActorCodesTask}
for {
services.Walk(cfg, actorcodes, chain.SINGLE_EPOCH, chain.ActorCodesTask)
}
case chain.MinersTask:
minr := []string{chain.MinersTask}
for {
services.Walk(cfg, minr, chain.SINGLE_EPOCH, chain.MinersTask)
}
case chain.BlocksTask:
blk := []string{chain.BlocksTask}
services.Walk(cfg, blk, chain.EPOCHS_RANGE, chain.BlocksTask)
ticker := time.NewTicker(6 * time.Hour)
for {
select {
case <-ticker.C:
services.Walk(cfg, blk, chain.EPOCHS_RANGE, chain.BlocksTask)
}
}
case chain.MessagesTask:
msg := []string{chain.MessagesTask}
services.Walk(cfg, msg, chain.EPOCHS_RANGE, chain.MessagesTask)
ticker := time.NewTicker(6 * time.Hour)
for {
select {
case <-ticker.C:
services.Walk(cfg, msg, chain.EPOCHS_RANGE, chain.MessagesTask)
}
}
case chain.MarketsTask:
mkt := []string{chain.MarketsTask}
services.Walk(cfg, mkt, chain.SINGLE_EPOCH, chain.MarketsTask)
ticker := time.NewTicker(3 * time.Hour)
for {
select {
case <-ticker.C:
services.Walk(cfg, mkt, chain.SINGLE_EPOCH, chain.MarketsTask)
}
}
// case "transform":
// services.Transform(cfg)
case "watchevents":
services.WatchEvents(cfg)
case "watchmarket":
services.WatchMarket(cfg)
case "insertcsv":
services.InsertTransformedMessages(cfg)
case "s3":
services.UploadS3()
case "partition":
services.Partition(cfg)
case "fixcsvs":
services.FixCsvs(cfg)
default:
log.Fatal("Please use a valid command")
}
}