From 6d6a5a93370371a33fb815d7ae47b60c7021c86a Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Tue, 24 Oct 2017 13:40:42 +0300 Subject: cmd, consensus, core, miner: instatx clique for --dev (#15323) * cmd, consensus, core, miner: instatx clique for --dev * cmd, consensus, clique: support configurable --dev block times * cmd, core: allow --dev to use persistent storage too --- consensus/clique/clique.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'consensus/clique/clique.go') diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 8d6cf653d..6892d8390 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -125,6 +125,11 @@ var ( // errUnauthorized is returned if a header is signed by a non-authorized entity. errUnauthorized = errors.New("unauthorized") + + // errWaitTransactions is returned if an empty block is attempted to be sealed + // on an instant chain (0 second period). It's important to refuse these as the + // block reward is zero, so an empty block just bloats the chain... fast. + errWaitTransactions = errors.New("waiting for transactions") ) // SignerFn is a signer callback function to request a hash to be signed by a @@ -211,9 +216,6 @@ func New(config *params.CliqueConfig, db ethdb.Database) *Clique { if conf.Epoch == 0 { conf.Epoch = epochLength } - if conf.Period == 0 { - conf.Period = blockPeriod - } // Allocate the snapshot caches and create the engine recents, _ := lru.NewARC(inmemorySnapshots) signatures, _ := lru.NewARC(inmemorySignatures) @@ -599,6 +601,10 @@ func (c *Clique) Seal(chain consensus.ChainReader, block *types.Block, stop <-ch if number == 0 { return nil, errUnknownBlock } + // For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing) + if c.config.Period == 0 && len(block.Transactions()) == 0 { + return nil, errWaitTransactions + } // Don't hold the signer fields for the entire sealing procedure c.lock.RLock() signer, signFn := c.signer, c.signFn -- cgit