-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (86 loc) · 2.56 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
package main
import (
"encoding/json"
"fmt"
air "github.com/airchains-network/svm-sequencer-node/airdb/air-leveldb"
"github.com/airchains-network/svm-sequencer-node/common"
"github.com/airchains-network/svm-sequencer-node/common/logs"
"github.com/airchains-network/svm-sequencer-node/handlers"
settlement_client "github.com/airchains-network/svm-sequencer-node/handlers/settlement-client"
"github.com/airchains-network/svm-sequencer-node/prover"
"github.com/airchains-network/svm-sequencer-node/types"
"os"
"sync"
"time"
)
func main() {
logs.LogMessage("INFO:", "Starting Solana Seq Indexer")
_, envError := common.ENVCheck()
if envError != "" {
logs.LogMessage("ERROR:", envError)
os.Exit(0)
}
dbStatus := air.InitDb()
if !dbStatus {
logs.LogMessage("ERROR:", "Error in initializing db")
os.Exit(0)
}
prover.CreateVkPk()
chainId := settlement_client.AddExecutionLayer()
if chainId == "nil" {
logs.LogMessage("ERROR:", "Something went wrong while adding execution layer")
logs.LogMessage("INFO:", "Retrying in 5 seconds...")
time.Sleep(5 * time.Second)
chainId = settlement_client.AddExecutionLayer()
} else if chainId == "exist" {
logs.LogMessage("INFO:", "Chain already exist")
}
ldt := air.GetTxDbInstance()
ldb := air.GetBlockDbInstance()
lds := air.GetStaticDbInstance()
ldbatch := air.GetBatchesDbInstance()
ldda := air.GetDaDbInstance()
da := types.DAStruct{
DAKey: "0",
DAClientName: "0",
BatchNumber: "0",
PreviousStateHash: "0",
CurrentStateHash: "0",
}
daBytes, err := json.Marshal(da)
_, err = ldda.Get([]byte("batch_0"), nil)
if err != nil {
err = ldda.Put([]byte("batch_0"), daBytes, nil)
if err != nil {
logs.LogMessage("ERROR:", fmt.Sprintf("Error in saving da in static db : %s", err.Error()))
os.Exit(0)
}
}
batchStartIndex, err := lds.Get([]byte("batchStartIndex"), nil)
if err != nil {
err = lds.Put([]byte("batchStartIndex"), []byte("0"), nil)
if err != nil {
logs.LogMessage("ERROR:", fmt.Sprintf("Error in saving batchStartIndex in static db : %s", err.Error()))
os.Exit(0)
}
}
_, err = lds.Get([]byte("batchCount"), nil)
if err != nil {
err = lds.Put([]byte("batchCount"), []byte("0"), nil)
if err != nil {
logs.LogMessage("ERROR:", fmt.Sprintf("Error in saving batchCount in static db : %s", err.Error()))
os.Exit(0)
}
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
handlers.BlockCheck(&wg, ldb, ldt)
}()
go func() {
defer wg.Done()
handlers.BatchGeneration(&wg, lds, ldt, ldbatch, ldda, batchStartIndex)
}()
wg.Wait()
}