mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-28 16:13:56 +00:00
Rename isHighPriority to neverExpires
This commit is contained in:
parent
ff10ce145a
commit
b2da9a4a00
@ -27,7 +27,7 @@ func newMempool(consensus externalapi.Consensus, dagParams *dagconfig.Params) *m
|
||||
return mp
|
||||
}
|
||||
|
||||
func (mp *mempool) ValidateAndInsertTransaction(transaction *externalapi.DomainTransaction, isHighPriority bool) (
|
||||
func (mp *mempool) ValidateAndInsertTransaction(transaction *externalapi.DomainTransaction, neverExpires bool) (
|
||||
acceptedTransactions []*externalapi.DomainTransaction, err error) {
|
||||
|
||||
panic("mempool.ValidateAndInsertTransaction not implemented") // TODO (Mike)
|
||||
|
||||
@ -6,11 +6,12 @@ import (
|
||||
)
|
||||
|
||||
type idToTransaction map[externalapi.DomainTransactionID]*mempoolTransaction
|
||||
type idToOrphan map[externalapi.DomainTransactionID]*orphanTransaction
|
||||
|
||||
type mempoolTransaction struct {
|
||||
transaction *externalapi.DomainTransaction
|
||||
parentsInPool idToTransaction
|
||||
isHighPriority bool
|
||||
neverExpires bool
|
||||
addAtDAAScore uint64
|
||||
}
|
||||
|
||||
@ -20,7 +21,7 @@ func (mt *mempoolTransaction) transactionID() *externalapi.DomainTransactionID {
|
||||
|
||||
type orphanTransaction struct {
|
||||
transaction *externalapi.DomainTransaction
|
||||
isHighPriority bool
|
||||
neverExpires bool
|
||||
addedAtDAAScore uint64
|
||||
}
|
||||
|
||||
|
||||
@ -1,12 +1,14 @@
|
||||
package mempool
|
||||
|
||||
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
import (
|
||||
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
||||
)
|
||||
|
||||
type previousOutpointToOrphans map[externalapi.DomainOutpoint]idToTransaction
|
||||
type previousOutpointToOrphans map[externalapi.DomainOutpoint]idToOrphan
|
||||
|
||||
type orphansPool struct {
|
||||
mempool *mempool
|
||||
allOrphans idToTransaction
|
||||
allOrphans idToOrphan
|
||||
orphanByPreviousOutpoint previousOutpointToOrphans
|
||||
lastExpireScan uint64
|
||||
}
|
||||
@ -14,14 +16,14 @@ type orphansPool struct {
|
||||
func newOrphansPool(mp *mempool) *orphansPool {
|
||||
return &orphansPool{
|
||||
mempool: mp,
|
||||
allOrphans: idToTransaction{},
|
||||
allOrphans: idToOrphan{},
|
||||
orphanByPreviousOutpoint: previousOutpointToOrphans{},
|
||||
lastExpireScan: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (op *orphansPool) maybeAddOrphan(transaction *externalapi.DomainTransaction,
|
||||
missingParents []*externalapi.DomainTransactionID, isHighPriority bool) error {
|
||||
missingParents []*externalapi.DomainTransactionID, neverExpires bool) error {
|
||||
|
||||
panic("orphansPool.maybeAddOrphan not implemented") // TODO (Mike)
|
||||
}
|
||||
@ -36,8 +38,37 @@ func (op *orphansPool) unorphanTransaction(orphanTransactionID *externalapi.Doma
|
||||
panic("orphansPool.unorphanTransaction not implemented") // TODO (Mike)
|
||||
}
|
||||
|
||||
func (op *orphansPool) removeOrphan(orphanTransactionID *externalapi.DomainTransactionID) error {
|
||||
panic("orphansPool.removeOrphan not implemented") // TODO (Mike)
|
||||
func (op *orphansPool) removeOrphan(orphanTransactionID *externalapi.DomainTransactionID, removeRedeemers bool) {
|
||||
var orphanTransaction *orphanTransaction
|
||||
var ok bool
|
||||
if orphanTransaction, ok = op.allOrphans[*orphanTransactionID]; !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// Remove orphan from allOrphans
|
||||
delete(op.allOrphans, *orphanTransactionID)
|
||||
|
||||
// Remove orphan from all relevant entries in orphanByPreviousOutpoint
|
||||
for _, input := range orphanTransaction.transaction.Inputs {
|
||||
if orphans, ok := op.orphanByPreviousOutpoint[input.PreviousOutpoint]; ok {
|
||||
delete(orphans, orphanTransactionID)
|
||||
if len(orphans) == 0 {
|
||||
delete(op.orphanByPreviousOutpoint, input.PreviousOutpoint)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively remove redeemers if requested.
|
||||
// Since the size of the orphan pool is very limited - the recursion depth is properly bound.
|
||||
if removeRedeemers {
|
||||
outpoint := externalapi.DomainOutpoint{TransactionID: *orphanTransactionID}
|
||||
for i := range orphanTransaction.transaction.Outputs {
|
||||
outpoint.Index = uint32(i)
|
||||
for _, orphanRedeemer := range op.orphanByPreviousOutpoint[outpoint] {
|
||||
op.removeOrphan(orphanRedeemer.transactionID(), true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (op *orphansPool) expireOrphanTransactions() error {
|
||||
@ -52,7 +83,7 @@ func (op *orphansPool) expireOrphanTransactions() error {
|
||||
|
||||
for _, orphanTransaction := range op.allOrphans {
|
||||
// Never expire high priority transactions
|
||||
if orphanTransaction.isHighPriority {
|
||||
if orphanTransaction.neverExpires {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ func (tp *transactionsPool) expireOldTransactions() error {
|
||||
|
||||
for _, mempoolTransaction := range tp.allTransactions {
|
||||
// Never expire high priority transactions
|
||||
if mempoolTransaction.isHighPriority {
|
||||
if mempoolTransaction.neverExpires {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user