Skip to content
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

bugfix with uncle inclusion and also allow sibling inclusion for workshares #1838

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions consensus/blake3pow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 9 additions & 2 deletions consensus/progpow/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
24 changes: 15 additions & 9 deletions core/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -709,10 +701,24 @@ 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")
}
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()) {
Expand Down
Loading