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

Conversation

@pepyakin
Copy link
Contributor

@pepyakin pepyakin commented May 13, 2019

This PR builds on top of #2491 and adds an ability for a contract to supply a list of topics along with an event.

ext_deposit_event now gets two paramters to supply a buffer with a topic list: topics_ptr and topics_len. There are some restrictions on this list.

  1. This buffer must encode a proper Vec<TopicOf<T>> vector.
  2. The size of a vector mustn't exceed max_event_topics (otherwise, the function traps).
  3. The vector must not contain any duplicates (otherwise, again, it traps)

There is one exception for 1) - passing 0 to the topics_len parameter is treated as an empty topics vector. In this case, the value of topics_ptr is ignored. The deduplication check is implemented as two loops: this is ok, as long as max_event_topics is small, and doesn't require additional memory.

This PR also introduces some fixed gas fee per topic, which is checked before recording the event.

The rest is almost the same, all events are recorded along with their topics and if they made it to the finalization phase, then all the events are deposited with respective topics.

@pepyakin pepyakin added A0-please_review Pull request needs code review. A3-in_progress Pull request is in progress. No review needed at this stage. labels May 13, 2019
@pepyakin pepyakin requested a review from gui1117 May 13, 2019 16:43
Copy link

@DemiMarie-temp DemiMarie-temp left a comment

Choose a reason for hiding this comment

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

The quadratic check for duplication in topics can be reduced to O(n log n) at the cost of a memory allocation. Additionally, it appears that event delivery is unreliable. If it is, that should be documented.

let event_idx = {
let old_event_count = <EventCount<T>>::get();
let new_event_count = match old_event_count.checked_add(1) {
// We've reached the maximum number of events at this block, just

Choose a reason for hiding this comment

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

This means that event delivery is unreliable, which could lead to starvation or deadlock in some protocols.

Copy link
Contributor Author

@pepyakin pepyakin May 13, 2019

Choose a reason for hiding this comment

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

Ah, this is more related to #2491 or even before that, to #2282.

I believe this code is a mere defending practice and will not be triggered. Here is my reasoning: wasm32 is a 32-bit platform. It can have at most 4GB of memory, that is, 2^32 bytes. Considering an element to be u8, by the time we reach this number of elements the memory will already be full.

If you are still concerned by this issue, I think it would be best to move this discussion into a new issue (or at least to the now closed #2282)

@pepyakin pepyakin force-pushed the ser-contract-topic-events branch from e23224e to fe64849 Compare May 13, 2019 20:30
@pepyakin pepyakin removed the A3-in_progress Pull request is in progress. No review needed at this stage. label May 13, 2019
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

looks good

@pepyakin pepyakin requested a review from gui1117 May 14, 2019 09:55
Copy link
Contributor

@gui1117 gui1117 left a comment

Choose a reason for hiding this comment

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

looks good to me

@gavofyork gavofyork merged commit 63f6c81 into master May 14, 2019
@gavofyork gavofyork deleted the ser-contract-topic-events branch May 14, 2019 10:09
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Jul 10, 2019
* Introduce an IndexedEvent

* Plumb topics through the Ext interface.

* Add topics to ext_deposit_event

* Charging for events.

* Check the number of topics.

* Check for duplicate topics.

* Bump API version.

* Move derive(*Eq) under test.

* Use sorting for finding duplicates.
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants