9
> miner.start()  
> null  

before it , I had created a account like this .

 user1 = eth.accounts[0] 
"0xb62f0bae52d153365661c4e23ab1d594484e9bef"  
  • 3
    After you created an account, did you set the coinbase to that account? Miner needs an account to send earnings from the mining process. – Rob Hitchens - B9lab May 10 '17 at 16:19
  • 1
    This is -I think- normal. Check your console output to see if the mining has actually started. – jeff May 12 '17 at 19:26
10

Recently, there are so many people confused about miner.start(1) returning null, but it's actually not a problem, just a reasonable return value misunderstanding. If you aren't sure that your node is mining, please execute eth.hashrate to check, if the return value is greater than zero, it is mining, otherwise, it is not.

Now let's analyze why miner.start(1) returns null. It might help to read the source code. When you execute the command miner.start(1) on the terminal, this would call Start(threads *int) method in api.go source file, as follows:

// Start 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.
func (api *PrivateMinerAPI) Start(threads *int) error {
    // Set the number of threads if the seal engine supports it
    if threads == nil {
        threads = new(int)
    } else if *threads == 0 {
        *threads = -1 // Disable the miner from within
    }
    type threaded interface {
        SetThreads(threads int)
    }
    if th, ok := api.e.engine.(threaded); ok {
        log.Info("Updated mining threads", "threads", *threads)
        th.SetThreads(*threads)
    }
    // Start the miner and return
    if !api.e.IsMining() {
        // Propagate the initial price point to the transaction pool
        api.e.lock.RLock()
        price := api.e.gasPrice
        api.e.lock.RUnlock()

        api.e.txPool.SetGasPrice(price)
        return api.e.StartMining(true)
    }
    return nil
}

As the miner is not currently mining, api.e.IsMining() returns false, and then executes api.e.StartMining(true) function and returns its return value. Now let's read its implementation, as follows:

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)
    }
    if clique, ok := s.engine.(*clique.Clique); ok {
        wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
        if wallet == nil || err != nil {
            log.Error("Etherbase account unavailable locally", "err", err)
            return fmt.Errorf("singer missing: %v", err)
        }
        clique.Authorize(eb, wallet.SignHash)
    }
    if local {
        // If local (CPU) mining is started, we can disable the transaction rejection
        // mechanism introduced to speed sync times. CPU mining on mainnet is ludicrous
        // so noone will ever hit this path, whereas marking sync done on CPU mining
        // will ensure that private networks work in single miner mode too.
        atomic.StoreUint32(&s.protocolManager.acceptTxs, 1)
    }
    go s.miner.Start(eb)
    return nil
}

Please notice the return value of StartMining(local bool) method.It would return nil if the start mining process is successful, or return a detailed error message otherwise. So it's a frustrating return value, but it doesn't mean that the start mining process failed.

Hope it helps~

  • 1
    Loved the RTFS explanation for the null return code – Alan Buxton Aug 28 '17 at 14:57
  • 1
    Related question. Why is my hash rate 0 even though my block number 633? – tem Apr 18 '18 at 8:54
5

try setting miner.setEtherbase(eth.coinbase)

or step by step:

  1. start Mist browser (let the node synchronize completely)
  2. open console and type: geth attach
  3. miner.setEtherbase(eth.accounts[0])
  4. miner.start()

Even if it returns null you can see in the buttom left corner of Mist broser, that mining has startet. It takes a while till the hashrate incrases. You can check the current hashrate with miner.getHashrate()

  • 1
    Hi there. If you have a NEW question, please ask it by clicking the Ask Question button. If you have sufficient reputation, you may upvote the question. Alternatively, "star" it as a favorite and you will be notified of any new answers. – Richard Horrocks May 12 '17 at 11:00
  • 1
    thanks for your help - Do you have an idea on how to solve the issue as well? – Andi Erni May 12 '17 at 11:31
  • 1
    What does eth.coinbase show on your machine? – Richard Horrocks May 12 '17 at 11:40
  • 1
    it shows my address 0x47Ba2C3c2880dcB31caA3DC644f4e895cB9d9bc4 – Andi Erni May 12 '17 at 11:43
  • 1
    have to say that I am running Mist and have started the console with:geth attach – Andi Erni May 12 '17 at 11:44
2

The null is expected. If you are mining you will see lots of messages in your console like this:

INFO [07-25|18:46:25] Successfully sealed new block number=72 hash=d0316e…36554e INFO [07-25|18:46:25] 🔗 block reached canonical chain number=67 hash=a89be4…5a73be INFO [07-25|18:46:25] 🔨 mined potential block number=72 hash=d0316e…36554e INFO [07-25|18:46:25] Commit new mining work number=73 txs=0 uncles=0 elapsed=158.932µs

Try the following:

eth.hashrate will show you whether you are mining (make sure the number is a non-zero number).

If you are not mining, try explicitly starting the miner with one thread e.g. miner.start(1)

Though I wonder... are you mining on a private network / testnet?

1

Some times the genesis.json with chainId:0 will create this issue, For me below genesis.json helped to solve the issue.

{
"config": {
"chainId": 45,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc" : {},
"coinbase" : "0x75bcb134477f42f6fefbf177f9a610c0665e23a6",
"difficulty" : "0x20000",
"extraData" : "",
"gasLimit" : "0x2fefd8ffffffffff",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}

Try with a fresh datadir, init this json, create account, configure with miner ( setEtherBase ), then start miner

miner.start(1) gave null for me. Also eth.hashrate is also 0. But mining works perfectly...!!!

1

It sometimes so happens that the geth you have attached shows NULL but the other geth console will be showing up the mining trace.

Once you start mining check the other console for which the geth console is attached to, also wait for few minutes and then check for balance.

This happened in my case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.