2023-10-14 04:05:44 +00:00
|
|
|
|
//go:build !js && !wasm
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-25 05:22:50 +00:00
|
|
|
|
"bytes"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"encoding/binary"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"encoding/hex"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
2023-09-25 02:43:35 +00:00
|
|
|
|
"io/fs"
|
2024-02-19 00:28:29 +00:00
|
|
|
|
"log"
|
2024-06-08 11:32:45 +00:00
|
|
|
|
"math/big"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"os"
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
"os/exec"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"os/signal"
|
2023-09-25 02:43:35 +00:00
|
|
|
|
"path/filepath"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"runtime"
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
rdebug "runtime/debug"
|
2024-02-19 00:28:29 +00:00
|
|
|
|
"runtime/pprof"
|
2024-03-24 08:11:58 +00:00
|
|
|
|
"strconv"
|
2024-05-25 05:22:50 +00:00
|
|
|
|
"strings"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"syscall"
|
2024-02-19 00:28:29 +00:00
|
|
|
|
"time"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"go.uber.org/zap"
|
2024-05-25 05:22:50 +00:00
|
|
|
|
"golang.org/x/crypto/sha3"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"google.golang.org/protobuf/proto"
|
2024-02-14 07:11:12 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/utils"
|
2024-02-14 07:11:12 +00:00
|
|
|
|
|
2024-05-25 05:22:50 +00:00
|
|
|
|
"github.com/cloudflare/circl/sign/ed448"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"github.com/libp2p/go-libp2p/core/crypto"
|
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
"github.com/pbnjay/memory"
|
2023-08-21 03:50:38 +00:00
|
|
|
|
"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"
|
2024-03-01 07:12:31 +00:00
|
|
|
|
qcrypto "source.quilibrium.com/quilibrium/monorepo/node/crypto"
|
2024-02-13 07:04:56 +00:00
|
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/crypto/kzg"
|
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",
|
|
|
|
|
)
|
2024-01-29 21:11:40 +00:00
|
|
|
|
balance = flag.Bool(
|
|
|
|
|
"balance",
|
|
|
|
|
false,
|
|
|
|
|
"print the node's confirmed token balance to stdout and exit",
|
2023-09-09 23:45:47 +00:00
|
|
|
|
)
|
|
|
|
|
dbConsole = flag.Bool(
|
|
|
|
|
"db-console",
|
|
|
|
|
false,
|
|
|
|
|
"starts the node in database console mode",
|
|
|
|
|
)
|
2024-01-29 21:11:40 +00:00
|
|
|
|
importPrivKey = flag.String(
|
|
|
|
|
"import-priv-key",
|
|
|
|
|
"",
|
|
|
|
|
"creates a new config using a specific key from the phase one ceremony",
|
|
|
|
|
)
|
2024-01-04 22:48:00 +00:00
|
|
|
|
peerId = flag.Bool(
|
|
|
|
|
"peer-id",
|
|
|
|
|
false,
|
|
|
|
|
"print the peer id to stdout from the config and exit",
|
|
|
|
|
)
|
2024-03-23 20:26:57 +00:00
|
|
|
|
cpuprofile = flag.String(
|
|
|
|
|
"cpuprofile",
|
|
|
|
|
"",
|
|
|
|
|
"write cpu profile to file",
|
|
|
|
|
)
|
2024-02-19 00:28:29 +00:00
|
|
|
|
memprofile = flag.String(
|
|
|
|
|
"memprofile",
|
|
|
|
|
"",
|
|
|
|
|
"write memory profile after 20m to this file",
|
|
|
|
|
)
|
2024-03-24 08:11:58 +00:00
|
|
|
|
nodeInfo = flag.Bool(
|
|
|
|
|
"node-info",
|
|
|
|
|
false,
|
|
|
|
|
"print node related information",
|
|
|
|
|
)
|
2024-03-27 08:50:52 +00:00
|
|
|
|
debug = flag.Bool(
|
|
|
|
|
"debug",
|
|
|
|
|
false,
|
|
|
|
|
"sets log output to debug (verbose)",
|
|
|
|
|
)
|
2024-04-23 01:38:20 +00:00
|
|
|
|
dhtOnly = flag.Bool(
|
|
|
|
|
"dht-only",
|
|
|
|
|
false,
|
|
|
|
|
"sets a node to run strictly as a dht bootstrap peer (not full node)",
|
|
|
|
|
)
|
2024-05-25 05:22:50 +00:00
|
|
|
|
network = flag.Uint(
|
|
|
|
|
"network",
|
|
|
|
|
0,
|
|
|
|
|
"sets the active network for the node (mainnet = 0, primary testnet = 1)",
|
|
|
|
|
)
|
|
|
|
|
signatureCheck = flag.Bool(
|
|
|
|
|
"signature-check",
|
2024-06-08 11:32:45 +00:00
|
|
|
|
signatureCheckDefault(),
|
|
|
|
|
"enables or disables signature validation (default true or value of QUILIBRIUM_SIGNATURE_CHECK env var)",
|
2024-05-25 05:22:50 +00:00
|
|
|
|
)
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
core = flag.Int(
|
|
|
|
|
"core",
|
|
|
|
|
0,
|
|
|
|
|
"specifies the core of the process (defaults to zero, the initial launcher)",
|
|
|
|
|
)
|
|
|
|
|
parentProcess = flag.Int(
|
|
|
|
|
"parent-process",
|
|
|
|
|
0,
|
|
|
|
|
"specifies the parent process pid for a data worker",
|
|
|
|
|
)
|
2024-06-21 17:46:36 +00:00
|
|
|
|
integrityCheck = flag.Bool(
|
|
|
|
|
"integrity-check",
|
|
|
|
|
false,
|
|
|
|
|
"runs an integrity check on the store, helpful for confirming backups are not corrupted (defaults to false)",
|
|
|
|
|
)
|
2023-08-21 03:50:38 +00:00
|
|
|
|
)
|
|
|
|
|
|
2024-06-08 11:32:45 +00:00
|
|
|
|
func signatureCheckDefault() bool {
|
|
|
|
|
envVarValue, envVarExists := os.LookupEnv("QUILIBRIUM_SIGNATURE_CHECK")
|
|
|
|
|
if envVarExists {
|
|
|
|
|
def, err := strconv.ParseBool(envVarValue)
|
|
|
|
|
if err == nil {
|
|
|
|
|
return def
|
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("Invalid environment variable QUILIBRIUM_SIGNATURE_CHECK, must be 'true' or 'false'. Got: " + envVarValue)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
2024-05-25 05:22:50 +00:00
|
|
|
|
if *signatureCheck {
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
fmt.Println("Signature check not available for windows yet, skipping...")
|
|
|
|
|
} else {
|
|
|
|
|
ex, err := os.Executable()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err := os.ReadFile(ex)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(
|
|
|
|
|
"Error encountered during signature check – are you running this " +
|
|
|
|
|
"from source? (use --signature-check=false)",
|
|
|
|
|
)
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checksum := sha3.Sum256(b)
|
|
|
|
|
digest, err := os.ReadFile(ex + ".dgst")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Digest file not found")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parts := strings.Split(string(digest), " ")
|
|
|
|
|
if len(parts) != 2 {
|
|
|
|
|
fmt.Println("Invalid digest file format")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
digestBytes, err := hex.DecodeString(parts[1][:64])
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Invalid digest file format")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !bytes.Equal(checksum[:], digestBytes) {
|
|
|
|
|
fmt.Println("Invalid digest for node")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
count := 0
|
|
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
|
for i := 1; i <= len(config.Signatories); i++ {
|
2024-05-25 05:22:50 +00:00
|
|
|
|
signatureFile := fmt.Sprintf(ex+".dgst.sig.%d", i)
|
|
|
|
|
sig, err := os.ReadFile(signatureFile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
|
pubkey, _ := hex.DecodeString(config.Signatories[i-1])
|
2024-05-25 05:22:50 +00:00
|
|
|
|
if !ed448.Verify(pubkey, digest, sig, "") {
|
|
|
|
|
fmt.Printf("Failed signature check for signatory #%d\n", i)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
|
if count < len(config.Signatories)/2+len(config.Signatories)%2 {
|
2024-05-25 05:22:50 +00:00
|
|
|
|
fmt.Printf("Quorum on signatures not met")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 05:10:15 +00:00
|
|
|
|
fmt.Println("Signature check passed")
|
2024-05-25 05:22:50 +00:00
|
|
|
|
}
|
2024-06-08 11:32:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
fmt.Println("Signature check disabled, skipping...")
|
2024-05-25 05:22:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 00:12:53 +00:00
|
|
|
|
if *memprofile != "" && *core == 0 {
|
2024-02-19 00:28:29 +00:00
|
|
|
|
go func() {
|
|
|
|
|
for {
|
2024-02-20 07:59:03 +00:00
|
|
|
|
time.Sleep(5 * time.Minute)
|
2024-02-19 00:28:29 +00:00
|
|
|
|
f, err := os.Create(*memprofile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
pprof.WriteHeapProfile(f)
|
|
|
|
|
f.Close()
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 00:12:53 +00:00
|
|
|
|
if *cpuprofile != "" && *core == 0 {
|
2024-03-23 20:26:57 +00:00
|
|
|
|
f, err := os.Create(*cpuprofile)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
pprof.StartCPUProfile(f)
|
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 21:11:40 +00:00
|
|
|
|
if *balance {
|
2024-10-14 01:37:19 +00:00
|
|
|
|
config, err := config.LoadConfig(*configDirectory, "", false)
|
2024-01-29 21:11:40 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 08:11:58 +00:00
|
|
|
|
printBalance(config)
|
2024-01-29 21:11:40 +00:00
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-04 22:48:00 +00:00
|
|
|
|
if *peerId {
|
2024-10-14 01:37:19 +00:00
|
|
|
|
config, err := config.LoadConfig(*configDirectory, "", false)
|
2024-01-04 22:48:00 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printPeerID(config.P2P)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
if *importPrivKey != "" {
|
2024-10-14 01:37:19 +00:00
|
|
|
|
config, err := config.LoadConfig(*configDirectory, *importPrivKey, false)
|
2023-08-21 03:50:38 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printPeerID(config.P2P)
|
|
|
|
|
fmt.Println("Import completed, you are ready for the launch.")
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-03-24 08:11:58 +00:00
|
|
|
|
|
|
|
|
|
if *nodeInfo {
|
2024-10-14 01:37:19 +00:00
|
|
|
|
config, err := config.LoadConfig(*configDirectory, "", false)
|
2024-03-24 08:11:58 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printNodeInfo(config)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
if !*dbConsole && *core == 0 {
|
2024-10-12 18:55:17 +00:00
|
|
|
|
config.PrintLogo()
|
|
|
|
|
config.PrintVersion()
|
2023-11-27 02:51:46 +00:00
|
|
|
|
fmt.Println(" ")
|
|
|
|
|
}
|
2023-08-21 03:50:38 +00:00
|
|
|
|
|
2024-10-14 01:37:19 +00:00
|
|
|
|
nodeConfig, err := config.LoadConfig(*configDirectory, "", false)
|
2023-09-03 23:47:09 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 05:22:50 +00:00
|
|
|
|
if *network != 0 {
|
|
|
|
|
if nodeConfig.P2P.BootstrapPeers[0] == config.BootstrapPeers[0] {
|
|
|
|
|
fmt.Println(
|
|
|
|
|
"Node has specified to run outside of mainnet but is still " +
|
|
|
|
|
"using default bootstrap list. This will fail. Exiting.",
|
|
|
|
|
)
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nodeConfig.Engine.GenesisSeed = fmt.Sprintf(
|
|
|
|
|
"%02x%s",
|
|
|
|
|
byte(*network),
|
|
|
|
|
nodeConfig.Engine.GenesisSeed,
|
|
|
|
|
)
|
|
|
|
|
nodeConfig.P2P.Network = uint8(*network)
|
|
|
|
|
fmt.Println(
|
|
|
|
|
"Node is operating outside of mainnet – be sure you intended to do this.",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-25 02:43:35 +00:00
|
|
|
|
clearIfTestData(*configDirectory, nodeConfig)
|
|
|
|
|
|
2023-09-09 23:45:47 +00:00
|
|
|
|
if *dbConsole {
|
|
|
|
|
console, err := app.NewDBConsole(nodeConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.Run()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-23 01:38:20 +00:00
|
|
|
|
if *dhtOnly {
|
2024-06-08 11:32:45 +00:00
|
|
|
|
done := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
|
2024-04-23 01:38:20 +00:00
|
|
|
|
dht, err := app.NewDHTNode(nodeConfig)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
|
dht.Start()
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
<-done
|
|
|
|
|
dht.Stop()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
if *core != 0 {
|
|
|
|
|
runtime.GOMAXPROCS(1)
|
|
|
|
|
rdebug.SetGCPercent(9999)
|
|
|
|
|
|
|
|
|
|
if nodeConfig.Engine.DataWorkerMemoryLimit == 0 {
|
|
|
|
|
nodeConfig.Engine.DataWorkerMemoryLimit = 1792 * 1024 * 1024 // 1.75GiB
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rdebug.SetMemoryLimit(nodeConfig.Engine.DataWorkerMemoryLimit)
|
|
|
|
|
|
|
|
|
|
if nodeConfig.Engine.DataWorkerBaseListenMultiaddr == "" {
|
|
|
|
|
nodeConfig.Engine.DataWorkerBaseListenMultiaddr = "/ip4/127.0.0.1/tcp/%d"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if nodeConfig.Engine.DataWorkerBaseListenPort == 0 {
|
|
|
|
|
nodeConfig.Engine.DataWorkerBaseListenPort = 40000
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 11:32:45 +00:00
|
|
|
|
if *parentProcess == 0 && len(nodeConfig.Engine.DataWorkerMultiaddrs) == 0 {
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
panic("parent process pid not specified")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l, err := zap.NewProduction()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rpcMultiaddr := fmt.Sprintf(
|
|
|
|
|
nodeConfig.Engine.DataWorkerBaseListenMultiaddr,
|
|
|
|
|
int(nodeConfig.Engine.DataWorkerBaseListenPort)+*core-1,
|
|
|
|
|
)
|
2024-06-08 11:32:45 +00:00
|
|
|
|
|
|
|
|
|
if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 {
|
|
|
|
|
rpcMultiaddr = nodeConfig.Engine.DataWorkerMultiaddrs[*core-1]
|
|
|
|
|
}
|
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
srv, err := rpc.NewDataWorkerIPCServer(
|
|
|
|
|
rpcMultiaddr,
|
|
|
|
|
l,
|
|
|
|
|
uint32(*core)-1,
|
|
|
|
|
qcrypto.NewWesolowskiFrameProver(l),
|
|
|
|
|
*parentProcess,
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = srv.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 05:22:50 +00:00
|
|
|
|
fmt.Println("Loading ceremony state and starting node...")
|
2024-06-21 17:46:36 +00:00
|
|
|
|
|
|
|
|
|
if !*integrityCheck {
|
|
|
|
|
go spawnDataWorkers(nodeConfig)
|
|
|
|
|
}
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
|
2024-05-25 05:22:50 +00:00
|
|
|
|
kzg.Init()
|
|
|
|
|
|
|
|
|
|
report := RunSelfTestIfNeeded(*configDirectory, nodeConfig)
|
|
|
|
|
|
2024-06-08 11:32:45 +00:00
|
|
|
|
done := make(chan os.Signal, 1)
|
|
|
|
|
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
|
2024-03-27 08:50:52 +00:00
|
|
|
|
var node *app.Node
|
|
|
|
|
if *debug {
|
|
|
|
|
node, err = app.NewDebugNode(nodeConfig, report)
|
|
|
|
|
} else {
|
|
|
|
|
node, err = app.NewNode(nodeConfig, report)
|
|
|
|
|
}
|
2024-06-15 16:05:06 +00:00
|
|
|
|
|
2023-09-03 23:47:09 +00:00
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
2023-10-09 04:52:19 +00:00
|
|
|
|
|
2024-06-21 17:46:36 +00:00
|
|
|
|
if *integrityCheck {
|
|
|
|
|
fmt.Println("Running integrity check...")
|
|
|
|
|
node.VerifyProofIntegrity()
|
|
|
|
|
fmt.Println("Integrity check passed!")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-30 00:12:53 +00:00
|
|
|
|
runtime.GOMAXPROCS(1)
|
2024-03-08 05:05:04 +00:00
|
|
|
|
|
2023-10-09 04:52:19 +00:00
|
|
|
|
if nodeConfig.ListenGRPCMultiaddr != "" {
|
|
|
|
|
srv, err := rpc.NewRPCServer(
|
|
|
|
|
nodeConfig.ListenGRPCMultiaddr,
|
|
|
|
|
nodeConfig.ListenRestMultiaddr,
|
|
|
|
|
node.GetLogger(),
|
2024-06-08 11:32:45 +00:00
|
|
|
|
node.GetDataProofStore(),
|
2023-10-09 04:52:19 +00:00
|
|
|
|
node.GetClockStore(),
|
2024-10-14 21:41:40 +00:00
|
|
|
|
node.GetCoinStore(),
|
2023-10-28 02:23:55 +00:00
|
|
|
|
node.GetKeyManager(),
|
2023-10-09 04:52:19 +00:00
|
|
|
|
node.GetPubSub(),
|
2024-03-04 03:20:24 +00:00
|
|
|
|
node.GetMasterClock(),
|
2023-10-09 04:52:19 +00:00
|
|
|
|
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
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
stopDataWorkers()
|
2023-09-03 23:47:09 +00:00
|
|
|
|
node.Stop()
|
2023-08-21 03:50:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
var dataWorkers []*exec.Cmd
|
|
|
|
|
|
2024-06-08 11:32:45 +00:00
|
|
|
|
func spawnDataWorkers(nodeConfig *config.Config) {
|
|
|
|
|
if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 {
|
|
|
|
|
fmt.Println(
|
|
|
|
|
"Data workers configured by multiaddr, be sure these are running...",
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
process, err := os.Executable()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cores := runtime.GOMAXPROCS(0)
|
|
|
|
|
dataWorkers = make([]*exec.Cmd, cores-1)
|
|
|
|
|
fmt.Printf("Spawning %d data workers...\n", cores-1)
|
|
|
|
|
|
|
|
|
|
for i := 1; i <= cores-1; i++ {
|
|
|
|
|
i := i
|
|
|
|
|
go func() {
|
2024-06-21 17:46:36 +00:00
|
|
|
|
for {
|
|
|
|
|
args := []string{
|
|
|
|
|
fmt.Sprintf("--core=%d", i),
|
|
|
|
|
fmt.Sprintf("--parent-process=%d", os.Getpid()),
|
|
|
|
|
}
|
|
|
|
|
args = append(args, os.Args[1:]...)
|
|
|
|
|
cmd := exec.Command(process, args...)
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stdout
|
|
|
|
|
err := cmd.Start()
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
|
2024-06-21 17:46:36 +00:00
|
|
|
|
dataWorkers[i-1] = cmd
|
|
|
|
|
cmd.Wait()
|
|
|
|
|
time.Sleep(25 * time.Millisecond)
|
|
|
|
|
fmt.Printf("Data worker %d stopped, restarting...\n", i)
|
|
|
|
|
}
|
v1.4.18-patch-2 (#230)
* feat: IPC for wesolowski
* update self peer info
* remove digests and signatures
* add new binaries and digests
* Signatory #13 added
* Signatory #4 added (#231)
* added sig.6 files (#232)
* Signatory #9 added (#233)
* Added signatories #1, #2, #3, #5, #8, #12, #14, #15, #16, #17
* remove binaries, release ready
---------
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Demipoet <161999657+demipoet@users.noreply.github.com>
Co-authored-by: Freekers <1370857+Freekers@users.noreply.github.com>
2024-05-29 17:51:47 +00:00
|
|
|
|
}()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func stopDataWorkers() {
|
|
|
|
|
for i := 0; i < len(dataWorkers); i++ {
|
|
|
|
|
err := dataWorkers[i].Process.Signal(os.Kill)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf(
|
|
|
|
|
"fatal: unable to kill worker with pid %d, please kill this process!\n",
|
|
|
|
|
dataWorkers[i].Process.Pid,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 07:12:31 +00:00
|
|
|
|
func RunSelfTestIfNeeded(
|
|
|
|
|
configDir string,
|
|
|
|
|
nodeConfig *config.Config,
|
|
|
|
|
) *protobufs.SelfTestReport {
|
|
|
|
|
logger, _ := zap.NewProduction()
|
|
|
|
|
|
|
|
|
|
cores := runtime.GOMAXPROCS(0)
|
2024-06-08 11:32:45 +00:00
|
|
|
|
if len(nodeConfig.Engine.DataWorkerMultiaddrs) != 0 {
|
|
|
|
|
cores = len(nodeConfig.Engine.DataWorkerMultiaddrs) + 1
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 07:12:31 +00:00
|
|
|
|
memory := memory.TotalMemory()
|
2024-03-14 07:18:14 +00:00
|
|
|
|
d, err := os.Stat(filepath.Join(configDir, "store"))
|
|
|
|
|
if d == nil {
|
|
|
|
|
err := os.Mkdir(filepath.Join(configDir, "store"), 0755)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 07:12:31 +00:00
|
|
|
|
report := &protobufs.SelfTestReport{}
|
|
|
|
|
|
|
|
|
|
report.Cores = uint32(cores)
|
|
|
|
|
report.Memory = binary.BigEndian.AppendUint64([]byte{}, memory)
|
|
|
|
|
disk := utils.GetDiskSpace(nodeConfig.DB.Path)
|
|
|
|
|
report.Storage = binary.BigEndian.AppendUint64([]byte{}, disk)
|
|
|
|
|
logger.Info("writing report")
|
|
|
|
|
|
2024-10-12 18:55:17 +00:00
|
|
|
|
report.Capabilities = []*protobufs.Capability{
|
|
|
|
|
{
|
|
|
|
|
ProtocolIdentifier: 0x020000,
|
|
|
|
|
},
|
|
|
|
|
}
|
2024-03-01 07:12:31 +00:00
|
|
|
|
reportBytes, err := proto.Marshal(report)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = os.WriteFile(
|
|
|
|
|
filepath.Join(configDir, "SELF_TEST"),
|
|
|
|
|
reportBytes,
|
|
|
|
|
fs.FileMode(0600),
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return report
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2024-02-29 06:02:49 +00:00
|
|
|
|
fs.FileMode(0600),
|
2023-09-25 02:43:35 +00:00
|
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 08:11:58 +00:00
|
|
|
|
func printBalance(config *config.Config) {
|
|
|
|
|
if config.ListenGRPCMultiaddr == "" {
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "gRPC Not Enabled, Please Configure\n")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
conn, err := app.ConnectToNode(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
client := protobufs.NewNodeServiceClient(conn)
|
|
|
|
|
|
|
|
|
|
balance, err := app.FetchTokenBalance(client)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-08 11:32:45 +00:00
|
|
|
|
conversionFactor, _ := new(big.Int).SetString("1DCD65000", 16)
|
2024-10-14 01:37:19 +00:00
|
|
|
|
r := new(big.Rat).SetFrac(balance.Owned, conversionFactor)
|
|
|
|
|
fmt.Println("Owned balance:", r.FloatString(12), "QUIL")
|
|
|
|
|
fmt.Println("Note: bridged balance is not reflected here, you must bridge back to QUIL to use QUIL on mainnet.")
|
2024-03-24 08:11:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 17:46:36 +00:00
|
|
|
|
func getPeerID(p2pConfig *config.P2PConfig) peer.ID {
|
2023-08-21 03:50:38 +00:00
|
|
|
|
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"))
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 17:46:36 +00:00
|
|
|
|
return id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printPeerID(p2pConfig *config.P2PConfig) {
|
|
|
|
|
id := getPeerID(p2pConfig)
|
|
|
|
|
|
2023-08-21 03:50:38 +00:00
|
|
|
|
fmt.Println("Peer ID: " + id.String())
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 08:11:58 +00:00
|
|
|
|
func printNodeInfo(cfg *config.Config) {
|
|
|
|
|
if cfg.ListenGRPCMultiaddr == "" {
|
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "gRPC Not Enabled, Please Configure\n")
|
|
|
|
|
os.Exit(1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printPeerID(cfg.P2P)
|
|
|
|
|
|
|
|
|
|
conn, err := app.ConnectToNode(cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
client := protobufs.NewNodeServiceClient(conn)
|
|
|
|
|
|
|
|
|
|
nodeInfo, err := app.FetchNodeInfo(client)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println("Version: " + config.FormatVersion(nodeInfo.Version))
|
2024-03-29 07:20:35 +00:00
|
|
|
|
fmt.Println("Max Frame: " + strconv.FormatUint(nodeInfo.GetMaxFrame(), 10))
|
|
|
|
|
fmt.Println("Peer Score: " + strconv.FormatUint(nodeInfo.GetPeerScore(), 10))
|
2024-03-24 08:11:58 +00:00
|
|
|
|
printBalance(cfg)
|
|
|
|
|
}
|