This adds server sent event apis for /subscribe-contracts and /subscribe-blocks. Internally it uses a stream unfold that does the initial lists and then awaits a watch channel for updates. I chose a watch instead of a notify because a watch Receiver will return from changed() if there has been any updates since the start of the channel. This means that the api will never miss an update. Compared to a notify which would work if we used notify_one() except that we can have multiple streams, so you would need to use notify_waiters() which only notifies streams actively awaiting the notify future. This makes it easy to miss an update.
The stream logic is abstracted across databases and contracts / blocks which makes it easier to maintain and test. It has to live in the essential-storage crate because of this though.
TODO:
[x] Add block number as a starting point for list-blocks and use it in subscribe blocks.
[x] Add tests to value paging in mem storage
[x] Add tests for subscription around different paging for db
This adds server sent event apis for
/subscribe-contracts
and/subscribe-blocks
. Internally it uses a stream unfold that does the initiallists
and then awaits a watch channel for updates. I chose a watch instead of a notify because a watchReceiver
will return fromchanged()
if there has been any updates since the start of the channel. This means that the api will never miss an update. Compared to a notify which would work if we usednotify_one()
except that we can have multiple streams, so you would need to usenotify_waiters()
which only notifies streams actively awaiting thenotify
future. This makes it easy to miss an update.The stream logic is abstracted across databases and contracts / blocks which makes it easier to maintain and test. It has to live in the
essential-storage
crate because of this though.TODO: