6

The Clique consensus seems to be always sealing a new block at fixed intervals of period seconds, where period is the setting in the genesis block (config.clique.period).

That seems wasteful, indeed Parity's Aura only signs empty blocks when a transaction is recorded or a transfer to another node takes place (normally every 120 seconds, see --reseal-on-txs and --reseal-min-period args).

Is it possible to get geth to work like that? I don't care about immediate resealing, but it would be really nice to skip empty blocks, even if not completely.

1
  • 8
    In geth if you set clique period to 0, it will only create new block when there is transaction. Commented Aug 9, 2018 at 13:10

3 Answers 3

5

Geth doesn't have a predefined flag to achieve this but you can write and then --preload .js files in geth - I use this approach on our private network to only seal blocks when there are new transactions.

3
  • 1
    hyperlink fixed, sorry - I don't use eth-mine-when-needed, I use a JS file very similar to the answer linked to above. We use Clique as we have no need for PoW on our private network
    – TC8
    Commented Apr 8, 2018 at 14:13
  • 1
    Interesting, thanks. I got a variant of it to work, though for "X confirmations" I had to run the script on only one of the 2 signer nodes. It probably won't work at all in a 3+ signer setup.
    – rustyx
    Commented Apr 9, 2018 at 7:35
  • 1
    it can work on all signers in a network if you modify the script slightly - if(eth.getBlock("pending").transactions.length > 0 || eth.getBlock("latest").transactions.length > 0) {<start mining>.... This means all sealers will start sealing whenever a new tx is added, even if they miss the trigger in the tx pool
    – TC8
    Commented Apr 9, 2018 at 9:42
3

All you have to do is set period:0 in the genesis.json file to achieve this sealing behavior.

1

AFAIK it's not possible to do that with GETH without making significant modifications to the source code. There are some "tricks" that you can use on PoW networks to only mine when transactions have been committed to the blockchain. I imagine you could do the same with PoA. That being said, if you want to skip empty blocks, why not just go with Aura and Parity?

How to stop mining unwanted blocks on private net on geth ethrereum

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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