This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
contracts: add events to ContractResult #13807
Merged
paritytech-processbot
merged 32 commits into
master
from
jg/12412-contracts-return-emitted-events-for-dry-runs
May 3, 2023
Merged
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
47200ff
contracts: add events to ContractResult
juangirini a534758
contracts: add encoded events to ContractResult
juangirini 28a9643
contracts: add generic Event to ContractResult
juangirini cf43686
Merge remote-tracking branch 'origin/master' into jg/12412-contracts-…
juangirini 08db645
contracts: test bare_call events
juangirini 7ca1b4b
contracts: update bare_call test name
juangirini 5ad0868
contracts: add better comments to dry run events
juangirini dbd8735
contracts: fix pallet contracts primitives implementation
juangirini 1718400
contracts: add EventRecord generic to ContractInstantiateResult
juangirini 782aba7
contracts: make event collection optional
juangirini 74d4b70
contracts: impreved notes on `collect_events`
juangirini 45e6eab
contracts: update benchmarking calls
juangirini 4426bbe
contracts: change bare_call and bare_instantiate to accept enums inst…
juangirini 0de45b6
contracts: add partial eq to new enums
juangirini 8d36e91
contracts: improve comments
juangirini 02c41d3
contracts: improve comments
juangirini 5d4fd5c
contracts: merge master and resolve conflicts
juangirini b9cb4ef
contracts: fix bare_call benchmarking
juangirini a8b0c8b
contracts: fix bare call and instantiate in impl_runtime_apis
juangirini 160cfb3
contracts: add api versioning to new ContractsApi functions
juangirini dacdc53
contracts: modify api versioning to new ContractsApi functions
juangirini e7fa394
contracts: merge master and fix conflicts
juangirini 337e54e
contracts: create new contracts api trait
juangirini b9838b1
contracts: clean up code
juangirini fca001f
contracts: remove the contract results with events
juangirini a8da1ff
contracts: undo contracts api v3
juangirini af6587a
contracts: remove commented out code
juangirini 9919fd1
contracts: add new test bare call result does not return events
juangirini 51894be
contracts: merge master and resolve conflicts
juangirini 1e09bdb
contracts: add code review improvements
juangirini eef0f97
contracts: remove type imports
juangirini 3023dfd
contracts: minor code review improvements
juangirini File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -117,7 +117,7 @@ use frame_support::{ | |||||
weights::Weight, | ||||||
BoundedVec, RuntimeDebugNoBound, WeakBoundedVec, | ||||||
}; | ||||||
use frame_system::{EventRecord, Pallet as System}; | ||||||
use frame_system::{ensure_signed, pallet_prelude::OriginFor, EventRecord, Pallet as System}; | ||||||
use pallet_contracts_primitives::{ | ||||||
Code, CodeUploadResult, CodeUploadReturnValue, ContractAccessError, ContractExecResult, | ||||||
ContractInstantiateResult, ExecReturnValue, GetStorageResult, InstantiateReturnValue, | ||||||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
missed that earlier |
||||||
/// | ||||||
/// **Never** use this mode for on-chain execution. | ||||||
|
@@ -1231,14 +1231,15 @@ impl<T: Config> Pallet<T> { | |||||
storage_deposit_limit: Option<BalanceOf<T>>, | ||||||
data: Vec<u8>, | ||||||
debug: DebugInfo, | ||||||
juangirini marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
determinism: Determinism, | ||||||
collect_events: CollectEvents, | ||||||
determinism: Determinism, | ||||||
) -> ContractExecResult<BalanceOf<T>, EventRecordOf<T>> { | ||||||
let mut debug_message = if matches!(debug, DebugInfo::UnsafeDebug) { | ||||||
Some(DebugBufferVec::<T>::default()) | ||||||
} else { | ||||||
None | ||||||
}; | ||||||
let origin = Origin::from_account_id(origin); | ||||||
let common = CommonInput { | ||||||
origin, | ||||||
value, | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Even if
EventRecords = ()
this will still add some bytes to the end of the struct. This is not 100% backwards compatible as clients might reject trailing data.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.
This has been tested against Contracts UI and it works just fine.
The 'old'
call
andinstantiate
functions returnevents: None
that encodes to0x00
, but as far as I understand SCALE ignores trailing data. Anyway, if we want to be on the safe side we can always create two versions ofContractResult
, one with and another one withoutevents
.WDYT?
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.
SCALE is not really well defined by a spec or something. Whether you ignore trailing data or not is up to the implementation. See
Decode
vsDecodeAll
.That said, I suspect the default behavior is to ignore trailing data. Hence we can safely extend the struct in new versions. But if you think about it this means we don't even need a new version in this case because we can just always emit the events since they will be ignored by older code as trailing data. If they ignore a single
0x00
they will also ignore everything else.I suggest we do away with the new version and two type aliases and just extend the struct. Should work the same way.
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 have removed the new version and implemented it all in the original
ContractsApi
. Tested it against Contracts UI and works fineThere 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.