Closed yusefnapora closed 8 years ago
k; the last commit changes canonical_stream
to output the folded canonical for both the insertCanonicalEvent
and updateChainEvent
to make sure we get both canonicals with empty chains and updates. It adds some overhead, but seems safest.
This adds a new parameter to the
BlockchainFollower
constructor, anevent_map_fn
that maps rpc events into whatever you want. It's actually a combined map / filter fn, really, since if you returnNone
, it will skip yielding that event entirely.With that in place, we can return a
BlockchainFollower
directly fromcanonical_stream
, which means that the caller can use thewith client.canonical_stream() as stream
pattern to get the automatic close behavior we need if we want to disable the timeouts.This won't break the current indexer, since the
BlockchainFollower
can be iterated over directly, and the indexer is currently passing in an explicit timeout. Once this is in place, the indexer can drop the timeout and usewith / as
to get the infinite stream.Note: this removes the hack that we put in place for
canonical_stream
where it only emits the canonical after the first chain cell. That no longer makes sense now that we're introducing more translators. So thecanonical_stream
now yields updated canonicals for eachinsertCanonicalEvent
in the stream.This means we still need to figure out the potential race condition, where the indexer sees the
insertCanonicalEvent
and requests the folded object before the update cell comes in.One possible solution is to have the indexer listen for updates and re-request the folded canonical, although ideally we'd like to also keep track of the last known chain head to avoid re-requesting if we've already seen that update. Anyway, that sounds like a job for a separate PR.