API Requirements

What we have and what we are facing?

What we want is an API to fetch blocks from the storage layer (assume that the tip is from carnot/info api).

We have:

  1. A key-value storage layer, the key is block hash, the value is block info. Key-values are stored out of order (sled is an ordered storage by key, but our block hash does not have a valid Ord implementation, so the order in db cannot reflect the order we store those blocks)

We face:

  1. We need to invoke get(id: BlockId) on sled N times, N is the gap between from and to. This leads to bad performance and expensive overhead, because the actual IO operations are M x N times, where M < N.

We can improve:

  1. Global block number like ethereum, we can use the block number as the key, and then the API, will be from: BlockNumber, to: Option<BlockNumber>. In storage side, we can directly fetch all of N blocks by list(range: Range<BlockNumber>). In this way, we need M IO operations.

Naive Solution (Current)

A while loop, we find from first, and call parent to get the parent block, and continue until we reach to.

Ideal Solution (Future)

Add index information like BlockNumber, so that we can improve the query performance signaficantly.