2023-10-14 04:05:44 +00:00
|
|
|
|
//go:build !js && !wasm
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
2023-09-25 02:43:35 +00:00
|
|
|
|
"io/fs"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"os"
|
|
|
|
|
"os/signal"
|
2023-09-25 02:43:35 +00:00
|
|
|
|
"path/filepath"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p/core/crypto"
|
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
|
|
|
|
"github.com/pkg/errors"
|
2023-09-03 23:47:09 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/app"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/config"
|
2023-09-25 02:43:35 +00:00
|
|
|
|
qcrypto "source.quilibrium.com/quilibrium/monorepo/node/crypto"
|
2023-09-27 09:05:39 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/execution/ceremony/application"
|
2023-10-09 04:52:19 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/rpc"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
2023-09-09 23:45:47 +00:00
|
|
|
|
configDirectory = flag.String(
|
|
|
|
|
"config",
|
2024-01-03 07:31:42 +00:00
|
|
|
|
filepath.Join(".", ".config"),
|
2023-09-09 23:45:47 +00:00
|
|
|
|
"the configuration directory",
|
|
|
|
|
)
|
|
|
|
|
importPrivKey = flag.String(
|
|
|
|
|
"import-priv-key",
|
|
|
|
|
"",
|
|
|
|
|
"creates a new config using a specific key from the phase one ceremony",
|
|
|
|
|
)
|
|
|
|
|
dbConsole = flag.Bool(
|
|
|
|
|
"db-console",
|
|
|
|
|
false,
|
|
|
|
|
"starts the node in database console mode",
|
|
|
|
|
)
|
2023-08-21 03:50:38 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
if *importPrivKey != "" {
|
|
|
|
|
config, err := config.LoadConfig(*configDirectory, *importPrivKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printPeerID(config.P2P)
|
|
|
|
|
fmt.Println("Import completed, you are ready for the launch.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
done := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
|
|
2023-11-27 02:51:46 +00:00
|
|
|
|
if !*dbConsole {
|
|
|
|
|
printLogo()
|
|
|
|
|
printVersion()
|
|
|
|
|
fmt.Println(" ")
|
|
|
|
|
}
|
2023-08-21 03:50:38 +00:00
|
|
|
|
|
2023-09-03 23:47:09 +00:00
|
|
|
|
nodeConfig, err := config.LoadConfig(*configDirectory, "")
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 02:43:35 +00:00
|
|
|
|
clearIfTestData(*configDirectory, nodeConfig)
|
2023-09-27 09:05:39 +00:00
|
|
|
|
migrate(*configDirectory, nodeConfig)
|
2023-09-25 02:43:35 +00:00
|
|
|
|
|
2023-09-09 23:45:47 +00:00
|
|
|
|
if *dbConsole {
|
|
|
|
|
console, err := app.NewDBConsole(nodeConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.Run()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 02:43:35 +00:00
|
|
|
|
fmt.Println("Loading ceremony state and starting node...")
|
|
|
|
|
qcrypto.Init()
|
|
|
|
|
|
2023-09-03 23:47:09 +00:00
|
|
|
|
node, err := app.NewNode(nodeConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2023-10-09 04:52:19 +00:00
|
|
|
|
|
|
|
|
|
if nodeConfig.ListenGRPCMultiaddr != "" {
|
|
|
|
|
srv, err := rpc.NewRPCServer(
|
|
|
|
|
nodeConfig.ListenGRPCMultiaddr,
|
|
|
|
|
nodeConfig.ListenRestMultiaddr,
|
|
|
|
|
node.GetLogger(),
|
|
|
|
|
node.GetClockStore(),
|
2023-10-28 02:23:55 +00:00
|
|
|
|
node.GetKeyManager(),
|
2023-10-09 04:52:19 +00:00
|
|
|
|
node.GetPubSub(),
|
|
|
|
|
node.GetExecutionEngines(),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
err := srv.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-03 23:47:09 +00:00
|
|
|
|
node.Start()
|
|
|
|
|
|
|
|
|
|
<-done
|
|
|
|
|
node.Stop()
|
2023-08-21 03:50:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 02:43:35 +00:00
|
|
|
|
func clearIfTestData(configDir string, nodeConfig *config.Config) {
|
|
|
|
|
_, err := os.Stat(filepath.Join(configDir, "RELEASE_VERSION"))
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
fmt.Println("Clearing test data...")
|
|
|
|
|
err := os.RemoveAll(nodeConfig.DB.Path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
versionFile, err := os.OpenFile(
|
|
|
|
|
filepath.Join(configDir, "RELEASE_VERSION"),
|
|
|
|
|
os.O_CREATE|os.O_RDWR,
|
|
|
|
|
fs.FileMode(0700),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = versionFile.Write([]byte{0x01, 0x00, 0x00})
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = versionFile.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-27 09:05:39 +00:00
|
|
|
|
func migrate(configDir string, nodeConfig *config.Config) {
|
|
|
|
|
_, err := os.Stat(filepath.Join(configDir, "MIGRATIONS"))
|
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
|
fmt.Println("Deduplicating and compressing clock frame data...")
|
|
|
|
|
clock, err := app.NewClockStore(nodeConfig)
|
|
|
|
|
if err := clock.Deduplicate(application.CEREMONY_ADDRESS); err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
migrationFile, err := os.OpenFile(
|
|
|
|
|
filepath.Join(configDir, "MIGRATIONS"),
|
|
|
|
|
os.O_CREATE|os.O_RDWR,
|
|
|
|
|
fs.FileMode(0700),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = migrationFile.Write([]byte{0x00, 0x00, 0x01})
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = migrationFile.Close()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
func printPeerID(p2pConfig *config.P2PConfig) {
|
|
|
|
|
peerPrivKey, err := hex.DecodeString(p2pConfig.PeerPrivKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
privKey, err := crypto.UnmarshalEd448PrivateKey(peerPrivKey)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(errors.Wrap(err, "error unmarshaling peerkey"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub := privKey.GetPublic()
|
|
|
|
|
id, err := peer.IDFromPublicKey(pub)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(errors.Wrap(err, "error getting peer id"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("Peer ID: " + id.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printLogo() {
|
|
|
|
|
fmt.Println(" %#########")
|
|
|
|
|
fmt.Println(" #############################")
|
|
|
|
|
fmt.Println(" ########################################&")
|
|
|
|
|
fmt.Println(" ###############################################")
|
|
|
|
|
fmt.Println(" &#####################% %######################")
|
|
|
|
|
fmt.Println(" ################# #################")
|
|
|
|
|
fmt.Println(" ############### ###############")
|
|
|
|
|
fmt.Println(" ############# ##############")
|
|
|
|
|
fmt.Println(" ############# ############&")
|
|
|
|
|
fmt.Println(" ############ ############")
|
|
|
|
|
fmt.Println(" ########### ########## &###########")
|
|
|
|
|
fmt.Println(" ########### ############## ###########")
|
|
|
|
|
fmt.Println(" ########### ############## ##########&")
|
|
|
|
|
fmt.Println(" ########## ############## ##########")
|
|
|
|
|
fmt.Println("%########## ########## ##########")
|
|
|
|
|
fmt.Println("##########& ##########")
|
|
|
|
|
fmt.Println("########## &#########")
|
|
|
|
|
fmt.Println("##########& ####### ####### ##########")
|
|
|
|
|
fmt.Println(" ########## &######################### ##########")
|
|
|
|
|
fmt.Println(" ########## ##############% ############## &##########")
|
|
|
|
|
fmt.Println(" %########## &############## ############### ##########")
|
|
|
|
|
fmt.Println(" ########### ############### ##############% ###########")
|
|
|
|
|
fmt.Println(" ###########& ########## ############### ########")
|
|
|
|
|
fmt.Println(" ############ ##### ##############% ####")
|
|
|
|
|
fmt.Println(" ############ ###############")
|
|
|
|
|
fmt.Println(" ############## ##############%")
|
|
|
|
|
fmt.Println(" ############### ###############")
|
|
|
|
|
fmt.Println(" #################& ##############%")
|
|
|
|
|
fmt.Println(" #########################&&&############# ###############")
|
|
|
|
|
fmt.Println(" ########################################% ############")
|
|
|
|
|
fmt.Println(" ####################################### ########")
|
|
|
|
|
fmt.Println(" ############################# ##")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printVersion() {
|
|
|
|
|
fmt.Println(" ")
|
2024-01-04 04:45:25 +00:00
|
|
|
|
fmt.Println(" Quilibrium Node - v1.2.1 – Dawn")
|
2023-08-21 03:50:38 +00:00
|
|
|
|
}
|