mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-28 16:13:56 +00:00
Implemented removeOrphan
This commit is contained in:
parent
65da2462b8
commit
9a1d548e7f
@ -38,8 +38,7 @@ func (tobf *TransactionsOrderedByFeeRate) Remove(transaction *MempoolTransaction
|
|||||||
return errors.Errorf("Couldn't find %s in mp.orderedTransactionsByFeeRate", txID)
|
return errors.Errorf("Couldn't find %s in mp.orderedTransactionsByFeeRate", txID)
|
||||||
}
|
}
|
||||||
|
|
||||||
tobf.RemoveAtIndex(index)
|
return tobf.RemoveAtIndex(index)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveAtIndex removes the transaction at the given index.
|
// RemoveAtIndex removes the transaction at the given index.
|
||||||
|
|||||||
@ -7,12 +7,12 @@ import (
|
|||||||
|
|
||||||
// OrphanTransaction represents a transaction in the OrphanPool
|
// OrphanTransaction represents a transaction in the OrphanPool
|
||||||
type OrphanTransaction struct {
|
type OrphanTransaction struct {
|
||||||
transaction *externalapi.DomainTransaction
|
Transaction *externalapi.DomainTransaction
|
||||||
IsHighPriority bool
|
IsHighPriority bool
|
||||||
AddedAtDAAScore uint64
|
AddedAtDAAScore uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// TransactionID returns the ID of this OrphanTransaction
|
// TransactionID returns the ID of this OrphanTransaction
|
||||||
func (ot *OrphanTransaction) TransactionID() *externalapi.DomainTransactionID {
|
func (ot *OrphanTransaction) TransactionID() *externalapi.DomainTransactionID {
|
||||||
return consensushashing.TransactionID(ot.transaction)
|
return consensushashing.TransactionID(ot.Transaction)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,24 +3,25 @@ package mempool
|
|||||||
import (
|
import (
|
||||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||||
"github.com/kaspanet/kaspad/domain/miningmanager/mempool/model"
|
"github.com/kaspanet/kaspad/domain/miningmanager/mempool/model"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type idToOrphan map[externalapi.DomainTransactionID]*model.OrphanTransaction
|
type idToOrphan map[externalapi.DomainTransactionID]*model.OrphanTransaction
|
||||||
type previousOutpointToOrphans map[externalapi.DomainOutpoint]idToOrphan
|
type previousOutpointToOrphans map[externalapi.DomainOutpoint]idToOrphan
|
||||||
|
|
||||||
type orphansPool struct {
|
type orphansPool struct {
|
||||||
mempool *mempool
|
mempool *mempool
|
||||||
allOrphans idToOrphan
|
allOrphans idToOrphan
|
||||||
orphanByPreviousOutpoint previousOutpointToOrphans
|
orphansByPreviousOutpoint previousOutpointToOrphans
|
||||||
lastExpireScan uint64
|
lastExpireScan uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func newOrphansPool(mp *mempool) *orphansPool {
|
func newOrphansPool(mp *mempool) *orphansPool {
|
||||||
return &orphansPool{
|
return &orphansPool{
|
||||||
mempool: mp,
|
mempool: mp,
|
||||||
allOrphans: idToOrphan{},
|
allOrphans: idToOrphan{},
|
||||||
orphanByPreviousOutpoint: previousOutpointToOrphans{},
|
orphansByPreviousOutpoint: previousOutpointToOrphans{},
|
||||||
lastExpireScan: 0,
|
lastExpireScan: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,8 +41,41 @@ func (op *orphansPool) unorphanTransaction(orphanTransactionID *externalapi.Doma
|
|||||||
panic("orphansPool.unorphanTransaction not implemented") // TODO (Mike)
|
panic("orphansPool.unorphanTransaction not implemented") // TODO (Mike)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *orphansPool) removeOrphan(orphanTransactionID *externalapi.DomainTransactionID) error {
|
func (op *orphansPool) removeOrphan(orphanTransactionID *externalapi.DomainTransactionID, removeRedeemers bool) error {
|
||||||
panic("orphansPool.removeOrphan not implemented") // TODO (Mike)
|
orphanTransaction, ok := op.allOrphans[*orphanTransactionID]
|
||||||
|
if !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(op.allOrphans, orphanTransactionID)
|
||||||
|
|
||||||
|
for i, input := range orphanTransaction.Transaction.Inputs {
|
||||||
|
orphans, ok := op.orphansByPreviousOutpoint[input.PreviousOutpoint]
|
||||||
|
if !ok {
|
||||||
|
return errors.Errorf("Input No. %d of %s (%s) doesn't exist in orphansByPreviousOutpoint",
|
||||||
|
i, orphanTransactionID, input.PreviousOutpoint)
|
||||||
|
}
|
||||||
|
delete(orphans, *orphanTransactionID)
|
||||||
|
if len(orphans) == 0 {
|
||||||
|
delete(op.orphansByPreviousOutpoint, input.PreviousOutpoint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if removeRedeemers {
|
||||||
|
outpoint := externalapi.DomainOutpoint{TransactionID: *orphanTransactionID}
|
||||||
|
for i := range orphanTransaction.Transaction.Outputs {
|
||||||
|
outpoint.Index = uint32(i)
|
||||||
|
for _, orphan := range op.orphansByPreviousOutpoint[outpoint] {
|
||||||
|
// Recursive call is bound by size of orphan pool (which is very small)
|
||||||
|
err := op.removeOrphan(orphan.TransactionID(), true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *orphansPool) expireOrphanTransactions() error {
|
func (op *orphansPool) expireOrphanTransactions() error {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user