Skip to content

Commit

Permalink
Remove miner functionality from the node
Browse files Browse the repository at this point in the history
Remove references to mining threads
  • Loading branch information
Djadih committed May 9, 2023
1 parent 263aed1 commit 963a18f
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 191 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ endif
ifeq ($(CORS),true)
BASE_CMD += --ws.origins=$(WS_ORIG) --http.corsdomain=$(HTTP_CORSDOMAIN)
endif
ifeq ($(QUAI_MINING),true)
BASE_CMD += --mine --miner.threads $(THREADS)
endif
ifeq ($(QUAI_STATS),true)
BASE_CMD += --quaistats ${STATS_NAME}:${STATS_PASS}@${STATS_HOST}
endif
Expand Down
18 changes: 1 addition & 17 deletions cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,8 @@ var (
utils.ListenPortFlag,
utils.MaxPeersFlag,
utils.MaxPendingPeersFlag,
utils.MiningEnabledFlag,
utils.MinerThreadsFlag,
utils.MinerNotifyFlag,
utils.LegacyMinerGasTargetFlag,
utils.MinerGasLimitFlag,
utils.MinerGasPriceFlag,
utils.MinerEtherbaseFlag,
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
utils.DiscoveryV5Flag,
Expand All @@ -126,7 +118,6 @@ var (
utils.GpoPercentileFlag,
utils.GpoMaxGasPriceFlag,
utils.GpoIgnoreGasPriceFlag,
utils.MinerNotifyFullFlag,
configFileFlag,
utils.RegionFlag,
utils.ZoneFlag,
Expand Down Expand Up @@ -193,8 +184,6 @@ func init() {
licenseCommand,
// See config.go
dumpConfigCommand,
// See cmd/utils/flags_legacy.go
utils.ShowDeprecated,
// See snapshot.go
snapshotCommand,
}
Expand Down Expand Up @@ -315,7 +304,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend quaiapi.Backend) {
}

// Start auxiliary services if enabled
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
if ctx.GlobalBool(utils.DeveloperFlag.Name) {

var err error
ethBackend, ok := backend.(*eth.QuaiAPIBackend)
Expand All @@ -328,10 +317,5 @@ func startNode(ctx *cli.Context, stack *node.Node, backend quaiapi.Backend) {
gasprice := utils.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
ethBackend.TxPool().SetGasPrice(gasprice)
}
// start mining
threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name)
if err := ethBackend.StartMining(threads); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
}
}
12 changes: 0 additions & 12 deletions cmd/go-quai/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,8 @@ var AppHelpFlagGroups = []flags.FlagGroup{
{
Name: "MINER",
Flags: []cli.Flag{
utils.MiningEnabledFlag,
utils.MinerThreadsFlag,
utils.MinerNotifyFlag,
utils.MinerNotifyFullFlag,
utils.MinerGasPriceFlag,
utils.MinerGasLimitFlag,
utils.MinerEtherbaseFlag,
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
},
},
{
Expand Down Expand Up @@ -194,7 +186,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.LegacyRPCCORSDomainFlag,
utils.LegacyRPCVirtualHostsFlag,
utils.LegacyRPCApiFlag,
utils.LegacyMinerGasTargetFlag,
},
},
{
Expand Down Expand Up @@ -230,9 +221,6 @@ func init() {
}
}
deprecated := make(map[string]struct{})
for _, flag := range utils.DeprecatedFlags {
deprecated[flag.String()] = struct{}{}
}
// Only add uncategorized flags if they are not deprecated
var uncategorized []cli.Flag
for _, flag := range data.(*cli.App).Flags {
Expand Down
61 changes: 0 additions & 61 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,28 +333,6 @@ var (
Usage: "Enable recording the SHA3/keccak preimages of trie keys",
}
// Miner settings
MiningEnabledFlag = cli.BoolFlag{
Name: "mine",
Usage: "Enable mining",
}
MinerThreadsFlag = cli.IntFlag{
Name: "miner.threads",
Usage: "Number of CPU threads to use for mining",
Value: 0,
}
MinerNotifyFlag = cli.StringFlag{
Name: "miner.notify",
Usage: "Comma separated HTTP URL list to notify of new work packages",
}
MinerNotifyFullFlag = cli.BoolFlag{
Name: "miner.notify.full",
Usage: "Notify with pending block headers instead of work packages",
}
MinerGasLimitFlag = cli.Uint64Flag{
Name: "miner.gaslimit",
Usage: "Target gas ceiling for mined blocks",
Value: ethconfig.Defaults.Miner.GasCeil,
}
MinerGasPriceFlag = BigFlag{
Name: "miner.gasprice",
Usage: "Minimum gas price for mining a transaction",
Expand All @@ -365,19 +343,6 @@ var (
Usage: "Public address for block mining rewards (default = first account)",
Value: "0",
}
MinerExtraDataFlag = cli.StringFlag{
Name: "miner.extradata",
Usage: "Block extra data set by the miner (default = client version)",
}
MinerRecommitIntervalFlag = cli.DurationFlag{
Name: "miner.recommit",
Usage: "Time interval to recreate the block being mined",
Value: ethconfig.Defaults.Miner.Recommit,
}
MinerNoVerfiyFlag = cli.BoolFlag{
Name: "miner.noverify",
Usage: "Disable remote sealing verification",
}
// Account settings
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Expand Down Expand Up @@ -1200,31 +1165,6 @@ func setBlake3pow(ctx *cli.Context, cfg *ethconfig.Config) {
}
}

func setMiner(ctx *cli.Context, cfg *core.Config) {
if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
}
cfg.NotifyFull = ctx.GlobalBool(MinerNotifyFullFlag.Name)
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
}
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
}
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
}
if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
cfg.Recommit = ctx.GlobalDuration(MinerRecommitIntervalFlag.Name)
}
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
cfg.Noverify = ctx.GlobalBool(MinerNoVerfiyFlag.Name)
}
if ctx.GlobalIsSet(LegacyMinerGasTargetFlag.Name) {
log.Warn("The generic --miner.gastarget flag is deprecated and will be removed in the future!")
}
}

