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

Conversation

@drahnr
Copy link
Contributor

@drahnr drahnr commented Mar 30, 2020

Provides a stream that guarantees to trigger on every block, imported, synced.

@drahnr drahnr added the A3-in_progress Pull request is in progress. No review needed at this stage. label Mar 30, 2020
Includes sync blocks too.
@drahnr drahnr force-pushed the bernhard/all-import-stream branch from d9c1e4b to 0c8037d Compare March 30, 2020 10:02
@drahnr drahnr requested review from NikVolf and tomusdrw as code owners March 30, 2020 10:02
Copy link
Contributor

@tomusdrw tomusdrw left a comment

Choose a reason for hiding this comment

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

Looks OK, but given the use cases we have in mind (Indexing OCW) I believe we should implement something more sophisticated, that gives us more guarantees about execution (state availability + persistence). I've drafted an idea in one of the comments.

storage_notifications: Mutex<StorageNotifications<Block>>,
import_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<BlockImportNotification<Block>>>>,
finality_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<FinalityNotification<Block>>>>,
all_blocks_notification_sinks: Mutex<Vec<mpsc::UnboundedSender<AllBlocksNotification<Block>>>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm quite hesitant on adding another Unbounded channel here. This may become very unreliable, imagine a case where:

  1. You have some non-trivial work to do on every block
  2. The channel queues up a bunch of blocks, as you are not as fast processing them.
  3. The state get's pruned in the meantime.

The whole scheme is then useless, cause even when we receive the notification the state is already lost. Also if the node is turned off the whole content of the channel is lost, so we will essentially miss running for some blocks.

If we want to make it super reliable and make sure that EACH and EVERY block is indexed/processed we need to come up with a more sophisticated mechanism.
I imagine something like LMAX-Disruptor scheme, where we:

  1. Persist the state of indexing in some DB
  2. Pin the state, up until the slower consumer processes it.
  3. Proceed as fast as possible with fast consumers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm quite hesitant on adding another Unbounded channel here.

Same here.

operation.op.insert_aux(aux)?;


let header = import_headers.into_post();
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth to construct this lazily for all_blocks. Also I'd consider passing less data to all_blocks notification for performance reasons.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Passing less data is imho not possible since header is required in https://github.com/paritytech/substrate/pull/5455/files#diff-240c17a1e4dbce4ad137b7777bf03ce4R919-R924 which in turn requires header to be extracted from import_headers - correct me if I am wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

In case there can be many all-blocks-notification-streams one could pass an Arc<AllBlocksNotification> down the channels instead of a clone for each channel within notify_any_block_imported.

We do similar things for the NetworkService::event_stream where we pass a Bytes instead of a Vec<u8>.

@arkpar
Copy link
Member

arkpar commented Mar 30, 2020

What's the intended usage for this stream?

@drahnr
Copy link
Contributor Author

drahnr commented Mar 30, 2020

@arkpar ultimately for providing a complete stream of block imports for #3722

drahnr and others added 4 commits March 30, 2020 15:54
Co-Authored-By: Tomasz Drwięga <[email protected]>
Co-Authored-By: Tomasz Drwięga <[email protected]>
Co-Authored-By: Tomasz Drwięga <[email protected]>
@drahnr drahnr mentioned this pull request Mar 30, 2020
@drahnr
Copy link
Contributor Author

drahnr commented Apr 1, 2020

Will be deferred to later point of time :)

@drahnr drahnr closed this Apr 1, 2020
@bkchr bkchr deleted the bernhard/all-import-stream branch April 1, 2020 15:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A3-in_progress Pull request is in progress. No review needed at this stage.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants