Conversation
|
Be good to get an opinion on this @svyatonik |
svyatonik
left a comment
There was a problem hiding this comment.
The idea seems OK to me. I'll submit some issues soon to not-to-forget what needs to be changed with changes tries. We need (at least) to extend changes tries API (and network messages) to allow fetching changes for several keys (here: topics) at once.
|
I've checked the storage entries and add a test. This should be ready for review then. |
# Conflicts: # node/runtime/src/lib.rs
|
There might be a problem with this approach, marking it inprogress until we figure it out. |
|
what might the problem be? |
|
Yes, there is indeed a problem, although not a significant one. Consider the case when an event So at the end of the block then, let's suppose that the same event Because the value at the storage location of I am still not entirely sure, but it seems to be a problem. If the light-client doesn't follow each block, and say, it "subscribes" to changes at the block To circumvent this problem we could store |
|
Ok, I put up a commit which fixes this. However, I went with Apparently it starts asking for a hand-rolled structure tailored for this particular use-case. |
# Conflicts: # core/test-runtime/wasm/Cargo.lock # node-template/runtime/wasm/Cargo.lock # node/executor/src/lib.rs # node/runtime/src/lib.rs # node/runtime/wasm/Cargo.lock
|
ok, but please add a TODO and issue explaining that this is highly inefficient and needs to be altered to |
|
This seems like a breaking change and requires JS SDK side change as well. |
* Sketch of indexed events. * Get EventIndex by holding another variable. * Add some docs. * Use DoubleMap to store reverse topic index * Implement StorageDoubleMap::append * Use append for EventTopics. * Refactor. * Avoid `mutate` * Docs. * Add topics to EventRecord * Update tests. * Rebuild. * Bump version. * Event topics test. * Mix in BlockNumber to distinguish updates * Fix srml-system test. * Post merge fixes. * Comments/TODO.
This PR proposes a solution for light client friendly SRML events.
Each deposited event can specify zero or more topics. A topic is a fixed sized value (atm, is just a hash). When an event is deposited with some topic, the runtime adds the index of this event in the
<Events<T>>list to a mapping that maps from topics to lists of indexes.Light clients can "subscribe" to changes of specific storage values (see #628). The idea is that light clients would subscribe to changes of the storage values for a topic they are interested in. When the light client detects a change, it fetches the contents of the indexes list for the specific topic and with this the light client can query events' data by the indexes.
Marking this as draft, since I don't know if this is the way that we want to go, I didn't test this with light-client nor inspected the storage values and there are some questions left