"github.com/golang/groupcache/lru"
log "github.com/sirupsen/logrus"
- "github.com/bytom/consensus"
- "github.com/bytom/event"
- "github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/types"
- "github.com/bytom/protocol/state"
+ "github.com/bytom/bytom/consensus"
+ "github.com/bytom/bytom/event"
+ "github.com/bytom/bytom/protocol/bc"
+ "github.com/bytom/bytom/protocol/bc/types"
+ "github.com/bytom/bytom/protocol/state"
)
// msg type
ErrTransactionNotExist = errors.New("transaction are not existed in the mempool")
// ErrPoolIsFull indicates the pool is full
ErrPoolIsFull = errors.New("transaction pool reach the max number")
+ // ErrDustTx indicates transaction is dust tx
+ ErrDustTx = errors.New("transaction is dust tx")
)
type TxMsgEvent struct{ TxMsg *TxPoolMsg }
return tp.IsTransactionInPool(txHash) || tp.IsTransactionInErrCache(txHash)
}
-// ProcessTransaction is the main entry for txpool handle new tx
-func (tp *TxPool) ProcessTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error) {
+func isTransactionNoBtmInput(tx *types.Tx) bool {
+ for _, input := range tx.TxData.Inputs {
+ if input.AssetID() == *consensus.BTMAssetID {
+ return false
+ }
+ }
+ return true
+}
+
+func isTransactionZeroOutput(tx *types.Tx) bool {
+ for _, output := range tx.TxData.Outputs {
+ if output.Amount == uint64(0) {
+ return true
+ }
+ }
+ return false
+}
+
+func (tp *TxPool) IsDust(tx *types.Tx) bool {
+ return isTransactionNoBtmInput(tx) || isTransactionZeroOutput(tx)
+}
+
+func (tp *TxPool) processTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error) {
tp.mtx.Lock()
defer tp.mtx.Unlock()
return false, nil
}
+// ProcessTransaction is the main entry for txpool handle new tx, ignore dust tx.
+func (tp *TxPool) ProcessTransaction(tx *types.Tx, statusFail bool, height, fee uint64) (bool, error) {
+ if tp.IsDust(tx) {
+ log.WithFields(log.Fields{"module": logModule, "tx_id": tx.ID.String()}).Warn("dust tx")
+ return false, nil
+ }
+ return tp.processTransaction(tx, statusFail, height, fee)
+}
+
func (tp *TxPool) addOrphan(txD *TxDesc, requireParents []*bc.Hash) error {
if len(tp.orphans) >= maxOrphanNum {
return ErrPoolIsFull
func (tp *TxPool) orphanExpireWorker() {
ticker := time.NewTicker(orphanExpireScanInterval)
+ defer ticker.Stop()
+
for now := range ticker.C {
tp.ExpireOrphan(now)
}