diff --git a/core/blockchain.go b/core/blockchain.go index b33eb85a44..7755abe63b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -47,8 +47,8 @@ import ( var ( blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil) - - ErrNoGenesis = errors.New("Genesis not found in chain") + Checkpoint = make(chan int) + ErrNoGenesis = errors.New("Genesis not found in chain") ) const ( @@ -1185,6 +1185,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty stats.processed++ stats.usedGas += usedGas stats.report(chain, i, bc.stateCache.TrieDB().Size()) + if i == len(chain)-1 { + if (bc.chainConfig.Clique != nil) && (chain[i].NumberU64()%bc.chainConfig.Clique.Epoch) == 0 { + Checkpoint <- 1 + } + } } // Append a single chain head event if we've progressed the chain if lastCanon != nil && bc.CurrentBlock().Hash() == lastCanon.Hash() { @@ -1422,11 +1427,9 @@ func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, e log.Error(fmt.Sprintf(` ########## BAD BLOCK ######### Chain config: %v - Number: %v Hash: 0x%x %v - Error: %v ############################## `, bc.chainConfig, block.Number(), block.Hash(), receiptString, err)) @@ -1561,4 +1564,4 @@ func (bc *BlockChain) SubscribeChainSideEvent(ch chan<- ChainSideEvent) event.Su // SubscribeLogsEvent registers a subscription of []*types.Log. func (bc *BlockChain) SubscribeLogsEvent(ch chan<- []*types.Log) event.Subscription { return bc.scope.Track(bc.logsFeed.Subscribe(ch)) -} +} \ No newline at end of file diff --git a/miner/worker.go b/miner/worker.go index 15395ae0b9..4f9ce13d70 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -488,6 +488,9 @@ func (self *worker) commitNewWork() { log.Info("Commit new mining work", "number", work.Block.Number(), "txs", work.tcount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart))) self.unconfirmed.Shift(work.Block.NumberU64() - 1) } + if (work.config.Clique != nil) && (work.Block.NumberU64()%work.config.Clique.Epoch) == 0 { + core.Checkpoint <- 1 + } self.push(work) } @@ -601,4 +604,4 @@ func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, c env.receipts = append(env.receipts, receipt) return nil, receipt.Logs -} +} \ No newline at end of file