mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-02 20:26:43 +00:00

* [NOD-90] Update mining simulator to pull latest block template * [NOD-90] Refactor to reduce global state * [NOD-90] Split onMinerSwitch func * [NOD-90] Replace chooseClient with getRandomClient * [NOD-90] Stop ranging over foundBlock to avoid code repetition
49 lines
867 B
Go
49 lines
867 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"runtime/debug"
|
|
)
|
|
|
|
func main() {
|
|
defer handlePanic()
|
|
|
|
cfg, err := parseConfig()
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error parsing command-line arguments: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
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)
|
|
|
|
err = mineLoop(clients)
|
|
if err != nil {
|
|
panic(fmt.Errorf("Error in main loop: %s", err))
|
|
}
|
|
}
|
|
|
|
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())
|
|
}
|
|
}
|