mirror of
https://github.com/LBRYFoundation/lbcd.git
synced 2025-08-30 17:01:29 +00:00
mining: Fix duplicate transactions in prio heap
This commit is contained in:
parent
e306158e25
commit
54b454ed3d
1 changed files with 13 additions and 19 deletions
32
mining.go
32
mining.go
|
@ -6,7 +6,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"container/list"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -266,13 +265,12 @@ func spendTransaction(utxoView *blockchain.UtxoViewpoint, tx *btcutil.Tx, height
|
||||||
|
|
||||||
// logSkippedDeps logs any dependencies which are also skipped as a result of
|
// logSkippedDeps logs any dependencies which are also skipped as a result of
|
||||||
// skipping a transaction while generating a block template at the trace level.
|
// skipping a transaction while generating a block template at the trace level.
|
||||||
func logSkippedDeps(tx *btcutil.Tx, deps *list.List) {
|
func logSkippedDeps(tx *btcutil.Tx, deps map[chainhash.Hash]*txPrioItem) {
|
||||||
if deps == nil {
|
if deps == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for e := deps.Front(); e != nil; e = e.Next() {
|
for _, item := range deps {
|
||||||
item := e.Value.(*txPrioItem)
|
|
||||||
minrLog.Tracef("Skipping tx %s since it depends on %s\n",
|
minrLog.Tracef("Skipping tx %s since it depends on %s\n",
|
||||||
item.tx.Hash(), tx.Hash())
|
item.tx.Hash(), tx.Hash())
|
||||||
}
|
}
|
||||||
|
@ -434,7 +432,7 @@ func NewBlockTemplate(policy *mining.Policy, server *server, payToAddress btcuti
|
||||||
// dependsOn map kept with each dependent transaction helps quickly
|
// dependsOn map kept with each dependent transaction helps quickly
|
||||||
// determine which dependent transactions are now eligible for inclusion
|
// determine which dependent transactions are now eligible for inclusion
|
||||||
// in the block once each transaction has been included.
|
// in the block once each transaction has been included.
|
||||||
dependers := make(map[chainhash.Hash]*list.List)
|
dependers := make(map[chainhash.Hash]map[chainhash.Hash]*txPrioItem)
|
||||||
|
|
||||||
// Create slices to hold the fees and number of signature operations
|
// Create slices to hold the fees and number of signature operations
|
||||||
// for each of the selected transactions and add an entry for the
|
// for each of the selected transactions and add an entry for the
|
||||||
|
@ -498,12 +496,12 @@ mempoolLoop:
|
||||||
// The transaction is referencing another
|
// The transaction is referencing another
|
||||||
// transaction in the source pool, so setup an
|
// transaction in the source pool, so setup an
|
||||||
// ordering dependency.
|
// ordering dependency.
|
||||||
depList, exists := dependers[*originHash]
|
deps, exists := dependers[*originHash]
|
||||||
if !exists {
|
if !exists {
|
||||||
depList = list.New()
|
deps = make(map[chainhash.Hash]*txPrioItem)
|
||||||
dependers[*originHash] = depList
|
dependers[*originHash] = deps
|
||||||
}
|
}
|
||||||
depList.PushBack(prioItem)
|
deps[*prioItem.tx.Hash()] = prioItem
|
||||||
if prioItem.dependsOn == nil {
|
if prioItem.dependsOn == nil {
|
||||||
prioItem.dependsOn = make(
|
prioItem.dependsOn = make(
|
||||||
map[chainhash.Hash]struct{})
|
map[chainhash.Hash]struct{})
|
||||||
|
@ -686,16 +684,12 @@ mempoolLoop:
|
||||||
// Add transactions which depend on this one (and also do not
|
// Add transactions which depend on this one (and also do not
|
||||||
// have any other unsatisified dependencies) to the priority
|
// have any other unsatisified dependencies) to the priority
|
||||||
// queue.
|
// queue.
|
||||||
if deps != nil {
|
for _, item := range deps {
|
||||||
for e := deps.Front(); e != nil; e = e.Next() {
|
// Add the transaction to the priority queue if there
|
||||||
// Add the transaction to the priority queue if
|
// are no more dependencies after this one.
|
||||||
// there are no more dependencies after this
|
delete(item.dependsOn, *tx.Hash())
|
||||||
// one.
|
if len(item.dependsOn) == 0 {
|
||||||
item := e.Value.(*txPrioItem)
|
heap.Push(priorityQueue, item)
|
||||||
delete(item.dependsOn, *tx.Hash())
|
|
||||||
if len(item.dependsOn) == 0 {
|
|
||||||
heap.Push(priorityQueue, item)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue