Block Reward Formula per Block

I’m working on a project that needs to be able to calculate the exact block reward at a given height. Since it isn’t disclosed in the API’s, I’ve been working on reworking the coinbase_gen script but seem to have messed it up somewhere (my Erlang is subpar).

The formula for block reward at a given height is here correct? Is there any description on the actual methodology used here (not the inflation curve, but the actual algorithm used to avoid rounding errors)?

The goal is to do this in a non-recursive manner, to avoid having to recursively calculate the “existing supply” for each height.

1 Like

I am not 100% sure and haven’t checked that endpoint on my own but my guess is that if you have debug endpoints enabled on your node you should be able to get that using this endpoint:

    "/debug/token-supply/height/{height}": {
      "get": {
        "tags": [
          "internal",
          "debug"
        ],
        "operationId": "GetTokenSupplyByHeight",
        "description": "Get total token supply at height",
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "in": "path",
            "name": "height",
            "description": "The height",
            "required": true,
            "type": "integer",
            "minimum": 0,
            "maximum": 18446744073709551615
          }
        ],
        "responses": {
          "200": {
            "description": "Total token supply at height divided in categories",
            "schema": {
              "$ref": "#/definitions/TokenSupply"
            }
          },
          "400": {
            "description": "Height not available",
            "schema": {
              "$ref": "#/definitions/Error"
            }
          }
        }
      }
    }
  }

but I better let someone of the core devs confirm that :sweat_smile:

1 Like

Oh wow I didn’t even see that, that would totally be enough for me to avoid recursion though, I can handle the calculation given previous supply pretty easily.

The issue is, I can’t seem to get a response from the debug endpoints - is there some configuration I have to specify to enable them? For example:

curl http://localhost:3013/v2/key-blocks/height/10 gives me the expected response but
curl http://localhost:3013/v2/debug/token-supply/height/10 does not work. The peer endpoint for debug gives an empty response too, so I’m assuming its the debug endpoints in general.

For what it’s worth, aeknow gives the reward so I checked their code and they seem to be just storing the same data in a table (meaning there’s probably no good way to non-recursively calc this besides asking a source who has calculated it all) - code here.

** EDIT **

Now I’m noticing that I configure an external and an internal port like so:

http:
  external:
    port: 3013
  internal:
    port: 3113

Though even when I try curl http://localhost:3113/v2/debug/token-supply/height/10 or
curl http://localhost:3013/debug/token-supply/height/10, I get an empty response.

1 Like

Ah! I figured it out, I had to change my config to this:

http:
  external:
    port: 3013
  internal:
    port: 3113
    debug_endpoints: true

That being said, I’m using this endpoint and it is really really slow, it seems to be doing it recursively was well. The first few orders of magniture (1, 10, 100) take a second or two (which is relatively long), but 100,000 times out. I think this endpoint is definitely debug for a reason ha

1 Like

what project?

profit switching

1 Like