aboutsummaryrefslogtreecommitdiffstats
path: root/consensus/clique
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-10-24 18:40:42 +0800
committerGitHub <noreply@github.com>2017-10-24 18:40:42 +0800
commit6d6a5a93370371a33fb815d7ae47b60c7021c86a (patch)
treeaa73dff1db3aa2566c2e74cf9ac37f13878fae80 /consensus/clique
parentea5f2da39ad198e58107a79214419e31988c5e5a (diff)
downloaddexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar.gz
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar.bz2
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar.lz
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar.xz
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.tar.zst
dexon-6d6a5a93370371a33fb815d7ae47b60c7021c86a.zip
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
Diffstat (limited to 'consensus/clique')
-rw-r--r--consensus/clique/clique.go12
-rw-r--r--consensus/clique/snapshot_test.go2
2 files changed, 10 insertions, 4 deletions
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
diff --git a/consensus/clique/snapshot_test.go b/consensus/clique/snapshot_test.go
index a1717d799..8b51e6e09 100644
--- a/consensus/clique/snapshot_test.go
+++ b/consensus/clique/snapshot_test.go
@@ -74,7 +74,7 @@ type testerChainReader struct {
db ethdb.Database
}
-func (r *testerChainReader) Config() *params.ChainConfig { return params.AllProtocolChanges }
+func (r *testerChainReader) Config() *params.ChainConfig { return params.AllCliqueProtocolChanges }
func (r *testerChainReader) CurrentHeader() *types.Header { panic("not supported") }
func (r *testerChainReader) GetHeader(common.Hash, uint64) *types.Header { panic("not supported") }
func (r *testerChainReader) GetBlock(common.Hash, uint64) *types.Block { panic("not supported") }