Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Emit events for inter contract calls #12136

Merged
merged 7 commits into from
Sep 3, 2022
Merged

Conversation

athei
Copy link
Member

@athei athei commented Aug 29, 2022

Currently, there is no way for off-chain tooling to track inter contract calls without adding custom events as the existing events only inform about whole extrinsics (call stacks). This is problematic for general purpose tools like dashboards that are not tailored towards specific contracts. This PR changes this by emitting an event whenever a contract was successfully called. Successfully because events are rolled back as storage changes on failure. We argue that rolled back calls "didn't happen" anyways as they do not lave any trace on-chain except incurred costs.

Please not that we do not include the input or output of those calls on purpose as this would include a variable overhead that we do not want to enforce for every single contract. Authors need to emit custom events in case this is needed.

Additionally, we add topics to all events so that clients have an easier time to subscribe to stuff they are interested in without needing to download each block.

Needed for paritytech/polkadot-sdk#120

@achimcc I think you asked for this some time ago?

@github-actions github-actions bot added the A0-please_review Pull request needs code review. label Aug 29, 2022
@athei athei added B7-runtimenoteworthy C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Aug 29, 2022
@athei athei requested review from agryaznov, HCastano and cmichi and removed request for agryaznov and HCastano August 29, 2022 09:59
Copy link
Contributor

@cmichi cmichi left a comment

Choose a reason for hiding this comment

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

What would be super great is to have additional log::debug output for those events. This would make it way easier for contract devs to debug their contracts. Or maybe just log::debug any event emitted by the pallet? That would actually be best, then we'd also be able to see contract events.

@tmcgroul
Copy link

tmcgroul commented Sep 1, 2022

Hi @athei does this pr affects on Contracts.ContractEmitted args? It extends args by topics, right?

contract: String,
data: String,
topics: Vec<String>

@athei
Copy link
Member Author

athei commented Sep 1, 2022

No. This doesn't touch Contracts.ContractEmitted at all. This always forwarded the topics as supplied by the contract. This PR adds topics to the events emitted by the pallet itself (not the contract).

Copy link
Contributor

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

Awesome! So many possibilites, could even use the new storage layout metadata (once it lands) to track changes in storage before and after these events.

frame/contracts/src/lib.rs Outdated Show resolved Hide resolved
@ascjones
Copy link
Contributor

ascjones commented Sep 1, 2022

then we'd also be able to see contract events.

<cargo-contract shill> Already displays all contract and pallet events </cargo-contract shill>

image

@athei
Copy link
Member Author

athei commented Sep 1, 2022

This would make it way easier for contract devs to debug their contracts. Or maybe just log::debug any event emitted by the pallet? That would actually be best, then we'd also be able to see contract events.

These things can be read by a client. Just outputting them to the console would seriously clutter the output.

@athei
Copy link
Member Author

athei commented Sep 3, 2022

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 4b79116 into master Sep 3, 2022
@paritytech-processbot paritytech-processbot bot deleted the at/call_event branch September 3, 2022 08:03
@achimcc
Copy link
Contributor

achimcc commented Sep 3, 2022

Currently, there is no way for off-chain tooling to track inter contract calls without adding custom events as the existing events only inform about whole extrinsics (call stacks). This is problematic for general purpose tools like dashboards that are not tailored towards specific contracts. This PR changes this by emitting an event whenever a contract was successfully called. Successfully because events are rolled back as storage changes on failure. We argue that rolled back calls "didn't happen" anyways as they do not lave any trace on-chain except incurred costs.

Please not that we do not include the input or output of those calls on purpose as this would include a variable overhead that we do not want to enforce for every single contract. Authors need to emit custom events in case this is needed.

Additionally, we add topics to all events so that clients have an easier time to subscribe to stuff they are interested in without needing to download each block.

Needed for paritytech/polkadot-sdk#120

@achimcc I think you asked for this some time ago?

Thanks for letting me know @athei ! I forwarded the info/PR to the Subsquid guys which requested this feature!

ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Add topics to contract events

* Add `Call` events

* Fix compilation for no_std

* Added docs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants