streamingfast / substreams

Powerful Blockchain streaming data engine, based on StreamingFast Firehose technology.
Apache License 2.0
164 stars 45 forks source link

Substreams Sink to KV (gRPC/Connect-Web API) #94

Closed maoueh closed 1 year ago

maoueh commented 1 year ago

Now that we have a Substreams sink to KV (https://github.com/streamingfast/substreams/issues/93), we will know try to have something easier for the developers to consume the KV store.

We are going to slap a gRPC + Connect Web.on top of the substream-sink-kv. At the infrastructure level, we expect a single binary to run that will do 2 things:

rpc {
  // Proper documentation for all request, also describes what happen on error cases (for example, on XXX it returns `InvalidArgument` gRPC code!
  Get(GetRequest) GetResponse
  GetMany(GetManyRequest) GetManyResponse
  Scan(ScanRequest)…
  Prefix(PrefixRequest)…
}

message GetResponse {
  any.Any value = 1;
}

message ScanRequest{
  uint64 limit;
  ...

And the payload would simply be an any.Any, with the value of the key, and the client would do the decoding, because he knows what he’s querying.

While doing this don't forget:

Design should allow these examples substreams to be built

sduchesneau commented 1 year ago

What do we do with maximum results and pagination for requests such as "Scan" and "Prefix" ? Without "time-traversal" properties on the kv store, we will end up with the same design problem as eth rpc calls...

sduchesneau commented 1 year ago

Small analysis of concurrency problems:

  1. on Badger (local DB only), we can implement WriteLock around the operations of a block
  2. on TiKV, there are ways of wrapping our changes in a transaction (then make it "one block == one transaction"
  3. on BigTable, there are no transactions or decent locking possibility, but we could use the timestamps of cells to filter by block number: https://cloud.google.com/bigtable/docs/using-filters#timestamp-range

on our own 'netkv', I don't see a good solution..

maoueh commented 1 year ago

Reopening because the task will be closed when instructions will have been sent to Pinax and our Discord

maoueh commented 1 year ago

Also, here a few things that are missing:

sduchesneau commented 1 year ago

@maoueh please review https://substreams.streamingfast.io/developers-guide/substreams-sinks/substreams-sink-kv#consume-the-key-value-data-from-a-web-page-using-connect-web

then we can close this issue :D

maoueh commented 1 year ago

All good, just some alignment of code blocks with bullet list, closing anyway so we move on.