Move vspd into cmd directory. (#352)

* Update linter to 1.49.0

* Move vspd into cmd directory.

This is standard practise in Decred golang repos. Especially useful when multiple executables are built from a single repo.

* Ignore bins in new dir.
This commit is contained in:
Jamie Holdstock 2022-09-27 14:54:23 +01:00 committed by GitHub
parent c961423e9e
commit 11401c5369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 50 deletions

View File

@ -21,5 +21,5 @@ jobs:
- name: Lint - name: Lint
uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc #v3.2.0 uses: golangci/golangci-lint-action@537aa1903e5d359d0b27dbc19ddd22c5087f3fbc #v3.2.0
with: with:
version: v1.48.0 version: v1.49.0

6
.gitignore vendored
View File

@ -1,5 +1,7 @@
*.exe ./vspd.exe
vspd ./vspd
./cmd/vspd/vspd.exe
./cmd/vspd/vspd
# Testing, profiling, and benchmarking artifacts # Testing, profiling, and benchmarking artifacts
cov.out cov.out

View File

@ -6,7 +6,6 @@ linters:
enable: enable:
- asciicheck - asciicheck
- bidichk - bidichk
- deadcode
- durationcheck - durationcheck
- errcheck - errcheck
- errchkjson - errchkjson
@ -23,11 +22,9 @@ linters:
- nilerr - nilerr
- revive - revive
- staticcheck - staticcheck
- structcheck
- tparallel - tparallel
- typecheck - typecheck
- unconvert - unconvert
- unparam - unparam
- unused - unused
- varcheck
- vetshadow - vetshadow

View File

@ -15,17 +15,16 @@ import (
) )
const ( const (
// requiredConfs is the number of confirmations required to consider a // requiredConfs is the number of confirmations required to consider a
// ticket purchase or a fee transaction to be final. // ticket purchase or a fee transaction to be final.
requiredConfs = 6 requiredConfs = 6
) )
// BlockConnected is called once when vspd starts up, and once each time a // blockConnected is called once when vspd starts up, and once each time a
// blockconnected notification is received from dcrd. // blockconnected notification is received from dcrd.
func BlockConnected(dcrdRPC rpc.DcrdConnect, walletRPC rpc.WalletConnect, db *database.VspDatabase, log slog.Logger) { func blockConnected(dcrdRPC rpc.DcrdConnect, walletRPC rpc.WalletConnect, db *database.VspDatabase, log slog.Logger) {
const funcName = "BlockConnected" const funcName = "blockConnected"
dcrdClient, _, err := dcrdRPC.Client() dcrdClient, _, err := dcrdRPC.Client()
if err != nil { if err != nil {
@ -281,12 +280,12 @@ func BlockConnected(dcrdRPC rpc.DcrdConnect, walletRPC rpc.WalletConnect, db *da
} }
// CheckWalletConsistency will retrieve all votable tickets from the database // checkWalletConsistency will retrieve all votable tickets from the database
// and ensure they are all added to voting wallets with the correct vote // and ensure they are all added to voting wallets with the correct vote
// choices. // choices.
func CheckWalletConsistency(dcrdRPC rpc.DcrdConnect, walletRPC rpc.WalletConnect, db *database.VspDatabase, log slog.Logger) { func checkWalletConsistency(dcrdRPC rpc.DcrdConnect, walletRPC rpc.WalletConnect, db *database.VspDatabase, log slog.Logger) {
const funcName = "CheckWalletConsistency" const funcName = "checkWalletConsistency"
log.Info("Checking voting wallet consistency") log.Info("Checking voting wallet consistency")

View File

@ -388,16 +388,16 @@ func loadConfig() (*config, error) {
} }
// Verify minimum number of voting wallets are configured. // Verify minimum number of voting wallets are configured.
if numHost < cfg.netParams.MinWallets { if numHost < cfg.netParams.minWallets {
return nil, fmt.Errorf("minimum required voting wallets has not been met: %d < %d", return nil, fmt.Errorf("minimum required voting wallets has not been met: %d < %d",
numHost, cfg.netParams.MinWallets) numHost, cfg.netParams.minWallets)
} }
// Add default port for the active network if there is no port specified. // Add default port for the active network if there is no port specified.
for i := 0; i < numHost; i++ { for i := 0; i < numHost; i++ {
cfg.walletHosts[i] = normalizeAddress(cfg.walletHosts[i], cfg.netParams.WalletRPCServerPort) cfg.walletHosts[i] = normalizeAddress(cfg.walletHosts[i], cfg.netParams.walletRPCServerPort)
} }
cfg.DcrdHost = normalizeAddress(cfg.DcrdHost, cfg.netParams.DcrdRPCServerPort) cfg.DcrdHost = normalizeAddress(cfg.DcrdHost, cfg.netParams.dcrdRPCServerPort)
// Create the data directory. // Create the data directory.
dataDir := filepath.Join(cfg.HomeDir, "data", cfg.netParams.Name) dataDir := filepath.Join(cfg.HomeDir, "data", cfg.netParams.Name)
@ -408,7 +408,7 @@ func loadConfig() (*config, error) {
// Initialize loggers and log rotation. // Initialize loggers and log rotation.
logDir := filepath.Join(cfg.HomeDir, "logs", cfg.netParams.Name) logDir := filepath.Join(cfg.HomeDir, "logs", cfg.netParams.Name)
cfg.logBackend, err = NewLogBackend(logDir, appName, cfg.MaxLogSize, cfg.LogsToKeep) cfg.logBackend, err = newLogBackend(logDir, appName, cfg.MaxLogSize, cfg.LogsToKeep)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to initialize logger: %w", err) return nil, fmt.Errorf("failed to initialize logger: %w", err)
} }
@ -437,7 +437,7 @@ func loadConfig() (*config, error) {
} }
// Create new database. // Create new database.
err = database.CreateNew(cfg.dbPath, cfg.FeeXPub, cfg.Logger(" DB")) err = database.CreateNew(cfg.dbPath, cfg.FeeXPub, cfg.logger(" DB"))
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating db file %s: %w", cfg.dbPath, err) return nil, fmt.Errorf("error creating db file %s: %w", cfg.dbPath, err)
} }
@ -456,7 +456,7 @@ func loadConfig() (*config, error) {
return &cfg, nil return &cfg, nil
} }
func (cfg *config) Logger(subsystem string) slog.Logger { func (cfg *config) logger(subsystem string) slog.Logger {
log := cfg.logBackend.Logger(subsystem) log := cfg.logBackend.Logger(subsystem)
log.SetLevel(cfg.logLevel) log.SetLevel(cfg.logLevel)
return log return log

View File

@ -1,4 +1,4 @@
// Copyright (c) 2020-2021 The Decred developers // Copyright (c) 2020-2022 The Decred developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@ -24,7 +24,7 @@ func (lw logWriter) Write(p []byte) (n int, err error) {
return lw.rotator.Write(p) return lw.rotator.Write(p)
} }
func NewLogBackend(logDir string, appName string, maxLogSize int64, logsToKeep int) (*slog.Backend, error) { func newLogBackend(logDir string, appName string, maxLogSize int64, logsToKeep int) (*slog.Backend, error) {
err := os.MkdirAll(logDir, 0700) err := os.MkdirAll(logDir, 0700)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create log directory: %w", err) return nil, fmt.Errorf("failed to create log directory: %w", err)

View File

@ -46,10 +46,10 @@ func run() int {
return 1 return 1
} }
log := cfg.Logger("VSP") log := cfg.logger("VSP")
dbLog := cfg.Logger(" DB") dbLog := cfg.logger(" DB")
apiLog := cfg.Logger("API") apiLog := cfg.logger("API")
rpcLog := cfg.Logger("RPC") rpcLog := cfg.logger("RPC")
// Create a context that is cancelled when a shutdown request is received // Create a context that is cancelled when a shutdown request is received
// through an interrupt signal. // through an interrupt signal.
@ -107,7 +107,7 @@ func run() int {
return return
case header := <-notifChan: case header := <-notifChan:
log.Debugf("Block notification %d (%s)", header.Height, header.BlockHash().String()) log.Debugf("Block notification %d (%s)", header.Height, header.BlockHash().String())
BlockConnected(dcrd, wallets, db, log) blockConnected(dcrd, wallets, db, log)
} }
} }
}() }()
@ -143,11 +143,11 @@ func run() int {
// Run the block connected handler now to catch up with any blocks mined // Run the block connected handler now to catch up with any blocks mined
// while vspd was shut down. // while vspd was shut down.
BlockConnected(dcrd, wallets, db, log) blockConnected(dcrd, wallets, db, log)
// Run voting wallet consistency check now to ensure all wallets are up to // Run voting wallet consistency check now to ensure all wallets are up to
// date. // date.
CheckWalletConsistency(dcrd, wallets, db, log) checkWalletConsistency(dcrd, wallets, db, log)
// Run voting wallet consistency check periodically. // Run voting wallet consistency check periodically.
shutdownWg.Add(1) shutdownWg.Add(1)
@ -158,7 +158,7 @@ func run() int {
shutdownWg.Done() shutdownWg.Done()
return return
case <-time.After(consistencyInterval): case <-time.After(consistencyInterval):
CheckWalletConsistency(dcrd, wallets, db, log) checkWalletConsistency(dcrd, wallets, db, log)
} }
} }
}() }()
@ -167,7 +167,7 @@ func run() int {
apiCfg := webapi.Config{ apiCfg := webapi.Config{
VSPFee: cfg.VSPFee, VSPFee: cfg.VSPFee,
NetParams: cfg.netParams.Params, NetParams: cfg.netParams.Params,
BlockExplorerURL: cfg.netParams.BlockExplorerURL, BlockExplorerURL: cfg.netParams.blockExplorerURL,
SupportEmail: cfg.SupportEmail, SupportEmail: cfg.SupportEmail,
VspClosed: cfg.VspClosed, VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg, VspClosedMsg: cfg.VspClosedMsg,

View File

@ -10,35 +10,35 @@ import (
type netParams struct { type netParams struct {
*chaincfg.Params *chaincfg.Params
DcrdRPCServerPort string dcrdRPCServerPort string
WalletRPCServerPort string walletRPCServerPort string
BlockExplorerURL string blockExplorerURL string
// MinWallets is the minimum number of voting wallets required for a vspd // minWallets is the minimum number of voting wallets required for a vspd
// deployment on this network. vspd will log an error and refuse to start if // deployment on this network. vspd will log an error and refuse to start if
// fewer wallets are configured. // fewer wallets are configured.
MinWallets int minWallets int
} }
var mainNetParams = netParams{ var mainNetParams = netParams{
Params: chaincfg.MainNetParams(), Params: chaincfg.MainNetParams(),
DcrdRPCServerPort: "9109", dcrdRPCServerPort: "9109",
WalletRPCServerPort: "9110", walletRPCServerPort: "9110",
BlockExplorerURL: "https://dcrdata.decred.org", blockExplorerURL: "https://dcrdata.decred.org",
MinWallets: 3, minWallets: 3,
} }
var testNet3Params = netParams{ var testNet3Params = netParams{
Params: chaincfg.TestNet3Params(), Params: chaincfg.TestNet3Params(),
DcrdRPCServerPort: "19109", dcrdRPCServerPort: "19109",
WalletRPCServerPort: "19110", walletRPCServerPort: "19110",
BlockExplorerURL: "https://testnet.dcrdata.org", blockExplorerURL: "https://testnet.dcrdata.org",
MinWallets: 1, minWallets: 1,
} }
var simNetParams = netParams{ var simNetParams = netParams{
Params: chaincfg.SimNetParams(), Params: chaincfg.SimNetParams(),
DcrdRPCServerPort: "19556", dcrdRPCServerPort: "19556",
WalletRPCServerPort: "19557", walletRPCServerPort: "19557",
BlockExplorerURL: "...", blockExplorerURL: "...",
MinWallets: 1, minWallets: 1,
} }

View File

@ -1,5 +1,5 @@
// Copyright (c) 2013-2014 The btcsuite developers // Copyright (c) 2013-2014 The btcsuite developers
// Copyright (c) 2021 The Decred developers // Copyright (c) 2021-2022 The Decred developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.

View File

@ -1,5 +1,5 @@
// Copyright (c) 2016 The btcsuite developers // Copyright (c) 2016 The btcsuite developers
// Copyright (c) 2021 The Decred developers // Copyright (c) 2021-2022 The Decred developers
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.