-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
120 lines (103 loc) · 2.96 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
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"sync"
"time"
air "github.com/airchains-network/evm-sequencer-node/airdb/air-leveldb"
"github.com/airchains-network/evm-sequencer-node/common"
"github.com/airchains-network/evm-sequencer-node/common/logs"
"github.com/airchains-network/evm-sequencer-node/handlers"
settlement_client "github.com/airchains-network/evm-sequencer-node/handlers/settlement-client"
"github.com/airchains-network/evm-sequencer-node/prover"
"github.com/airchains-network/evm-sequencer-node/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/joho/godotenv"
)
func main() {
logs.Log.Info("Starting EVM Sequencer")
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
daClientRPC := os.Getenv("DA_CLIENT_RPC")
if daClientRPC == "" {
logs.Log.Error("Please set all the environment variables")
os.Exit(0)
}
ctx := context.Background()
dbStatus := air.InitDb()
if !dbStatus {
logs.Log.Error("Error in initializing db")
os.Exit(0)
}
prover.CreateVkPk()
chainId := settlement_client.AddExecutionLayer()
if chainId == "nil" {
logs.Log.Error("Something went wrong while adding execution layer")
logs.Log.Warn("Retrying in 5 seconds...")
time.Sleep(5 * time.Second)
_ = settlement_client.AddExecutionLayer()
} else if chainId == "exist" {
logs.Log.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)
if err != nil {
logs.Log.Error(fmt.Sprintf("Error in marshalling da : %s", err.Error()))
os.Exit(0)
}
_, err = ldda.Get([]byte("batch_0"), nil)
if err != nil {
err = ldda.Put([]byte("batch_0"), daBytes, nil)
if err != nil {
logs.Log.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.Log.Error(fmt.Sprintf("Error in saving batchStartIndex in static db : %s", err.Error()))
os.Exit(0)
}
}
client, err := ethclient.Dial(common.ExecutionClientRPC)
if err != nil {
log.Fatal("Failed to connect to the Ethereum client:", err)
}
_, err = lds.Get([]byte("batchCount"), nil)
if err != nil {
err = lds.Put([]byte("batchCount"), []byte("0"), nil)
if err != nil {
logs.Log.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, ctx, client, ldb, ldt)
}()
go func() {
defer wg.Done()
handlers.BatchGeneration(&wg, client, ctx, lds, ldt, ldbatch, ldda, batchStartIndex)
}()
wg.Wait()
}