Skip to content

Commit

Permalink
[[FIX]] fix issue #1279
Browse files Browse the repository at this point in the history
  • Loading branch information
libangzhu authored and vipwzw committed Dec 15, 2022
1 parent 5c6b008 commit f76cfda
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 43 deletions.
32 changes: 10 additions & 22 deletions blockchain/blockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,10 @@ func (bs *BlockStore) HasTx(key []byte) (bool, error) {
cfg := bs.client.GetConfig()
if cfg.IsEnable("quickIndex") {
if _, err := bs.db.Get(types.CalcTxShortKey(key)); err != nil {
if _, etxErr := bs.db.Get(cfg.CalcEtxKey(key)); etxErr != nil {
if err == dbm.ErrNotFoundInDb {
return false, nil
}
return false, err
if err == dbm.ErrNotFoundInDb {
return false, nil
}

return false, err
}
//通过短hash查询交易存在时,需要再通过全hash索引查询一下。
//避免短hash重复,而全hash不一样的情况
Expand All @@ -420,12 +417,10 @@ func (bs *BlockStore) HasTx(key []byte) (bool, error) {
// 直接查全哈希,单次查询平均耗时24000ns
}
if _, err := bs.db.Get(cfg.CalcTxKey(key)); err != nil {
if _, etxErr := bs.db.Get(cfg.CalcEtxKey(key)); etxErr != nil {
if err == dbm.ErrNotFoundInDb {
return false, nil
}
return false, err
if err == dbm.ErrNotFoundInDb {
return false, nil
}
return false, err
}
return true, nil
}
Expand Down Expand Up @@ -668,24 +663,17 @@ func (bs *BlockStore) GetTx(hash []byte) (*types.TxResult, error) {
if rawBytes == nil || err != nil {
//查询eth 交易哈希对应的Chin33的交易
realHash, etxerr := bs.db.Get(cfg.CalcEtxKey(hash))
if etxerr == nil && realHash != nil {
if etxerr == nil && realHash != nil { // 查到eth txhash 映射关系
rawBytes, err = bs.db.Get(cfg.CalcTxKey(realHash))
if rawBytes == nil || err != nil {
if err != dbm.ErrNotFoundInDb {
storeLog.Error("GetTx", "hash", common.ToHex(hash), "err", err)
}
err = errors.New("tx not exist")
return nil, err
}
} else {
//查不到映射关系
}
if err != nil {
if err != dbm.ErrNotFoundInDb {
storeLog.Error("GetTx", "hash", common.ToHex(hash), "err", err)
}

err = errors.New("tx not exist")
return nil, err
}

}

var txResult types.TxResult
Expand Down
15 changes: 9 additions & 6 deletions rpc/ethrpc/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,23 @@ func (e *ethHandler) GetBlockByHash(txhash common.Hash, full bool) (*types.Block
//GetTransactionByHash eth_getTransactionByHash
func (e *ethHandler) GetTransactionByHash(txhash common.Hash) (*types.Transaction, error) {
log.Debug("GetTransactionByHash", "txhash", txhash)
var req ctypes.ReqHashes
req.Hashes = append(req.Hashes, txhash.Bytes())
txdetails, err := e.cli.GetTransactionByHash(&req)
var req ctypes.ReqHash
req.Hash = txhash.Bytes()

txdetail, err := e.cli.QueryTx(&req)
if err != nil {
return nil, err
}
var blockHash []byte
if len(txdetails.GetTxs()) != 0 {
blockNum := txdetails.GetTxs()[0].Height
if txdetail.Tx != nil {
blockNum := txdetail.GetHeight()
hashReply, err := e.cli.GetBlockHash(&ctypes.ReqInt{Height: blockNum})
if err == nil {
blockHash = hashReply.GetHash()
}
txs, _, err := types.TxDetailsToEthReceipts(txdetails, common.BytesToHash(blockHash), e.cfg)
var txdetails ctypes.TransactionDetails
txdetails.Txs = append(txdetails.Txs, txdetail)
txs, _, err := types.TxDetailsToEthReceipts(&txdetails, common.BytesToHash(blockHash), e.cfg)
if err != nil {
return nil, err
}
Expand Down
26 changes: 11 additions & 15 deletions types/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -901,23 +901,19 @@ func (tx *Transaction) Clone() *Transaction {

//GetEthTxHash 获取eth 兼容交易的交易哈希
func (tx *Transaction) GetEthTxHash() []byte {
if IsEthSignID(tx.GetSignature().GetTy()) {
payload := tx.GetPayload()
var evmaction EVMContractAction4Chain33
err := Decode(payload, &evmaction)
if err == nil {
note := evmaction.GetNote()
var etx etypes.Transaction
etxBytes, err := common.FromHex(note)
if err == nil {
if err = etx.UnmarshalBinary(etxBytes); err == nil {
return etx.Hash().Bytes()
}

}
if !IsEthSignID(tx.GetSignature().GetTy()) {
return nil
}
var evmaction EVMContractAction4Chain33
err := Decode(tx.GetPayload(), &evmaction)
if err == nil {
var etx etypes.Transaction
etxBytes, err := common.FromHex(evmaction.GetNote())
if err == nil && etx.UnmarshalBinary(etxBytes) == nil {
return etx.Hash().Bytes()
}

}

return nil
}

Expand Down

0 comments on commit f76cfda

Please sign in to comment.