Compare commits

..

5 Commits

Author SHA1 Message Date
Ori Newman
a12f86efc2 Reject from mempool 2023-09-25 07:22:38 +03:00
Ori Newman
4f04923114 Fix bug 2023-09-25 06:57:39 +03:00
Ori Newman
d3627de7f8 Fix fee 2023-09-25 05:27:15 +03:00
Ori Newman
582473cd8c Fix condition 2023-09-25 05:17:42 +03:00
Ori Newman
6408ba1420 BlockCandidateTransactions patch 2023-09-25 05:10:31 +03:00
2 changed files with 59 additions and 13 deletions

View File

@@ -1,6 +1,8 @@
package mempool
import (
"github.com/kaspanet/kaspad/domain/consensus/utils/consensushashing"
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
"sync"
"github.com/kaspanet/kaspad/domain/consensusreference"
@@ -141,7 +143,57 @@ func (mp *mempool) BlockCandidateTransactions() []*externalapi.DomainTransaction
mp.mtx.RLock()
defer mp.mtx.RUnlock()
return mp.transactionsPool.allReadyTransactions()
readyTxs := mp.transactionsPool.allReadyTransactions()
var candidateTxs []*externalapi.DomainTransaction
var spamTx *externalapi.DomainTransaction
var spamTxNewestUTXODaaScore uint64
for _, tx := range readyTxs {
if len(tx.Outputs) > len(tx.Inputs) {
numExtraOuts := len(tx.Outputs) - len(tx.Inputs)
if numExtraOuts > 2 && tx.Fee < uint64(numExtraOuts)*constants.SompiPerKaspa {
log.Debugf("Filtered spam tx %s", consensushashing.TransactionID(tx))
continue
}
hasCoinbaseInput := false
for _, input := range tx.Inputs {
if input.UTXOEntry.IsCoinbase() {
hasCoinbaseInput = true
break
}
}
if hasCoinbaseInput || tx.Fee > uint64(numExtraOuts)*constants.SompiPerKaspa {
candidateTxs = append(candidateTxs, tx)
} else {
txNewestUTXODaaScore := tx.Inputs[0].UTXOEntry.BlockDAAScore()
for _, input := range tx.Inputs {
if input.UTXOEntry.BlockDAAScore() > txNewestUTXODaaScore {
txNewestUTXODaaScore = input.UTXOEntry.BlockDAAScore()
}
}
if spamTx != nil {
if txNewestUTXODaaScore < spamTxNewestUTXODaaScore {
spamTx = tx
spamTxNewestUTXODaaScore = txNewestUTXODaaScore
}
} else {
spamTx = tx
spamTxNewestUTXODaaScore = txNewestUTXODaaScore
}
}
} else {
candidateTxs = append(candidateTxs, tx)
}
}
if spamTx != nil {
log.Debugf("Adding spam tx candidate %s", consensushashing.TransactionID(spamTx))
candidateTxs = append(candidateTxs, spamTx)
}
return candidateTxs
}
func (mp *mempool) RevalidateHighPriorityTransactions() (validTransactions []*externalapi.DomainTransaction, err error) {

View File

@@ -17,18 +17,6 @@ func (mp *mempool) validateAndInsertTransaction(transaction *externalapi.DomainT
fmt.Sprintf("validateAndInsertTransaction %s", consensushashing.TransactionID(transaction)))
defer onEnd()
numOutsLessThanOneKas := 0
for _, output := range transaction.Outputs {
if output.Value < constants.SompiPerKaspa {
numOutsLessThanOneKas += 1
}
}
if numOutsLessThanOneKas > len(transaction.Inputs) {
log.Warnf("Rejected transaction with %d outputs with less than 1 KAS")
return nil, nil
}
// Populate mass in the beginning, it will be used in multiple places throughout the validation and insertion.
mp.consensusReference.Consensus().PopulateMass(transaction)
@@ -42,6 +30,12 @@ func (mp *mempool) validateAndInsertTransaction(transaction *externalapi.DomainT
return nil, err
}
numExtraOuts := len(transaction.Outputs) - len(transaction.Inputs)
if numExtraOuts > 2 && transaction.Fee < uint64(numExtraOuts)*constants.SompiPerKaspa {
log.Warnf("Rejected spam tx %s from mempool", consensushashing.TransactionID(transaction))
return nil, nil
}
if len(missingOutpoints) > 0 {
if !allowOrphan {
str := fmt.Sprintf("Transaction %s is an orphan, where allowOrphan = false",