func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) {
whitelist := ctx.GlobalString(WhitelistFlag.Name)
if whitelist == "" {
Expand Down Expand Up @@ -1322,7 +1262,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setGPO(ctx, &cfg.GPO, ctx.GlobalString(SyncModeFlag.Name) == "light")
setTxPool(ctx, &cfg.TxPool)
setBlake3pow(ctx, cfg)
setMiner(ctx, &cfg.Miner)
setWhitelist(ctx, cfg)

// set the dominant chain websocket url
Expand Down
33 changes: 0 additions & 33 deletions cmd/utils/flags_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,12 @@
package utils

import (
"fmt"
"strings"

"github.com/dominant-strategies/go-quai/eth/ethconfig"
"github.com/dominant-strategies/go-quai/node"
"gopkg.in/urfave/cli.v1"
)

var ShowDeprecated = cli.Command{
Action: showDeprecated,
Name: "show-deprecated-flags",
Usage: "Show flags that have been deprecated",
ArgsUsage: " ",
Category: "MISCELLANEOUS COMMANDS",
Description: "Show flags that have been deprecated and will soon be removed",
}

var DeprecatedFlags = []cli.Flag{
LegacyMinerGasTargetFlag,
}

var (
// (Deprecated May 2020, shown in aliased flags section)
LegacyRPCEnabledFlag = cli.BoolFlag{
Expand Down Expand Up @@ -69,22 +54,4 @@ var (
Usage: "API's offered over the HTTP-RPC interface (deprecated and will be removed June 2021, use --http.api)",
Value: "",
}
// (Deprecated July 2021, shown in aliased flags section)
LegacyMinerGasTargetFlag = cli.Uint64Flag{
Name: "miner.gastarget",
Usage: "Target gas floor for mined blocks (deprecated)",
Value: ethconfig.Defaults.Miner.GasFloor,
}
)

// showDeprecated displays deprecated flags that will be soon removed from the codebase.
func showDeprecated(*cli.Context) {
fmt.Println("--------------------------------------------------------------------")
fmt.Println("The following flags are deprecated and will be removed in the future!")
fmt.Println("--------------------------------------------------------------------")
fmt.Println()
for _, flag := range DeprecatedFlags {
fmt.Println(flag.String())
}
fmt.Println()
}
19 changes: 0 additions & 19 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"io"
"math/big"
"os"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -93,24 +92,6 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
return &PrivateMinerAPI{e: e}
}

// Start starts the miner with the given number of threads. If threads is nil,
// the number of workers started is equal to the number of logical CPUs that are
// usable by this process. If mining is already running, this method adjust the
// number of threads allowed to use and updates the minimum price required by the
// transaction pool.
func (api *PrivateMinerAPI) Start(threads *int) error {
if threads == nil {
return api.e.StartMining(runtime.NumCPU())
}
return api.e.StartMining(*threads)
}

// Stop terminates the miner, both at the consensus engine level as well as at
// the block creation level.
func (api *PrivateMinerAPI) Stop() {
api.e.StopMining()
}

// SetExtra sets the extra data string that is included when this miner mines a block.
func (api *PrivateMinerAPI) SetExtra(extra string) (bool, error) {
if err := api.e.Core().SetExtra([]byte(extra)); err != nil {
Expand Down
8 changes: 0 additions & 8 deletions eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,6 @@ func (b *QuaiAPIBackend) CurrentHeader() *types.Header {
return b.eth.core.CurrentHeader()
}

func (b *QuaiAPIBackend) Miner() *core.Miner {
return b.eth.core.Miner()
}

func (b *QuaiAPIBackend) StartMining(threads int) error {
return b.eth.StartMining(threads)
}

func (b *QuaiAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, checkLive bool) (*state.StateDB, error) {
nodeCtx := common.NodeLocation.Context()
if nodeCtx != common.ZONE_CTX {
Expand Down
35 changes: 0 additions & 35 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,41 +355,6 @@ func (s *Ethereum) shouldPreserve(block *types.Block) bool {
return s.isLocalBlock(block.Header())
}

// StartMining starts the miner with the given number of CPU threads. If mining
// is already running, this method adjust the number of threads allowed to use
// and updates the minimum price required by the transaction pool.
func (s *Ethereum) StartMining(threads int) error {
// Update the thread count within the consensus engine
type threaded interface {
SetThreads(threads int)
}
if th, ok := s.engine.(threaded); ok {
log.Info("Updated mining threads", "threads", threads)
if threads == 0 {
threads = -1 // Disable the miner from within
}
th.SetThreads(threads)
}
// If the miner was not running, initialize it
if !s.core.IsMining() {
// Propagate the initial price point to the transaction pool
s.lock.RLock()
price := s.gasPrice
s.lock.RUnlock()
s.core.SetGasPrice(price)
// If mining is started, we can disable the transaction rejection mechanism
// introduced to speed sync times.
atomic.StoreUint32(&s.handler.acceptTxs, 1)
}
return nil
}

// StopMining terminates the miner, both at the consensus engine level as well as
// at the block creation level.
func (s *Ethereum) StopMining() {
s.core.StopMining()
}

func (s *Ethereum) Core() *core.Core { return s.core }
func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux }
func (s *Ethereum) Engine() consensus.Engine { return s.engine }
Expand Down
3 changes: 0 additions & 3 deletions network.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ HTTP_API=eth,net,web3,quai
#Mining Variables
QUAI_MINING=true

#Number of CPU threads
THREADS=1

#Bootnode Specific Variables
#Should only be used by bootnode operators, i.e. team developers
HTTP_CORSDOMAIN="*"
Expand Down

0 comments on commit 963a18f

Please sign in to comment.