streamingfast / substreams

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

Reusable Substreams modules with rewired inputs (use:) #403

Closed abourget closed 6 months ago

abourget commented 7 months ago

Context

Currently, we can reuse a module while overriding its params and initialBlocks.

However, there's no easy way to declare a completely generic module (ex: a mapper that converts a proto:sf.substreams.sink.database.v1.DatabaseChanges to type: proto:sf.substreams.entity.v1.EntityChanges) and use it on the output on our module, because we cannot override its "input".

The idea is to be able to swap a module's input with another input that has the same type.

ex

specVersion: v0.1.0
package:
  name: byac
  version: v0.1.0

imports:
  converter: spkg.io/streamingfast/converter-v1.0.2

modules:
...
  - name: db_out
    kind: map
    initialBlock: 12287507
    inputs:
      - map: map_events
    output:
      type: proto:sf.substreams.sink.database.v1.DatabaseChanges

  - name: graph_out
    use: converter:dbout_to_graphout
    inputs:
      - map: db_out

The line:

    use: converter:dbout_to_graphout

in here would make it use the code from the imported module, but rewire the inputs and outputs, making sure that they are of the same type.

The converter author has a substreams.yaml like this:

specVersion: v0.1.0
package:
  name: converter
  version: v1.0.2

modules:
...
  - name: example_dbout  # write some code here that does nothing, just to link things.
    kind: map
    inputs:
       source: sf.substreams.v1.Clock
    output:
      type: proto:sf.substreams.sink.database.v1.DatabaseChanges

  - name: dbout_to_graphout
    kind: map
    inputs:
      - map: example_dbout
    output:
      type: proto:sf.substreams.entity.v1.EntityChanges

TODO

The substreams client will do all the required remapping for that feature.

ArnaudBger commented 6 months ago

432