Mike Zak b412cd9bbc Revert "Rename isHighPriority to neverExpires"
This reverts commit b2da9a4a00c02fb380d2518cf54fa16257bd8423.
2021-06-07 09:50:26 +03:00

71 lines
2.2 KiB
Go

package mempool
import "github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
type previousOutpointToOrphans map[externalapi.DomainOutpoint]idToTransaction
type orphansPool struct {
mempool *mempool
allOrphans idToTransaction
orphanByPreviousOutpoint previousOutpointToOrphans
lastExpireScan uint64
}
func newOrphansPool(mp *mempool) *orphansPool {
return &orphansPool{
mempool: mp,
allOrphans: idToTransaction{},
orphanByPreviousOutpoint: previousOutpointToOrphans{},
lastExpireScan: 0,
}
}
func (op *orphansPool) maybeAddOrphan(transaction *externalapi.DomainTransaction,
missingParents []*externalapi.DomainTransactionID, isHighPriority bool) error {
panic("orphansPool.maybeAddOrphan not implemented") // TODO (Mike)
}
func (op *orphansPool) processOrphansAfterAcceptedTransaction(acceptedTransaction *mempoolTransaction) (
acceptedOrphans []*mempoolTransaction, err error) {
panic("orphansPool.processOrphansAfterAcceptedTransaction not implemented") // TODO (Mike)
}
func (op *orphansPool) unorphanTransaction(orphanTransactionID *externalapi.DomainTransactionID) (mempoolTransaction, error) {
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) expireOrphanTransactions() error {
virtualDAAScore, err := op.mempool.virtualDAAScore()
if err != nil {
return err
}
if virtualDAAScore-op.lastExpireScan < op.mempool.config.orphanExpireScanIntervalDAAScore {
return nil
}
for _, orphanTransaction := range op.allOrphans {
// Never expire high priority transactions
if orphanTransaction.isHighPriority {
continue
}
// Remove all transactions whose addedAtDAAScore is older then transactionExpireIntervalDAAScore
if virtualDAAScore-orphanTransaction.addAtDAAScore > op.mempool.config.orphanExpireIntervalDAAScore {
err = op.removeOrphan(orphanTransaction.transactionID())
if err != nil {
return err
}
}
}
op.lastExpireScan = virtualDAAScore
return nil
}