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

Add new APIs to allow efficient retrieval of receipts #1887

Conversation

@cburgdorf
Copy link
Contributor

cburgdorf commented Dec 2, 2019

What was wrong?

Our current APIs do not allow to implement getTransactionReceipt in Trinity (without reaching into Py-EVM internals).

That's because the expected response includes information that we can not retrieve if the APIs aren't changed or new APIs are added.

Exampe response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "blockHash": "0xf64a12502afc36db3d29931a2148e5d6ddaa883a2a3c968ca2fb293fa9258c68",
    "blockNumber": "0x70839",
    "contractAddress": null,
    "cumulativeGasUsed": "0x75d5",
    "from": "0xc80fb22930b303b55df9b89901889126400add38",
    "gasUsed": "0x75d5",
    "logs": [
      {
        "address": "0x03fca6077d38dd99d0ce14ba32078bd2cda72d74",
        "topics": [
          "0x24bcf19562365f6510754002f8d7b818d275886315d29c7aa04785570b97a363"
        ],
        "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a4861636b65726e65777300000000000000000000000000000000000000000000",
        "blockNumber": "0x70839",
        "transactionHash": "0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1",
        "transactionIndex": "0x0",
        "blockHash": "0xf64a12502afc36db3d29931a2148e5d6ddaa883a2a3c968ca2fb293fa9258c68",
        "logIndex": "0x0",
        "removed": false
      }
    ],
    "logsBloom": "0x00000000000000000000000000000400000000020000000000000000400000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "root": "0xc659845f1ac4e899ff1b0666dbac5deeda33a4a5d85da71f617f352824146e40",
    "to": "0x03fca6077d38dd99d0ce14ba32078bd2cda72d74",
    "transactionHash": "0x1e2910a262b1008d0616a0beb24c1a491d78771baa54a33e66065e03b1f46bc1",
    "transactionIndex": "0x0"
  }
}

With only a transaction_hash we have no way of telling the block or the index of the transaction within that block which we need to give a qualified response.

How was it fixed?

I tried to change the APIs in a way that would prevent us from unnecessary database access as much as possible (I think).

Therefore I've added the following new APIs to Chain:

def get_canonical_transaction_index(self, transaction_hash: Hash32) -> Tuple[BlockNumber, int]:

☝️ Allows to make subsequent requests that would not re-read the same information again.

def get_canonical_block_header_by_number(self, block_number: BlockNumber) -> BlockHeaderAPI

☝️ We have a similar API for full blocks but it seems wasteful to call that when retrieving a block header by number would do it.

def get_canonical_transaction_by_index(self, block_number: BlockNumber, index: int) -> SignedTransactionAPI:

This API is to bypass get_canonical_transaction which would involve another db lookup that for the block number and index that we already know at this point.

def get_transaction_receipt_by_index(self, block_number: BlockNumber, index: int) -> ReceiptAPI:

This API is to bypass get_canonical_transaction which would involve another db lookup that for the block number and index that we already know at this point.

To-Do

  • Clean up commit history

Cute Animal Picture

put a cute animal picture link inside the parentheses

@cburgdorf cburgdorf force-pushed the cburgdorf:christoph/feat/efficient-receipt-retrieval branch 2 times, most recently from ea210f2 to b985ec8 Dec 2, 2019
@cburgdorf

This comment has been minimized.

Copy link
Contributor Author

cburgdorf commented Dec 2, 2019

This might be best reviewed in the context of ethereum/trinity#1337 that uses these new APIs.

@cburgdorf cburgdorf force-pushed the cburgdorf:christoph/feat/efficient-receipt-retrieval branch from b985ec8 to 6af5f4f Dec 2, 2019
@cburgdorf

This comment has been minimized.

Copy link
Contributor Author

cburgdorf commented Dec 2, 2019

@pipermerriam This is the successor of #1886

@cburgdorf cburgdorf requested a review from pipermerriam Dec 2, 2019
@cburgdorf cburgdorf mentioned this pull request Dec 2, 2019
0 of 2 tasks complete
Copy link
Member

pipermerriam left a comment

I like this a lot better.

@cburgdorf cburgdorf merged commit c06b1de into ethereum:master Dec 2, 2019
21 checks passed
21 checks passed
ci/circleci: py36-benchmark Your tests passed on CircleCI!
Details
ci/circleci: py36-core Your tests passed on CircleCI!
Details
ci/circleci: py36-database Your tests passed on CircleCI!
Details
ci/circleci: py36-docs Your tests passed on CircleCI!
Details
ci/circleci: py36-lint Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-byzantium Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-constantinople Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-frontier Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-homestead Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-istanbul Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-petersburg Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-spurious_dragon Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-tangerine_whistle Your tests passed on CircleCI!
Details
ci/circleci: py36-native-blockchain-transition Your tests passed on CircleCI!
Details
ci/circleci: py36-transactions Your tests passed on CircleCI!
Details
ci/circleci: py36-vm Your tests passed on CircleCI!
Details
ci/circleci: py37-core Your tests passed on CircleCI!
Details
ci/circleci: py37-database Your tests passed on CircleCI!
Details
ci/circleci: py37-lint Your tests passed on CircleCI!
Details
ci/circleci: py37-transactions Your tests passed on CircleCI!
Details
ci/circleci: py37-vm Your tests passed on CircleCI!
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.