gatherUncles¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | miner/worker.go |
uncles_pow.go |
| Symbol | worker.prepareWork (lines 1032-1048) |
powWorker.gatherUncles |
| Ref | dde2da0ef~1 |
etc/v1.17.3-full-node |
Selects up to two valid uncles, preferring local ones. Transplanted from the commitUncles closure inside the pre-purge prepareWork.
Diff — vs pre-nuke original (reimplemented)¶
--- a/miner/worker.go
+++ b/miner/uncles_pow.go
@@ -1,10 +1,13 @@
- if !genParams.noUncle {
- commitUncles := func(blocks map[common.Hash]*types.Block) {
+// gatherUncles selects up to two valid uncles for the block whose header is
+// being sealed, preferring locally mined ones.
+func (w *powWorker) gatherUncles(header *types.Header) []*types.Header {
+ env := w.newUncleEnv(header)
+ commitUncles := func(blocks map[common.Hash]*types.Header) {
for hash, uncle := range blocks {
if len(env.uncles) == 2 {
break
}
- if err := w.commitUncle(env, uncle.Header()); err != nil {
+ if err := env.commitUncle(uncle); err != nil {
log.Trace("Possible uncle rejected", "hash", hash, "reason", err)
} else {
log.Debug("Committing new uncle to block", "hash", hash)
@@ -14,4 +17,5 @@
// Prefer to locally generated uncle
commitUncles(w.localUncles)
commitUncles(w.remoteUncles)
- }
+ return env.unclelist()
+}