lavanet / lava

Apache License 2.0
402 stars 206 forks source link

[Feature]: New SPEC language to make It less verbose. Increase readability and maintainability #1555

Open RuslanGlaznyov opened 1 month ago

RuslanGlaznyov commented 1 month ago

Summary

We have verbose API descriptions in the SPEC, which are challenging to write and review.

For example, in lava spec, this setting repeats for all endpoints:

 {
  "name": "/lavanet/lava/conflict/conflict_vote/{index}",
  "block_parsing": {
    "parser_arg": [
      "latest"
    ],
    "parser_func": "DEFAULT"
  },
  "compute_units": 10,
  "enabled": true,
  "category": {
    "deterministic": true,
    "local": false,
    "subscription": false,
    "stateful": 0
  },
  "extra_compute_units": 0
}

https://github.com/lavanet/lava/blob/main/cookbook/specs/lava.json#L36

The same thing for verifications and extensions https://github.com/lavanet/lava/blob/main/cookbook/specs/lava.json#L1247 https://github.com/lavanet/lava/blob/main/cookbook/specs/lava.json#L2463 https://github.com/lavanet/lava/blob/main/cookbook/specs/lava.json#L2507

Problem Definition

Now spec is verbose and we have a lot of repeats for endpoints

Proposed Feature

The idea is to create a new spec lang on top of the current lang, the same way as TS for JS, but for spec.

Here is an example of a new spec language

api_collections: 
  - enabled: true
    collection_data: 
     api_interface: "rest"
     type: "GET"
    # default settings for each endpoint  
    api_default: 
     block_parsing: 
      parser_arg: ["latest"]
      purser_func: "DEFAULT"
      computute_unit: 10
      enabled: true
      category: 
       deterministic: true
       local: false
       subscription: false
       stateful: false
      extra_compute_units: 0 
    apis:
    # here is an example of endpoints with default params 
     - name: [
         '/example/example/v1beta1/params',
         '/example/example/v1beta1/params',
         '/example/example/v1beta1/params',
       ]
     # here is the example of the batch of endpoints with overridden params   
     - name: [
         "/example/example/v1beta1/params",
         "/example/example/v1beta1/params",
         "/example/example/v1beta1/params",
         ]
       cotegory: 
        deterministic: true
    # override single endpoint settings 
     - name: '/example/example/v1beta1/params'
       extra_compute_units: 5

This YAML example will be transpile to regular JSON spec. The compiler will convert bidirectional json -> yaml yaml -> json

This approach will increase the readability of spec and maintainability. We don't need to modify existing spec logic on-chain, because translation will be done off-chain.

omerlavanet commented 1 month ago

thanks @RuslanGlaznyov i love this initiative, improving spec stack allows more champions and easier onboarding which is one of our goals will definitely revisit this post launch