Skip to content

Proposal: make block stream yield blocks when requested #5455

@0x009922

Description

@0x009922

How it works now

Currently, when Iroha has e.g. 1500 blocks and you connect to the block stream with height=1000, it will immediately emit (as WebSocket events) all existing 500 blocks, and then emit new blocks when ready.

Problem

It is not necessarily desirable. A client might need to take some time to process each incoming block (as is the case with the Explorer, for example). Keeping all received blocks from the stream in memory until then would be problematic when there are many of them.

Proposal

Introduce a mechanism to emit blocks only when the client tells it's ready to receive the next one.

Technically, I imagine BlockSubscriptionRequest to have an additional parameter - lazy:

struct BlockSubscriptionRequest {
  from_height: NonZero<u64>,
  lazy: bool
}

If client sets lazy: true, then Iroha would wait for the next invocation from the client:

enum BlockStreamClientMessage {
  /// Client is ready to receive the next block (applicable when `lazy: true`)
  Next
}

Downsides

Breaking ABI change.

Alternatives

None in my mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions