From a565777178fb8610b0372614ccf28ea95886f5e2 Mon Sep 17 00:00:00 2001 From: gop Date: Wed, 5 Jun 2024 17:54:57 -0500 Subject: [PATCH 1/2] bugfix: the ancestor calculation inside the commitUncle method --- core/worker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/worker.go b/core/worker.go index 8d675a340f..6e2b3afaff 100644 --- a/core/worker.go +++ b/core/worker.go @@ -690,14 +690,6 @@ func (w *worker) makeEnv(parent *types.WorkObject, proposedWo *types.WorkObject, etxRLimit: etxRLimit, etxPLimit: etxPLimit, } - // when 08 is processed ancestors contain 07 (quick block) - for _, ancestor := range w.hc.GetBlocksFromHash(parent.Header().Hash(), params.WorkSharesInclusionDepth) { - for _, uncle := range ancestor.Uncles() { - env.family.Add(uncle.Hash()) - } - env.family.Add(ancestor.Hash()) - env.ancestors.Add(ancestor.Hash()) - } // Keep track of transactions which return errors so they can be removed env.tcount = 0 return env, nil @@ -709,6 +701,14 @@ func (w *worker) commitUncle(env *environment, uncle *types.WorkObjectHeader) er defer env.uncleMu.Unlock() hash := uncle.Hash() + for _, ancestor := range w.hc.GetBlocksFromHash(env.wo.ParentHash(common.ZONE_CTX), params.WorkSharesInclusionDepth) { + for _, uncle := range ancestor.Uncles() { + env.family.Add(uncle.Hash()) + } + env.family.Add(ancestor.Hash()) + env.ancestors.Add(ancestor.Hash()) + } + if _, exist := env.uncles[hash]; exist { return errors.New("uncle not unique") } From 03d45b426a377c5c7a80cf9c0a1228adb0655bc6 Mon Sep 17 00:00:00 2001 From: gop Date: Wed, 5 Jun 2024 18:25:51 -0500 Subject: [PATCH 2/2] Allow sibling inclusion for workshares --- consensus/blake3pow/consensus.go | 11 +++++++++-- consensus/progpow/consensus.go | 11 +++++++++-- core/worker.go | 8 +++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/consensus/blake3pow/consensus.go b/consensus/blake3pow/consensus.go index 4217bf6948..0c4021fa91 100644 --- a/consensus/blake3pow/consensus.go +++ b/consensus/blake3pow/consensus.go @@ -238,12 +238,19 @@ func (blake3pow *Blake3pow) VerifyUncles(chain consensus.ChainReader, block *typ if ancestors[hash] != nil { return errUncleIsAncestor } - if ancestors[uncle.ParentHash()] == nil || uncle.ParentHash() == block.ParentHash(nodeCtx) { + // Siblings are not allowed to be included in the workshares list if its an + // uncle but can be if its a workshare + var workShare bool + _, err := blake3pow.VerifySeal(uncle) + if err != nil { + workShare = true + } + if ancestors[uncle.ParentHash()] == nil || (!workShare && (uncle.ParentHash() == block.ParentHash(nodeCtx))) { return errDanglingUncle } // make sure that the work can be computed - _, err := blake3pow.ComputePowHash(uncle) + _, err = blake3pow.ComputePowHash(uncle) if err != nil { return err } diff --git a/consensus/progpow/consensus.go b/consensus/progpow/consensus.go index 5d876bfb6a..8820e4e291 100644 --- a/consensus/progpow/consensus.go +++ b/consensus/progpow/consensus.go @@ -241,10 +241,17 @@ func (progpow *Progpow) VerifyUncles(chain consensus.ChainReader, block *types.W if ancestors[hash] != nil { return errUncleIsAncestor } - if ancestors[uncle.ParentHash()] == nil || uncle.ParentHash() == block.ParentHash(nodeCtx) { + // Siblings are not allowed to be included in the workshares list if its an + // uncle but can be if its a workshare + var workShare bool + _, err := progpow.VerifySeal(uncle) + if err != nil { + workShare = true + } + if ancestors[uncle.ParentHash()] == nil || (!workShare && (uncle.ParentHash() == block.ParentHash(nodeCtx))) { return errDanglingUncle } - _, err := progpow.ComputePowHash(uncle) + _, err = progpow.ComputePowHash(uncle) if err != nil { return err } diff --git a/core/worker.go b/core/worker.go index 6e2b3afaff..3953204375 100644 --- a/core/worker.go +++ b/core/worker.go @@ -712,7 +712,13 @@ func (w *worker) commitUncle(env *environment, uncle *types.WorkObjectHeader) er if _, exist := env.uncles[hash]; exist { return errors.New("uncle not unique") } - if env.wo.ParentHash(w.hc.NodeCtx()) == uncle.ParentHash() { + var workShare bool + // If the uncle is a workshare, we should allow siblings + _, err := w.engine.VerifySeal(uncle) + if err != nil { + workShare = true + } + if !workShare && (env.wo.ParentHash(w.hc.NodeCtx()) == uncle.ParentHash()) { return errors.New("uncle is sibling") } if !env.ancestors.Contains(uncle.ParentHash()) {