matter-labs / era-test-node

In-memory node that can be used for integration testing and debugging.
https://matter-labs.github.io/era-test-node
Apache License 2.0
311 stars 75 forks source link

hardhat_api: Implement `hardhat_setNextBlockBaseFeePerGas` method #150

Open dutterbutter opened 10 months ago

dutterbutter commented 10 months ago

Description:

The hardhat_setNextBlockBaseFeePerGas endpoint needs to be implemented. This endpoint is designed to set the base fee for the next block. Refer to the Hardhat documentation for more details. Test implementations can be derived from the Hardhat repo here.

// Interface in the `trait`
#[rpc(name = "hardhat_setNextBlockBaseFeePerGas")]
fn set_next_block_base_fee_per_gas(&self, base_fee_per_gas: U256) -> BoxFuture<Result<bool>>;

// Actual code in the `impl`
fn set_next_block_base_fee_per_gas(&self, base_fee_per_gas: U256) -> BoxFuture<Result<bool>> {
    // TODO: Solution here
}

JS implementation:

/**
 * Sets the base fee of the next block.
 *
 * @param baseFeePerGas The new base fee to use.
 */
export async function setNextBlockBaseFeePerGas(baseFeePerGas: NumberLike): Promise<void> {
  const provider = await getHardhatProvider();

  const baseFeePerGasHex = toRpcQuantity(baseFeePerGas);

  await provider.request({
    method: "hardhat_setNextBlockBaseFeePerGas",
    params: [baseFeePerGasHex],
  });
}

Expected response

Command to test the endpoint:

curl -X POST http://localhost:8011 \
     -H "Content-Type: application/json" \
     --data '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "hardhat_setNextBlockBaseFeePerGas",
       "params": ["0x2540be400"]
     }'

Response should be:

{"jsonrpc":"2.0", "result":true, "id":1}

Requirements:

  1. Implement the API:

    • The endpoint should return true if successful in setting the base fee for the next block, otherwise false.
    • Ensure the method executes the call reliably and efficiently.
    • Errors must be handled appropriately and returned accordingly.
  2. Unit Tests:

    • Compose unit tests to verify the setNextBlockBaseFeePerGas method functionality.
    • Ensure coverage for multiple edge-case scenarios.
  3. Documentation:

    • Append inline Rust documentation (/// comments) detailing the method's purpose, potential return values, and any significant edge cases or errors.
    • Update the documentation and examples in SUPPORTED_APIS.md.
    • Optionally, include this request in test_endpoints.http for more straightforward manual testing.

Task Checklist:

Additional Notes:

If you're an external contributor looking to take on this issue, please comment below to let us know you're working on it. If you need further clarification on the requirements or need assistance with anything related to the implementation, feel free to ask!

nbaztec commented 10 months ago

While working on this issue it came out that the bootloader would reject any transactions that have their enforced_base_fee parameter set to anything other than what it expects, which is currently 250_000_000.

image

For the implementation WIP, see https://github.com/Moonsong-Labs/era-test-node/tree/nish-fix-150-upstream