From a381e8672cb8f09fc13e9aa43b9d91cc6e2bdd1b Mon Sep 17 00:00:00 2001 From: Evgeny Khirin <32414982+evgeny-khirin@users.noreply.github.com> Date: Sun, 17 Mar 2019 11:55:40 +0200 Subject: [PATCH] [NOD-4] Exit on out of disk space when storing a block (#211) * [NOD-4] Exit on out of disk space when storing a block * [NOD-4] Fixed log message * [NOD-4] Fixed log message * [NOD-4] Fixed log message --- config/config.go | 2 +- database/ffldb/blockio.go | 5 +++++ mining/cpuminer/cpuminer.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index acb747283..888adc45d 100644 --- a/config/config.go +++ b/config/config.go @@ -764,7 +764,7 @@ func loadConfig() (*Config, []string, error) { } // Check that 'generate' and 'subnetwork' flags do not conflict - if cfg.Generate && cfg.SubnetworkID.IsEqual(subnetworkid.SubnetworkIDSupportsAll) { + if cfg.Generate && !cfg.SubnetworkID.IsEqual(subnetworkid.SubnetworkIDSupportsAll) { str := "%s: both generate flag and subnetwork filtering are set " err := fmt.Errorf(str, funcName) fmt.Fprintln(os.Stderr, err) diff --git a/database/ffldb/blockio.go b/database/ffldb/blockio.go index d7c8b3856..246fa1d9e 100644 --- a/database/ffldb/blockio.go +++ b/database/ffldb/blockio.go @@ -16,6 +16,7 @@ import ( "os" "path/filepath" "sync" + "syscall" "github.com/daglabs/btcd/dagconfig/daghash" "github.com/daglabs/btcd/database" @@ -385,6 +386,10 @@ func (s *blockStore) writeData(data []byte, fieldName string) error { n, err := wc.curFile.file.WriteAt(data, int64(wc.curOffset)) wc.curOffset += uint32(n) if err != nil { + if pathErr, isOk := err.(*os.PathError); isOk && pathErr.Err == syscall.ENOSPC { + log.Errorf("No space left on the hard disk, exiting...") + os.Exit(1) + } str := fmt.Sprintf("failed to write %s to file %d at "+ "offset %d: %s", fieldName, wc.curFileNum, wc.curOffset-uint32(n), err) diff --git a/mining/cpuminer/cpuminer.go b/mining/cpuminer/cpuminer.go index d3f2f122e..95233c7bd 100644 --- a/mining/cpuminer/cpuminer.go +++ b/mining/cpuminer/cpuminer.go @@ -436,7 +436,7 @@ func (m *CPUMiner) Start() { go m.miningWorkerController() m.started = true - log.Infof("CPU miner started") + log.Infof("CPU miner started, number of workers %d", m.numWorkers) } // Stop gracefully stops the mining process by signalling all workers, and the