-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 |
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?
frame/contracts/src/lib.rs
Outdated
@@ -980,7 +980,7 @@ pub enum CollectEvents { | |||
/// | |||
/// # Note | |||
/// | |||
/// Events should only be collected when called off-chain, as this would | |||
/// Events should only be collected when called off-chain, as this would otherwise | |||
/// collect all the Events emitted in the block so far and put them in them into the PoV. |
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
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.
@@ -71,15 +71,26 @@ pub struct ContractResult<R, Balance> { | |||
pub debug_message: Vec<u8>, | |||
/// The execution result of the wasm code. | |||
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
events
to theContractResult
struct (ContractExecResult
andContractInstantiateResult
) so that calls tobare_call
andbare_instantiate
can 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_call
andbare_instantiate
functions accept a newdebug
parameter of typeDebugInfo
which is an enum. Whendebug
is set toDebugInfo::UnsafeDebug
the events are collected, when set toDebugInfo::Skip
events returnNone
.Related Cargo Contract issue
cumulus companion: paritytech/cumulus#2510