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

Ethereum Transaction Receipts in Event Handlers #3373

Merged
merged 33 commits into from
Mar 31, 2022

Conversation

tilacog
Copy link
Contributor

@tilacog tilacog commented Mar 18, 2022

This PR allows Ethereum event handlers to access the receipt for the transaction which emitted it.

To support this, we introduce:

  • a new type hierarchy to the runtime
  • a new specVersion: 0.0.6
  • a new apiVersion: 0.0.7

1. Usage in Mappings

An event handler will receive an Event containing a receipt whenever it is declared in the subgraph manifest with the new receipt: true key, which is optional and defaults to false.

eventHandlers:
  - event: NewGravatar(uint256,address,string,string)
    handler: handleNewGravatar
    receipt: true

Inside the handler function, the receipt can be accessed in the Event.receipt field.
When the receipt key is set to false or omitted in the manifest, a null value will be returned instead.

2. New runtime data types

_ Type Description
A AscEthereumEventWithReceipt Contains all data for a Event plus a non-nullable receipt field, containing [B]
B AscEthereumTransactionReceipt A receipt for the transaction that emitted this event, which contains a logs field with an array of [C], containing all the logs for the associated transaction.
C AscEthereumLog A log from an event emitted within the transaction.

Depending on the subgraph manifest configuration, the runtime will receive either an AscEthereumEvent or an AscEthereumEventWithReceipt.

3. Receipt Ingestion

Transaction receipts will be collected inside the blocks_with_triggers function (which is used by PoolingBlockStream) only when an EthereumLogFilter requires them.

4. Affected Structs and Enums

The following items were updated with optional fields to accommodate data for receipt themselves and their requirement flags :

  • MappingEventHandlergot a new receipt: bool field which defaults to false when deserializing, to account for omissions in the subgraph manifest.
  • EthereumLogFilter: its inner Graph data structure was updated so its edges represent the requirement of a receipt. The original HashSet<EventSignature> of wildcard events was also updated to a HashMap<EventSignature, bool> to reflect that same aspect.
  • EthereumTrigger::Log variant got a second Option<web3::TransactionReceipt> field
  • MappingTrigger::Log variant got a new receipt: Option<web3::TransactionReceipt> field

Todo:

  • validations for the new apiVersion
  • tests for EthereumLogFilter
  • add a retry strategy to the get_transaction_receipts_for_transaction_hashes function
  • graph-ts and graph-cli released (see "Dependencies" below)
  • docs

Resolves #3218


Dependencies

This PR depends on:

@tilacog tilacog changed the title Ethereum Transaction Receipts in mappings Ethereum Transaction Receipts in Event Handlers Mar 18, 2022
@tilacog tilacog force-pushed the tiago/receipts-in-mappings branch 2 times, most recently from 6149468 to 1c0b6af Compare March 21, 2022 23:04
graph/src/runtime/mod.rs Outdated Show resolved Hide resolved
chain/ethereum/src/trigger.rs Outdated Show resolved Hide resolved
chain/ethereum/src/data_source.rs Outdated Show resolved Hide resolved
chain/ethereum/src/data_source.rs Show resolved Hide resolved
chain/ethereum/src/adapter.rs Show resolved Hide resolved
chain/ethereum/src/adapter.rs Show resolved Hide resolved
chain/ethereum/src/ethereum_adapter.rs Outdated Show resolved Hide resolved
chain/ethereum/src/ethereum_adapter.rs Outdated Show resolved Hide resolved
chain/ethereum/src/ethereum_adapter.rs Show resolved Hide resolved
chain/ethereum/src/ethereum_adapter.rs Show resolved Hide resolved
@evaporei
Copy link
Contributor

Another couple of things:

  1. Any reason for this PR still being Draft instead of Ready for Review?
  2. This needs a rebase, there are conflicts still.

@tilacog
Copy link
Contributor Author

tilacog commented Mar 29, 2022

Another couple of things:

1. Any reason for this PR still being Draft instead of Ready for Review?

The Draft status is related to the dependent PRs not being merged, but I can change it now since we already started the review process.

@tilacog tilacog marked this pull request as ready for review March 29, 2022 18:39
tilacog added 9 commits March 29, 2022 15:54
In this commit we stop calling `fetch_receipts_from_ethereum_client`
and use `fetch_transaction_receipts_with_retry` instead, so we can
take advantage of both its retry scheme and transaction receipt
resolution mechanism.

Calling this latest function requires block hashes, so we had to move
from a `Vec<TxnHash>` to a `Map<BlockHash,Vec<TxnHash>`.
Some assertions were supposed to be negated.
…Event_0_0_7`

Also changed the implementation of `ToAscObj` to use a
`Option<Receipt>` instead of a `Receipt`, since `AscPtr`s can be
nullable.
@tilacog tilacog force-pushed the tiago/receipts-in-mappings branch from 2905297 to 2008afa Compare March 29, 2022 18:55
@tilacog
Copy link
Contributor Author

tilacog commented Mar 29, 2022

Rebased with latest main branch

Copy link
Contributor

@evaporei evaporei left a comment

Choose a reason for hiding this comment

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

💯

@franz101
Copy link

franz101 commented May 8, 2022

You are my hero @tilacog

@creaink
Copy link

creaink commented Sep 15, 2022

Add receipt: true caused: Failed to deploy to Graph node https://api.thegraph.com/deploy/: ipfs failure::failure parsing subgraph manifest. when run graph deploy since today. Is there any changed?

@azf20
Copy link
Contributor

azf20 commented Sep 15, 2022

hi @creaink this is an issue with deployments to the Hosted Service, we are investigating and expect to resolve soon, sorry for the trouble

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.

Feature request: Extending the ethereum.Transaction to contain all logs
5 participants