[Rosetta] Fix tx receipt fetch (#3492)

* [rosetta] Fix staking + plain tx receipt fetch

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Add receipt check error catch

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Fix special case ID check

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>

* [rosetta] Fix receipt check error catch

Signed-off-by: Daniel Van Der Maden <dvandermaden0@berkeley.edu>
pull/3314/head
Daniel Van Der Maden 4 years ago committed by GitHub
parent 70b464efab
commit b6b35cbb32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      rosetta/services/block.go
  2. 2
      rosetta/services/block_side_effect.go
  3. 2
      rosetta/services/tx_operation.go

@ -139,9 +139,14 @@ func (s *BlockAPI) BlockTransaction(
return nil, err return nil, err
} }
blockHash := ethcommon.HexToHash(request.BlockIdentifier.Hash) blk, rosettaError := getBlock(
ctx, s.hmy, &types.PartialBlockIdentifier{Hash: &request.BlockIdentifier.Hash},
)
if rosettaError != nil {
return nil, rosettaError
}
txHash := ethcommon.HexToHash(request.TransactionIdentifier.Hash) txHash := ethcommon.HexToHash(request.TransactionIdentifier.Hash)
txInfo, rosettaError := s.getTransactionInfo(ctx, blockHash, txHash) txInfo, rosettaError := s.getTransactionInfo(ctx, blk, txHash)
if rosettaError != nil { if rosettaError != nil {
// If no transaction info is found, check for side effect case transaction. // If no transaction info is found, check for side effect case transaction.
response, rosettaError2 := s.sideEffectBlockTransaction(ctx, request) response, rosettaError2 := s.sideEffectBlockTransaction(ctx, request)
@ -173,12 +178,6 @@ func (s *BlockAPI) BlockTransaction(
contractInfo.ContractCode = state.GetCode(txInfo.receipt.ContractAddress) contractInfo.ContractCode = state.GetCode(txInfo.receipt.ContractAddress)
contractInfo.ContractAddress = &txInfo.receipt.ContractAddress contractInfo.ContractAddress = &txInfo.receipt.ContractAddress
} }
blk, rosettaError := getBlock(
ctx, s.hmy, &types.PartialBlockIdentifier{Hash: &request.BlockIdentifier.Hash},
)
if rosettaError != nil {
return nil, rosettaError
}
contractInfo.ExecutionResult, rosettaError = s.getTransactionTrace(ctx, blk, txInfo) contractInfo.ExecutionResult, rosettaError = s.getTransactionTrace(ctx, blk, txInfo)
if rosettaError != nil { if rosettaError != nil {
return nil, rosettaError return nil, rosettaError
@ -210,7 +209,7 @@ type transactionInfo struct {
// getTransactionInfo given the block hash and transaction hash // getTransactionInfo given the block hash and transaction hash
func (s *BlockAPI) getTransactionInfo( func (s *BlockAPI) getTransactionInfo(
ctx context.Context, blockHash, txHash ethcommon.Hash, ctx context.Context, blk *hmytypes.Block, txHash ethcommon.Hash,
) (txInfo *transactionInfo, rosettaError *types.Error) { ) (txInfo *transactionInfo, rosettaError *types.Error) {
// Look for all of the possible transactions // Look for all of the possible transactions
var index uint64 var index uint64
@ -219,6 +218,8 @@ func (s *BlockAPI) getTransactionInfo(
plainTx, _, _, index = rawdb.ReadTransaction(s.hmy.ChainDb(), txHash) plainTx, _, _, index = rawdb.ReadTransaction(s.hmy.ChainDb(), txHash)
if plainTx == nil { if plainTx == nil {
stakingTx, _, _, index = rawdb.ReadStakingTransaction(s.hmy.ChainDb(), txHash) stakingTx, _, _, index = rawdb.ReadStakingTransaction(s.hmy.ChainDb(), txHash)
// if there both normal and staking transactions, correct index offset.
index = index + uint64(blk.Transactions().Len())
} }
cxReceipt, _, _, _ := rawdb.ReadCXReceipt(s.hmy.ChainDb(), txHash) cxReceipt, _, _, _ := rawdb.ReadCXReceipt(s.hmy.ChainDb(), txHash)
@ -227,7 +228,7 @@ func (s *BlockAPI) getTransactionInfo(
} }
var receipt *hmytypes.Receipt var receipt *hmytypes.Receipt
receipts, err := s.hmy.GetReceipts(ctx, blockHash) receipts, err := s.hmy.GetReceipts(ctx, blk.Hash())
if err != nil { if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{ return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": err.Error(), "message": err.Error(),
@ -235,6 +236,11 @@ func (s *BlockAPI) getTransactionInfo(
} }
if int(index) < len(receipts) { if int(index) < len(receipts) {
receipt = receipts[index] receipt = receipts[index]
if cxReceipt == nil && receipt.TxHash != txHash {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": "unable to find correct receipt for transaction",
})
}
} }
// Use pool transaction for concise formatting // Use pool transaction for concise formatting

@ -54,7 +54,7 @@ func unpackSideEffectTransactionIdentifier(
hash := txID.Hash hash := txID.Hash
hash = strings.TrimPrefix(hash, "0x") hash = strings.TrimPrefix(hash, "0x")
hash = strings.TrimPrefix(hash, "0X") hash = strings.TrimPrefix(hash, "0X")
if len(hash) < blockHashStrLen || string(hash[blockHashStrLen]) != "_" || if len(hash) <= blockHashStrLen || string(hash[blockHashStrLen]) != "_" ||
hash[blockHashStrLen+1:] != SideEffectTransactionSuffix { hash[blockHashStrLen+1:] != SideEffectTransactionSuffix {
return ethcommon.Hash{}, common.NewError(common.CatchAllError, map[string]interface{}{ return ethcommon.Hash{}, common.NewError(common.CatchAllError, map[string]interface{}{
"message": "unknown side effect transaction ID format", "message": "unknown side effect transaction ID format",

@ -460,7 +460,7 @@ func getAmountFromCollectRewards(
} }
if amount == nil { if amount == nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{ return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": fmt.Sprintf("collect rewards amount not found for %v", senderAddress), "message": fmt.Sprintf("collect rewards amount not found for %v", senderAddress.String()),
}) })
} }
return amount, nil return amount, nil

Loading…
Cancel
Save