Skip to content

Commit

Permalink
fix tx pool bug
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-li-hua committed Jul 23, 2021
1 parent 42c5ddf commit 2e0b6c9
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 20 deletions.
8 changes: 4 additions & 4 deletions internal/ptnapi/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func (s *PrivateContractAPI) contractFeeCheck(ctx *buildContractContext, reqMsg

//assetId, _, err := modules.String2AssetId(ctx.tokenId)
assetId := dagconfig.DagConfig.GetGasToken()
if err != nil {
log.Errorf("contractFeeCheck, String2AssetId err:%s:%s", err.Error(), ctx.tokenId)
return fee, fmt.Errorf("contractFeeCheck, String2AssetId err:%s", err.Error())
}
//if err != nil {
// log.Errorf("contractFeeCheck, String2AssetId err:%s:%s", err.Error(), ctx.tokenId)
// return fee, fmt.Errorf("contractFeeCheck, String2AssetId err:%s", err.Error())
//}
//baseFee := decimal.NewFromFloat(float64(s.b.Dag().GetChainParameters().TransferPtnBaseFee))
//if ctx.gasFee.Cmp(baseFee) < 0 { //ctx.gasFee < s.b.Dag().GetChainParameters().TransferPtnBaseFee

Expand Down
60 changes: 46 additions & 14 deletions internal/ptnapi/dag_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,28 +539,60 @@ func (s *PublicDagAPI) GetTxPoolTxByHash(ctx context.Context, hex string) (strin
}

//GetTxStatusByHash returns the transaction status for hash
//func (s *PublicDagAPI) GetTxStatusByHash(ctx context.Context, hex string) (*ptnjson.TxPoolTxJson, error) {
// log.Debug("this is hash tx's hash hex to find tx.", "hex", hex)
// if len(hex) > 72 || len(hex) < 64 {
// return nil, fmt.Errorf("the hex[%s] is illegal.", hex)
// }
// hash := common.HexToHash(hex)
//
// tx_status := new(ptnjson.TxPoolTxJson)
// item, err := s.b.GetTxPoolTxByHash(hash)
// log.Debugf("GetTxStatusByHash,GetTxPoolTxByHash, item[%v]", item)
//
// if err != nil {
// log.Debug("GetTxStatusByHash, A")
// if tx_info, err := s.b.Dag().GetTxByReqId(hash); err == nil {
// log.Debugf("GetTxStatusByHash,GetTxByReqId, tx_info[%v]", ptnjson.ConvertTxWithInfo2Json(tx_info))
// return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
// }
// if tx_info, err := s.b.Dag().GetTransaction(hash); err == nil {
// log.Debugf("GetTxStatusByHash,GetTxByReqId, GetTransaction[%v]", ptnjson.ConvertTxWithInfo2Json(tx_info))
// return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
// }
// tx_status.NotExsit = true
// log.Debugf("the txhash[%s] is not exist in dag,error[%s]", hash.String(), err.Error())
// tx_status.TxHash = hex
// return tx_status, nil
// }
// return item, nil
//}
func (s *PublicDagAPI) GetTxStatusByHash(ctx context.Context, hex string) (*ptnjson.TxPoolTxJson, error) {
log.Debug("this is hash tx's hash hex to find tx.", "hex", hex)
if len(hex) > 72 || len(hex) < 64 {
return nil, fmt.Errorf("the hex[%s] is illegal.", hex)
}
hash := common.HexToHash(hex)

if tx_info, err := s.b.Dag().GetTxByReqId(hash); err == nil {
//log.Debugf("GetTxStatusByHash,GetTxByReqId, tx_info[%v]", ptnjson.ConvertTxWithInfo2Json(tx_info))
return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
}
if tx_info, err := s.b.Dag().GetTransaction(hash); err == nil {
//log.Debugf("GetTxStatusByHash,GetTxByReqId, GetTransaction[%v]", ptnjson.ConvertTxWithInfo2Json(tx_info))
return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
}
if item, err := s.b.GetTxPoolTxByHash(hash); err == nil {
//log.Debugf("GetTxStatusByHash,GetTxPoolTxByHash, item[%v]", item)
return item, nil
}

tx_status := new(ptnjson.TxPoolTxJson)
item, err := s.b.GetTxPoolTxByHash(hash)
if err != nil {
if tx_info, err := s.b.Dag().GetTxByReqId(hash); err == nil {
return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
}
if tx_info, err := s.b.Dag().GetTransaction(hash); err == nil {
return ptnjson.ConvertTxWithInfo2Json(tx_info), nil
}
tx_status.NotExsit = true
log.Debugf("the txhash[%s] is not exist in dag,error[%s]", hash.String(), err.Error())
tx_status.TxHash = hex
return tx_status, nil
}
return item, nil
tx_status.NotExsit = true
log.Debugf("the txhash[%s] is not exist ", hash.String())
tx_status.TxHash = hex
return tx_status, nil

}

// MemdagInfos returns the pool transaction for the given hash
Expand Down
5 changes: 3 additions & 2 deletions txspool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ func (pool *TxPool) promoteTx(hash common.Hash, tx *TxPoolTransaction, number, i
// An older transaction was better, discard this
this.Pending = true
this.Discarded = true
this.Confirmed = true
pool.all.Store(tx_hash, this)
// delete utxo
pool.deletePoolUtxos(tx.Tx)
Expand Down Expand Up @@ -1238,7 +1239,7 @@ func (pool *TxPool) removeTransaction(tx *TxPoolTransaction, removeRedeemers boo
}
}
POOLLOAD:
// Remove the transaction if needed.
// Remove the transaction if needed.
interTx, has := pool.all.Load(hash)
if !has {
return
Expand Down Expand Up @@ -1768,7 +1769,7 @@ func (pool *TxPool) GetSortedTxs() ([]*TxPoolTransaction, error) {
//return list, total
}
func (pool *TxPool) getPrecusorTxs(tx *TxPoolTransaction, poolTxs,
orphanTxs map[common.Hash]*TxPoolTransaction) (bool, []*TxPoolTransaction) {
orphanTxs map[common.Hash]*TxPoolTransaction) (bool, []*TxPoolTransaction) {
var isNotOriginal bool
pretxs := make([]*TxPoolTransaction, 0)
for _, op := range tx.Tx.GetSpendOutpoints() {
Expand Down

0 comments on commit 2e0b6c9

Please sign in to comment.