-
Notifications
You must be signed in to change notification settings - Fork 2.7k
contracts: add events to ContractResult #13807
contracts: add events to ContractResult #13807
Conversation
…return-emitted-events-for-dry-runs
|
@athei This changes have been tested successfully against the contract-ui tool, but not against |
|
bot help |
|
Here's a link to docs |
agryaznov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this PR have a cumulus companion?
| }; | ||
| use codec::{Codec, Decode, Encode, HasCompact}; | ||
| use environmental::*; | ||
| use frame_support::{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// collect all the Events emitted in the block so far and put them in them into the PoV. | |
| /// collect all the Events emitted in the block so far and put them into the PoV. |
missed that earlier
athei
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Ready to merge after those last nits are removed.
bin/node/runtime/src/lib.rs
Outdated
| use pallet_contracts_primitives::{ | ||
| Code, CodeUploadResult, ContractExecResult, ContractInstantiateResult, GetStorageResult, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is no longer needed, right? It is a bit inconsistent now. Sometimes you use fully qualified types and sometimes you use those imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those types are used in the code, we do need either the imports or the fully qualified types.
There is indeed a mix of both in that file, not sure what is the guideline here. I am making them all fully qualified so at least it is consistent in my own code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is what I was getting at. Thanks.
| pub result: R, | ||
| /// The events that were emitted during execution. It is an options as event collection is | ||
| /// optional. | ||
| pub events: Option<Vec<EventRecord>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a #Note to the type to warn users that we take the liberty to extend the type with new data without bumping the API version? It should warn them to always ignore trailing data.
Correct. CI is complaining. |
|
bot merge |
|
Waiting for commit status. |
* contracts: add events to ContractResult * contracts: add encoded events to ContractResult * contracts: add generic Event to ContractResult * contracts: test bare_call events * contracts: update bare_call test name * contracts: add better comments to dry run events * contracts: fix pallet contracts primitives implementation * contracts: add EventRecord generic to ContractInstantiateResult * contracts: make event collection optional * contracts: impreved notes on `collect_events` * contracts: update benchmarking calls * contracts: change bare_call and bare_instantiate to accept enums instead of bools * contracts: add partial eq to new enums * contracts: improve comments * contracts: improve comments * contracts: fix bare_call benchmarking * contracts: fix bare call and instantiate in impl_runtime_apis * contracts: add api versioning to new ContractsApi functions * contracts: modify api versioning to new ContractsApi functions * contracts: create new contracts api trait * contracts: clean up code * contracts: remove the contract results with events * contracts: undo contracts api v3 * contracts: remove commented out code * contracts: add new test bare call result does not return events * contracts: add code review improvements * contracts: remove type imports * contracts: minor code review improvements
* contracts: add events to ContractResult * contracts: add encoded events to ContractResult * contracts: add generic Event to ContractResult * contracts: test bare_call events * contracts: update bare_call test name * contracts: add better comments to dry run events * contracts: fix pallet contracts primitives implementation * contracts: add EventRecord generic to ContractInstantiateResult * contracts: make event collection optional * contracts: impreved notes on `collect_events` * contracts: update benchmarking calls * contracts: change bare_call and bare_instantiate to accept enums instead of bools * contracts: add partial eq to new enums * contracts: improve comments * contracts: improve comments * contracts: fix bare_call benchmarking * contracts: fix bare call and instantiate in impl_runtime_apis * contracts: add api versioning to new ContractsApi functions * contracts: modify api versioning to new ContractsApi functions * contracts: create new contracts api trait * contracts: clean up code * contracts: remove the contract results with events * contracts: undo contracts api v3 * contracts: remove commented out code * contracts: add new test bare call result does not return events * contracts: add code review improvements * contracts: remove type imports * contracts: minor code review improvements
Fix #12412
It adds an Option
eventsto theContractResultstruct (ContractExecResultandContractInstantiateResult) so that calls tobare_callandbare_instantiatecan return the events collected. This is useful when dry running.Collecting events though should only be done outside of the runtime block execution, so that the
bare_callandbare_instantiatefunctions accept a newdebugparameter of typeDebugInfowhich is an enum. Whendebugis set toDebugInfo::UnsafeDebugthe events are collected, when set toDebugInfo::Skipevents returnNone.Related Cargo Contract issue
cumulus companion: paritytech/cumulus#2510