mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-13 17:46:39 +00:00

* [NOD-122] Handle each message in rpcclient with a separate goroutine * [NOD-122] Stop listening to new blocks when not mining * [NOD-122] Made RPC logging in mining simulator more explicit + some styling enhencement
59 lines
1021 B
Go
59 lines
1021 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"runtime/debug"
|
|
|
|
"github.com/daglabs/btcd/signal"
|
|
)
|
|
|
|
func main() {
|
|
defer handlePanic()
|
|
cfg, err := parseConfig()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error parsing command-line arguments: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if cfg.Verbose {
|
|
enableRPCLogging()
|
|
}
|
|
|
|
addressList, err := getAddressList(cfg)
|
|
if err != nil {
|
|
panic(fmt.Errorf("Couldn't load address list: %s", err))
|
|
}
|
|
|
|
clients, err := connectToServers(cfg, addressList)
|
|
if err != nil {
|
|
panic(fmt.Errorf("Error connecting to servers: %s", err))
|
|
}
|
|
defer disconnect(clients)
|
|
|
|
go func() {
|
|
err = mineLoop(clients)
|
|
if err != nil {
|
|
panic(fmt.Errorf("Error in main loop: %s", err))
|
|
}
|
|
}()
|
|
|
|
interrupt := signal.InterruptListener()
|
|
<-interrupt
|
|
}
|
|
|
|
func disconnect(clients []*simulatorClient) {
|
|
for _, client := range clients {
|
|
client.Disconnect()
|
|
}
|
|
}
|
|
|
|
func handlePanic() {
|
|
err := recover()
|
|
if err != nil {
|
|
log.Printf("Fatal error: %s", err)
|
|
log.Printf("Stack trace: %s", debug.Stack())
|
|
}
|
|
}
|