Blockchain 7 min read

Why miner.start() Returns null in Ethereum v1.7.3 and How to Verify Mining Status

In Ethereum v1.7.3 the console command miner.start() always returns null, regardless of whether mining actually starts, because the underlying Go implementation returns nil and the real status is logged or inferred from other API calls, not from the return value.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
Why miner.start() Returns null in Ethereum v1.7.3 and How to Verify Mining Status

Mining entry point

The console command miner.start() (or miner.start(n) where n is the number of CPU cores) triggers the Go method miner.Start defined in eth/api.go. The method signature is:

func (api *PrivateMinerAPI) Start(threads *int) error

If threads is nil, the code creates a new int and sets it to the number of logical CPUs; if threads is zero, it disables mining by setting the value to -1. The method then obtains the engine, checks whether it implements the threaded interface, and calls SetThreads on it. Finally it starts the miner with api.e.StartMining(true) and returns nil regardless of success.

The parameter passed to the miner is the system CPU core count; it can be overridden.

If mining is already running, calling miner.start() adjusts the thread count.

The function always returns nil, so the return value cannot be used to determine success.

If mining has not started, the code still calls api.e.StartMining(true).

Executing mining

The StartMining method of Ethereum performs several checks before actually starting the miner:

func (s *Ethereum) StartMining(local bool) error {
    eb, err := s.Etherbase()
    if err != nil {
        log.Error("Cannot start mining without etherbase", "err", err)
        return fmt.Errorf("etherbase missing: %v", err)
    }
    // ... obtain clique engine, find account, authorize, etc.
    if local {
        // enable transaction acceptance for private networks
        atomic.StoreUint32(&s.protocolManager.acceptTxs, 1)
    }
    go s.miner.Start(eb)
    return nil
}

The method first retrieves the coinbase (etherbase) address; if it is missing, an error is returned. It then checks for a Clique consensus engine, finds the corresponding account, authorizes it, and, when local is true, enables transaction acceptance. Finally it launches the miner in a separate goroutine. The only observable indication of a successful start is the log line "Starting mining operation".

Stop function

The Stop method of PrivateMinerAPI always returns true after invoking the engine’s StopMining method, regardless of whether mining was actually running:

func (api *PrivateMinerAPI) Stop() bool {
    if th, ok := api.e.engine.(threaded); ok {
        th.SetThreads(-1)
    }
    api.e.StopMining()
    return true
}

Thus the return value of miner.stop() cannot be used to confirm that mining has stopped.

Conclusion

In Ethereum version 1.7.3 the console commands miner.start() and miner.stop() both return values ( nil and true respectively) that do not reflect the actual mining state. To verify that mining has started, one must look for the log message "Starting mining operation" or check other runtime indicators such as the miner’s thread count or the node’s sync status.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GoEthereumsource codeminer.start
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.