utxo map[bc.Hash]*types.Tx
orphans map[bc.Hash]*orphanTx
orphansByPrev map[bc.Hash]map[bc.Hash]*orphanTx
+ claimTx map[bc.Hash]bool
errCache *lru.Cache
msgCh chan *TxPoolMsg
}
utxo: make(map[bc.Hash]*types.Tx),
orphans: make(map[bc.Hash]*orphanTx),
orphansByPrev: make(map[bc.Hash]map[bc.Hash]*orphanTx),
+ claimTx: make(map[bc.Hash]bool),
errCache: lru.New(maxCachedErrTxs),
msgCh: make(chan *TxPoolMsg, maxMsgChSize),
}
for _, output := range txD.Tx.ResultIds {
delete(tp.utxo, *output)
}
+ tp.removeClaimTx(txD.Tx)
delete(tp.pool, *txHash)
atomic.StoreInt64(&tp.lastUpdated, time.Now().Unix())
tp.mtx.Lock()
defer tp.mtx.Unlock()
- if tp.isWithdrawSpent(tx) {
+ if tp.IsWithdrawSpent(tx) {
+ log.WithFields(log.Fields{"module": "ProcessTransaction", "error": "pegin-already-claimed"}).Error("ProcessTransaction error")
return false, errors.New("pegin-already-claimed")
}
-
txD := &TxDesc{
Tx: tx,
StatusFail: statusFail,
return false, nil
}
-func (tp *TxPool) isWithdrawSpent(tx *types.Tx) bool {
+func (tp *TxPool) IsWithdrawSpent(tx *types.Tx) bool {
for key, value := range tx.Entries {
switch value.(type) {
case *bc.Claim:
- return tp.store.IsWithdrawSpent(&key)
+ _, ok := tp.claimTx[key]
+ return tp.store.IsWithdrawSpent(&key) || ok
default:
continue
}
return false
}
+func (tp *TxPool) addClaimTx(tx *types.Tx) {
+ for key, value := range tx.Entries {
+ switch value.(type) {
+ case *bc.Claim:
+ tp.claimTx[key] = true
+ default:
+ continue
+ }
+ }
+}
+
+func (tp *TxPool) removeClaimTx(tx *types.Tx) {
+ for key, value := range tx.Entries {
+ switch value.(type) {
+ case *bc.Claim:
+ delete(tp.claimTx, key)
+ default:
+ continue
+ }
+ }
+}
+
func (tp *TxPool) addOrphan(txD *TxDesc, requireParents []*bc.Hash) error {
if len(tp.orphans) >= maxOrphanNum {
return ErrPoolIsFull
tx := txD.Tx
txD.Added = time.Now()
tp.pool[tx.ID] = txD
+ // 增加一个claim id 到到claim pool中
+ tp.addClaimTx(tx)
for _, id := range tx.ResultIds {
output, err := tx.Output(*id)
if err != nil {
atomic.StoreInt64(&tp.lastUpdated, time.Now().Unix())
tp.msgCh <- &TxPoolMsg{TxDesc: txD, MsgType: MsgNewTx}
+
log.WithField("tx_id", tx.ID.String()).Debug("Add tx to mempool")
return nil
}