-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Anti-spam measurements against dust attack (#2223)
* BlockCandidateTransactions patch * Fix condition * Fix fee * Fix bug * Reject from mempool * Fix hasCoinbaseInput * Fix position * Bump version to v0.12.14
- Loading branch information
1 parent
bd14202
commit 92574e6
Showing
5 changed files
with
70 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) { | ||
hasCoinbaseInput := false | ||
for _, input := range tx.Inputs { | ||
if input.UTXOEntry.IsCoinbase() { | ||
hasCoinbaseInput = true | ||
break | ||
} | ||
} | ||
|
||
numExtraOuts := len(tx.Outputs) - len(tx.Inputs) | ||
if !hasCoinbaseInput && numExtraOuts > 2 && tx.Fee < uint64(numExtraOuts)*constants.SompiPerKaspa { | ||
log.Debugf("Filtered spam tx %s", consensushashing.TransactionID(tx)) | ||
continue | ||
} | ||
|
||
if hasCoinbaseInput || tx.Fee > uint64(numExtraOuts)*constants.SompiPerKaspa { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
michaelsutton
Collaborator
|
||
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@someone235 in the case where
{len(inputs): 1, len(outputs): 2}
and there's no coinbase input, this means that the fee must be1.00000001 KAS
for it to not enter into the spamTx else condition below. Is this expected?A tx with 1 input and 2 outputs doesn't seem to be spam