Blob gas price prediction and history methods update

Stage: Idea, Prototype

TL;DR

  • Add eth_gasPrices that returns prices for regular and blob gas
  • Add eth_blobGasPrice
  • Update eth_feeHistory to include blob related data

Execution-apis PR

Motivation

Execution client provides gas price prediction via eth_gasPrice and fee history via eth_feeHistory. Such information allows to create a transaction with real value for gas fee cap and tip, so it will be executed in adequate time for adequate price. Shard blob transactions EIP introduces another kind of gas - blob's, so users have to pay for it in addition to regular gas fees when posting blobs. It may be useful to have ability to retrieve potential blob gas price for the same purpose as it is for regular gas.

Before adding another endpoints or upgrading existing ones let's enumerate cons that would be cool to address.

  1. Blob gas price calculation is trivial: to predict blob gas fee for the next blob we just need the values of the current block's header, specifically excess data gas and blob gas used;

    The same is true for the regular gas, the oracle may also be based on non-trivial implementation that produces more efficient prediction, taking into account the transaction may be added to some block far ahead due to price hike.

  2. Is there a real need? Blob transactions will be mostly sent by projects like L2s, not by end users. Execution client's oracle can be not so useful for such projects.

    • Making sending blobs more convenient increases neutrality of the blobs update, it's hard to let obstacles stay if we know about them;
    • Make blob senders which do it from browsers happier.

New method eth_blobGasPrice

Estimation - TBD

The simplest (used by prototype)

blobGas = ceil(MIN_BLOB_GASPRICE * e**(excess_blob_gas / BLOB_GASPRICE_UPDATE_FRACTION))

Adjusted, based on gas used statistics

Let's try to estimate blobGas needed to get into next 2 blocks.

Given:

  • excess_blob_gas for the head block
  • blob_gas_used for the previous N blocks
  • multiplier for confidence = 110%
to_be_sure_coef = 110 / 100

average_gas_used = 0
for i in range(head.number - N + 1, head.number + 1):
    average_gas_used += blocks[i].blob_gas_used
average_gas_used = average_gas_used / N)

blobGas = ceil(MIN_BLOB_GASPRICE * e**((excess_blob_gas + average_gas_used) / BLOB_GASPRICE_UPDATE_FRACTION) * to_be_sure_coef)

API

The method is similar to eth_gasPrice

Request

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_blobGasPrice"
}

Response

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": "0x7"
}

Alternatives

  • eth_gasPrices - a method similar to eth_gasPrice, but with prices for multiple gas prices needed. Covered by batch requests.

    Request

    ​​​​{
    ​​​​  "id": 1,
    ​​​​  "jsonrpc": "2.0",
    ​​​​  "method": "eth_gasPrices"
    ​​​​}
    

    Response

    ​​​​{
    ​​​​  "id": 1,
    ​​​​  "jsonrpc": "2.0",
    ​​​​  "result": {
    ​​​​    "gas" : "0x7",
    ​​​​    "blobGas" : "0x7",
    ​​​​    "maxPriorityFee" : "0x2"
    ​​​​  }
    ​​​​}
    
  • REST style

    Request

    ​​​​GET /v1/eth/blob-price
    

    Response

    ​​​​200 OK
    
    ​​​​0x7
    

Update for eth_feeHistory

API - TBD

Let's add baseFeePerBlobGas/blobGasUsedRatio, that have 0 values for pre-Cancun blocks.

Request

{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_feeHistory",
    "params": [2, "latest", [25, 75]]
}

Response

{
  "id": "1",
  "jsonrpc": "2.0",
  "result": {
    "oldestBlock": 42, // 0x2a?
    "reward": [
      [
        "0x4a817c7ee",
        "0x4a817c7ee"
      ], [
        "0x773593f0",
        "0x773593f5"
      ], [
        "0x0",
        "0x0"
      ], [
        "0x773593f5",
        "0x773bae75"
      ]
    ],
    "baseFeePerGas": [
      "0x10",
      "0x12",
      "0x10",
    ],
    "baseFeePerBlobGas": [
      "0x1",
      "0x2",
      "0x1",
    ],
    "gasUsedRatio": [
      0.0,
      0.5,
      0.25,
      0.25
    ],
    "blobGasUsedRatio": [
      0.0,
      0.5,
      0.25,
      0.25
    ]
  }
}

Prototype

Ping @__flcl in the R&D discord in case of troubles

In Nethermind

  • ✅ eth_blobGasPrice
  • ✅ eth_feeHistory
  • ✅ eth_gasPrices [no plans to include in stable version]

Branch: https://github.com/NethermindEth/nethermind/tree/feature/blob-price

Image: nethermindeth/nethermind:blob-price

RPC:

curl:

curl --request POST --url http://139.177.181.61:8545 \
     --header 'content-type: application/json' \
     --data '{ "method": "eth_blobGasPrice", "id": 1, "jsonrpc": "2.0" }'
curl --request POST --url http://139.177.181.61:8545 \
     --header 'content-type: application/json' \
     --data '{ "method": "eth_feeHistory", "params": ["0x3", "latest", [0.5]], "id": 1, "jsonrpc": "2.0" }'
curl --request POST --url http://139.177.181.61:8545 \
     --header 'content-type: application/json' \
     --data '{ "method": "eth_gasPrices", "id": 1, "jsonrpc": "2.0" }'

Presentation

image.png

Select a repo