func newPool(db pool.Database, cfg *config) (*miningPool, error) {
	p := new(miningPool)
	dcrdRPCCfg := &rpcclient.ConnConfig{
		Host:         cfg.DcrdRPCHost,
		Endpoint:     "ws",
		User:         cfg.RPCUser,
		Pass:         cfg.RPCPass,
		Certificates: cfg.dcrdRPCCerts,
	}
	p.ctx, p.cancel = context.WithCancel(context.Background())
	powLimit := cfg.net.PowLimit
	powLimitF, _ := new(big.Float).SetInt(powLimit).Float64()
	iterations := math.Pow(2, 256-math.Floor(math.Log2(powLimitF)))
	hcfg := &pool.HubConfig{
		DB:                    db,
		NodeRPCConfig:         dcrdRPCCfg,
		WalletRPCCert:         cfg.WalletRPCCert,
		WalletTLSCert:         cfg.WalletTLSCert,
		WalletTLSKey:          cfg.WalletTLSKey,
		WalletGRPCHost:        cfg.WalletGRPCHost,
		ActiveNet:             cfg.net.Params,
		PoolFee:               cfg.PoolFee,
		MaxGenTime:            cfg.MaxGenTime,
		PaymentMethod:         cfg.PaymentMethod,
		LastNPeriod:           cfg.LastNPeriod,
		WalletPass:            cfg.WalletPass,
		PoolFeeAddrs:          cfg.poolFeeAddrs,
		SoloPool:              cfg.SoloPool,
		NonceIterations:       iterations,
		MinerListen:           cfg.MinerListen,
		MaxConnectionsPerHost: cfg.MaxConnectionsPerHost,
		WalletAccount:         cfg.WalletAccount,
		CoinbaseConfTimeout:   cfg.CoinbaseConfTimeout,
		MonitorCycle:          cfg.MonitorCycle,
		MaxUpgradeTries:       cfg.MaxUpgradeTries,
		ClientTimeout:         cfg.clientTimeout,
	}
	var err error
	p.hub, err = pool.NewHub(p.cancel, hcfg)
	if err != nil {
		return nil, fmt.Errorf("unable to initialize hub: %v", err)
	}
	err = p.hub.Connect(p.ctx)
	if err != nil {
		return nil, fmt.Errorf("unable to establish node connections: %v", err)
	}
	err = p.hub.FetchWork(p.ctx)
	if err != nil {
		return nil, err
	}
	csrfSecret, err := p.hub.CSRFSecret()
	if err != nil {
		return nil, err
	}
	gcfg := &gui.Config{
		SoloPool:              cfg.SoloPool,
		GUIDir:                cfg.GUIDir,
		AdminPass:             cfg.AdminPass,
		GUIListen:             cfg.GUIListen,
		UseLEHTTPS:            cfg.UseLEHTTPS,
		NoGUITLS:              cfg.NoGUITLS,
		Domain:                cfg.Domain,
		TLSCertFile:           cfg.GUITLSCert,
		TLSKeyFile:            cfg.GUITLSKey,
		ActiveNetName:         cfg.net.Params.Name,
		BlockExplorerURL:      cfg.net.BlockExplorerURL,
		PaymentMethod:         cfg.PaymentMethod,
		Designation:           cfg.Designation,
		PoolFee:               cfg.PoolFee,
		CSRFSecret:            csrfSecret,
		MinerListen:           cfg.MinerListen,
		WithinLimit:           p.hub.WithinLimit,
		FetchLastWorkHeight:   p.hub.FetchLastWorkHeight,
		FetchLastPaymentInfo:  p.hub.FetchLastPaymentInfo,
		FetchMinedWork:        p.hub.FetchMinedWork,
		FetchWorkQuotas:       p.hub.FetchWorkQuotas,
		FetchHashData:         p.hub.FetchHashData,
		AccountExists:         p.hub.AccountExists,
		FetchArchivedPayments: p.hub.FetchArchivedPayments,
		FetchPendingPayments:  p.hub.FetchPendingPayments,
		FetchCacheChannel:     p.hub.FetchCacheChannel,
	}
	if !cfg.UsePostgres {
		gcfg.HTTPBackupDB = p.hub.HTTPBackupDB
	}
	p.gui, err = gui.NewGUI(gcfg)
	if err != nil {
		return nil, err
	}
	return p, nil
}
newPool initializes the mining pool.
package main
import (
	"context"
	"fmt"
	"math"
	"math/big"
	"net/http"
	_ "net/http/pprof"
	"os"
	"os/signal"
	"runtime"
	"github.com/decred/dcrd/rpcclient/v6"
	"github.com/decred/dcrpool/gui"
	"github.com/decred/dcrpool/pool"
)
var signals = []os.Signal{os.Interrupt}
type miningPool struct {
	ctx    context.Context
	cancel context.CancelFunc
	hub    *pool.Hub
	gui    *gui.GUI
}