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

mining: Fix duplicate txns in the prio heap. #1108

Merged
merged 1 commit into from
Mar 3, 2018
Merged
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
32 changes: 13 additions & 19 deletions mining.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main

import (
"container/heap"
"container/list"
"encoding/binary"
"fmt"
"math"
Expand Down Expand Up @@ -659,13 +658,12 @@ func spendTransaction(utxoView *blockchain.UtxoViewpoint, tx *dcrutil.Tx,

// logSkippedDeps logs any dependencies which are also skipped as a result of
// skipping a transaction while generating a block template at the trace level.
func logSkippedDeps(tx *dcrutil.Tx, deps *list.List) {
func logSkippedDeps(tx *dcrutil.Tx, deps map[chainhash.Hash]*txPrioItem) {
if deps == nil {
return
}

for e := deps.Front(); e != nil; e = e.Next() {
item := e.Value.(*txPrioItem)
for _, item := range deps {
minrLog.Tracef("Skipping tx %s since it depends on %s\n",
item.tx.Hash(), tx.Hash())
}
Expand Down Expand Up @@ -1265,7 +1263,7 @@ func NewBlockTemplate(policy *mining.Policy, server *server,
// dependsOn map kept with each dependent transaction helps quickly
// determine which dependent transactions are now eligible for inclusion
// 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
// for each of the selected transactions and add an entry for the
Expand Down Expand Up @@ -1351,12 +1349,12 @@ mempoolLoop:
// The transaction is referencing another
// transaction in the source pool, so setup an
// ordering dependency.
depList, exists := dependers[*originHash]
deps, exists := dependers[*originHash]
if !exists {
depList = list.New()
dependers[*originHash] = depList
deps = make(map[chainhash.Hash]*txPrioItem)
dependers[*originHash] = deps
}
depList.PushBack(prioItem)
deps[*prioItem.tx.Hash()] = prioItem
if prioItem.dependsOn == nil {
prioItem.dependsOn = make(
map[chainhash.Hash]struct{})
Expand Down Expand Up @@ -1632,16 +1630,12 @@ mempoolLoop:
// Add transactions which depend on this one (and also do not
// have any other unsatisified dependencies) to the priority
// queue.
if deps != nil {
for e := deps.Front(); e != nil; e = e.Next() {
// Add the transaction to the priority queue if
// there are no more dependencies after this
// one.
item := e.Value.(*txPrioItem)
delete(item.dependsOn, *tx.Hash())
if len(item.dependsOn) == 0 {
heap.Push(priorityQueue, item)
}
for _, item := range deps {
// Add the transaction to the priority queue if there
// are no more dependencies after this one.
delete(item.dependsOn, *tx.Hash())
if len(item.dependsOn) == 0 {
heap.Push(priorityQueue, item)
}
}
}
Expand Down