Skip to content

Commit c6cb43b

Browse files
committed
Revert "miner/worker: broadcast block immediately once sealed (#2576)"
This reverts commit 6d5b4ad.
1 parent 222e108 commit c6cb43b

File tree

4 files changed

+12
-20
lines changed

4 files changed

+12
-20
lines changed

core/blockchain.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,30 +1914,26 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
19141914

19151915
// WriteBlockAndSetHead writes the given block and all associated state to the database,
19161916
// and applies the block as the new chain head.
1917-
func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool, mux *event.TypeMux) (status WriteStatus, err error) {
1917+
func (bc *BlockChain) WriteBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
19181918
if !bc.chainmu.TryLock() {
19191919
return NonStatTy, errChainStopped
19201920
}
19211921
defer bc.chainmu.Unlock()
19221922

1923-
return bc.writeBlockAndSetHead(block, receipts, logs, state, emitHeadEvent, mux)
1923+
return bc.writeBlockAndSetHead(block, receipts, logs, state, emitHeadEvent)
19241924
}
19251925

19261926
// writeBlockAndSetHead is the internal implementation of WriteBlockAndSetHead.
19271927
// This function expects the chain mutex to be held.
1928-
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool, mux *event.TypeMux) (status WriteStatus, err error) {
1928+
func (bc *BlockChain) writeBlockAndSetHead(block *types.Block, receipts []*types.Receipt, logs []*types.Log, state *state.StateDB, emitHeadEvent bool) (status WriteStatus, err error) {
1929+
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
1930+
return NonStatTy, err
1931+
}
19291932
currentBlock := bc.CurrentBlock()
19301933
reorg, err := bc.forker.ReorgNeededWithFastFinality(currentBlock, block.Header())
19311934
if err != nil {
19321935
return NonStatTy, err
19331936
}
1934-
if reorg && mux != nil {
1935-
mux.Post(NewSealedBlockEvent{Block: block})
1936-
}
1937-
1938-
if err := bc.writeBlockWithState(block, receipts, state); err != nil {
1939-
return NonStatTy, err
1940-
}
19411937
if reorg {
19421938
// Reorganise the chain if the parent is not the head block
19431939
if block.ParentHash() != currentBlock.Hash() {
@@ -2310,7 +2306,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
23102306
// Don't set the head, only insert the block
23112307
err = bc.writeBlockWithState(block, receipts, statedb)
23122308
} else {
2313-
status, err = bc.writeBlockAndSetHead(block, receipts, logs, statedb, false, nil)
2309+
status, err = bc.writeBlockAndSetHead(block, receipts, logs, statedb, false)
23142310
}
23152311
if err != nil {
23162312
return it.index, err

core/events.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ type NewTxsEvent struct{ Txs []*types.Transaction }
2727
// ReannoTxsEvent is posted when a batch of local pending transactions exceed a specified duration.
2828
type ReannoTxsEvent struct{ Txs []*types.Transaction }
2929

30-
// NewSealedBlockEvent is posted when a block has been sealed.
31-
type NewSealedBlockEvent struct{ Block *types.Block }
32-
33-
// NewMinedBlockEvent is posted when a block has been mined.
30+
// NewMinedBlockEvent is posted when a block has been imported.
3431
type NewMinedBlockEvent struct{ Block *types.Block }
3532

3633
// RemovedLogsEvent is posted when a reorg happens

eth/handler.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ func (h *handler) Start(maxPeers int, maxPeersPerIP int) {
729729

730730
// broadcast mined blocks
731731
h.wg.Add(1)
732-
h.minedBlockSub = h.eventMux.Subscribe(core.NewMinedBlockEvent{}, core.NewSealedBlockEvent{})
732+
h.minedBlockSub = h.eventMux.Subscribe(core.NewMinedBlockEvent{})
733733
go h.minedBroadcastLoop()
734734

735735
// start sync handlers
@@ -946,9 +946,8 @@ func (h *handler) minedBroadcastLoop() {
946946
if obj == nil {
947947
continue
948948
}
949-
if ev, ok := obj.Data.(core.NewSealedBlockEvent); ok {
950-
h.BroadcastBlock(ev.Block, true) // Propagate block to peers
951-
} else if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
949+
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok {
950+
h.BroadcastBlock(ev.Block, true) // First propagate block to peers
952951
h.BroadcastBlock(ev.Block, false) // Only then announce to the rest
953952
}
954953
case <-h.stopCh:

miner/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ func (w *worker) resultLoop() {
665665
// Commit block and state to database.
666666
task.state.SetExpectedStateRoot(block.Root())
667667
start := time.Now()
668-
status, err := w.chain.WriteBlockAndSetHead(block, receipts, logs, task.state, true, w.mux)
668+
status, err := w.chain.WriteBlockAndSetHead(block, receipts, logs, task.state, true)
669669
if status != core.CanonStatTy {
670670
if err != nil {
671671
log.Error("Failed writing block to chain", "err", err, "status", status)

0 commit comments

Comments
 (0)