Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rosetta] Mempool Endpoint #3339

Merged
merged 11 commits into from
Sep 23, 2020
Merged

[rosetta] Mempool Endpoint #3339

merged 11 commits into from
Sep 23, 2020

Conversation

rhazberries
Copy link
Contributor

Implements /mempool & /mempool/transaction
The transaction fetch implementation utilizes an "estimated" version of the finalized transaction receipt, which assumes transaction success.
No test file, because formatTransaction is already tested in block_test.go.

Example:

$ curl -X POST --data '{
    "network_identifier": {
      "blockchain": "Harmony",
      "network": "Testnet",
      "sub_network_identifier": {
        "network": "shard 1",
          "metadata": {
            "is_beacon": false
          }
      }
    }}' http://localhost:9798/mempool | jq
{
  "transaction_identifiers": [
    {
      "hash": "0x445113f5e313e3a388829ff1d47650a5deb6f9964a2f1c9e894ed6bc7af0abb2"
    }
  ]
}
$ curl -X POST --data '{
    "network_identifier": {
      "blockchain": "Harmony",
      "network": "Testnet",
      "sub_network_identifier": {
        "network": "shard 1",
          "metadata": {
            "is_beacon": false
          }
      }
    },
    "transaction_identifier": {
        "hash": "0x445113f5e313e3a388829ff1d47650a5deb6f9964a2f1c9e894ed6bc7af0abb2"
    }}' http://localhost:9798/mempool/transaction | jq
{
  "transaction": {
    "transaction_identifier": {
      "hash": "0x445113f5e313e3a388829ff1d47650a5deb6f9964a2f1c9e894ed6bc7af0abb2"
    },
    "operations": [
      {
        "operation_identifier": {
          "index": 0
        },
        "type": "Gas",
        "status": "success",
        "account": {
          "address": "one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur",
          "metadata": {
            "hex_address": "0x15a128e599b74842BCcBa860311Efa92991bffb5"
          }
        },
        "amount": {
          "value": "-21000000000000",
          "currency": {
            "symbol": "ONE",
            "decimals": 18
          }
        }
      },
      {
        "operation_identifier": {
          "index": 1
        },
        "related_operations": [
          {
            "index": 0
          }
        ],
        "type": "Transfer",
        "status": "success",
        "account": {
          "address": "one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur",
          "metadata": {
            "hex_address": "0x15a128e599b74842BCcBa860311Efa92991bffb5"
          }
        },
        "amount": {
          "value": "-100000000000000000000",
          "currency": {
            "symbol": "ONE",
            "decimals": 18
          }
        }
      },
      {
        "operation_identifier": {
          "index": 2
        },
        "related_operations": [
          {
            "index": 1
          }
        ],
        "type": "Transfer",
        "status": "success",
        "account": {
          "address": "one155jp2y76nazx8uw5sa94fr0m4s5aj8e5xm6fu3",
          "metadata": {
            "hex_address": "0xA5241513DA9F4463F1d4874b548dFBAC29D91f34"
          }
        },
        "amount": {
          "value": "100000000000000000000",
          "currency": {
            "symbol": "ONE",
            "decimals": 18
          }
        }
      }
    ]
  }

@codecov
Copy link

codecov bot commented Sep 11, 2020

Codecov Report

Merging #3339 into main will decrease coverage by 0.23%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3339      +/-   ##
==========================================
- Coverage   34.49%   34.26%   -0.24%     
==========================================
  Files         210      210              
  Lines       24693    25067     +374     
==========================================
+ Hits         8519     8588      +69     
- Misses      15523    15826     +303     
- Partials      651      653       +2     
Impacted Files Coverage Δ
rosetta/services/mempool.go 0.00% <0.00%> (ø)
consensus/construct.go 49.47% <0.00%> (-14.47%) ⬇️
crypto/bls/mask.go 76.10% <0.00%> (-8.87%) ⬇️
rosetta/services/network.go 40.80% <0.00%> (-3.85%) ⬇️
consensus/quorum/quorum.go 56.16% <0.00%> (-3.54%) ⬇️
rosetta/services/block.go 46.44% <0.00%> (-3.12%) ⬇️
consensus/view_change.go 7.75% <0.00%> (-0.36%) ⬇️
node/node.go 8.79% <0.00%> (-0.14%) ⬇️
consensus/checks.go 0.00% <0.00%> (ø)
consensus/leader.go 0.00% <0.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccc1c44...dbca516. Read the comment docs.

@Daniel-VDM
Copy link
Contributor

PR is related to #3210

Copy link
Contributor

@Daniel-VDM Daniel-VDM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just take care of the error with collect reward txs

pool, err := s.hmy.GetPoolTransactions()
if err != nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": "unable to fetch pool transactions",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a good idea to also give the err message here.

Status: hmyTypes.ReceiptStatusSuccessful, // Assume transaction will succeed
CumulativeGasUsed: poolTx.Gas(),
Bloom: [256]byte{},
Logs: []*hmyTypes.Log{},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing logs here for collect reward transaction will cause an error, reference:

func getAmountFromCollectRewards(
receipt *hmytypes.Receipt, senderAddress ethcommon.Address,
) (*types.Amount, *types.Error) {
var amount *types.Amount
logs := findLogsWithTopic(receipt, staking.CollectRewardsTopic)
for _, log := range logs {
if log.Address == senderAddress {
amount = &types.Amount{
Value: fmt.Sprintf("%v", big.NewInt(0).SetBytes(log.Data)),
Currency: &common.Currency,
}
break
}
}
if amount == nil {
return nil, common.NewError(common.CatchAllError, map[string]interface{}{
"message": fmt.Sprintf("collect rewards amount not found for %v", senderAddress),
})
}
return amount, nil
}

Can just create some dummy logs with the collect reward topic and have the value at 0.

@rlan35 rlan35 merged commit 5260aee into harmony-one:main Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants