-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miner/worker: broadcast block immediately once sealed #2576
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -729,7 +729,7 @@ func (h *handler) Start(maxPeers int, maxPeersPerIP int) { | |
|
||
// broadcast mined blocks | ||
h.wg.Add(1) | ||
h.minedBlockSub = h.eventMux.Subscribe(core.NewMinedBlockEvent{}) | ||
h.minedBlockSub = h.eventMux.Subscribe(core.NewMinedBlockEvent{}, core.NewSealedBlockEvent{}) | ||
go h.minedBroadcastLoop() | ||
|
||
// start sync handlers | ||
|
@@ -946,8 +946,9 @@ func (h *handler) minedBroadcastLoop() { | |
if obj == nil { | ||
continue | ||
} | ||
if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok { | ||
h.BroadcastBlock(ev.Block, true) // First propagate block to peers | ||
if ev, ok := obj.Data.(core.NewSealedBlockEvent); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure how exactly this improves things? Could you clarify bit more? |
||
h.BroadcastBlock(ev.Block, true) // Propagate block to peers | ||
} else if ev, ok := obj.Data.(core.NewMinedBlockEvent); ok { | ||
h.BroadcastBlock(ev.Block, false) // Only then announce to the rest | ||
} | ||
case <-h.stopCh: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,7 +665,7 @@ func (w *worker) resultLoop() { | |
// Commit block and state to database. | ||
task.state.SetExpectedStateRoot(block.Root()) | ||
start := time.Now() | ||
status, err := w.chain.WriteBlockAndSetHead(block, receipts, logs, task.state, true) | ||
status, err := w.chain.WriteBlockAndSetHead(block, receipts, logs, task.state, true, w.mux) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @emailtovamos this happens after double sign |
||
if status != core.CanonStatTy { | ||
if err != nil { | ||
log.Error("Failed writing block to chain", "err", err, "status", status) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
writeBlockWithState cost much, may be hundreds of milliseconds
we can post a NewSealedBlockEvent before it, so broadcast it early @emailtovamos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, understood.
But if
writeBlockWithState()
fails for some reason then it is still okay to post aNewSealedBlockEvent
? This is my only doubt.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
every verification has been passed when do
writeBlockWithState
.if a miner has a bad db, cause failed to writeBlockWithState. It's ok, others will write the mined block into db.
if the block is bad, cause failed to writeBlockWithState. It's ok, others will reject the mined block into db.