mediachain / oldchain-client

[DEPRECATED] old mediachain client experiments
MIT License
4 stars 2 forks source link

change canonical_stream to return a BlockchainFollower object with map/filter fn #74

Closed yusefnapora closed 8 years ago

yusefnapora commented 8 years ago

This adds a new parameter to the BlockchainFollower constructor, an event_map_fn that maps rpc events into whatever you want. It's actually a combined map / filter fn, really, since if you return None, it will skip yielding that event entirely.

With that in place, we can return a BlockchainFollower directly from canonical_stream, which means that the caller can use the with 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 use with / 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 the canonical_stream now yields updated canonicals for each insertCanonicalEvent 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.

yusefnapora commented 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.