nautechsystems/nautilus_trader · error

Missing gas used

Error message

Missing gas used

What it means

transform_hypersync_block converts a HyperSync block into the internal Block type and requires gas_used to be present. HyperSync returns block fields as optional hex-encoded values; when the API response omits gas_used (None), the code short-circuits with this anyhow error. It guards against constructing a Block with incomplete data rather than defaulting silently.

Source

Thrown at crates/adapters/blockchain/src/hypersync/transform.rs:44

/// Returns an error if required block fields are missing or if hex parsing fails.
pub fn transform_hypersync_block(
    chain: Blockchain,
    received_block: hypersync_client::simple_types::Block,
) -> Result<Block, anyhow::Error> {
    let number = received_block
        .number
        .ok_or_else(|| anyhow::anyhow!("Missing block number"))?;
    let gas_limit = from_str_hex_to_u64(
        received_block
            .gas_limit
            .ok_or_else(|| anyhow::anyhow!("Missing gas limit"))?
            .encode_hex()
            .as_str(),
    )?;
    let gas_used = from_str_hex_to_u64(
        received_block
            .gas_used
            .ok_or_else(|| anyhow::anyhow!("Missing gas used"))?
            .encode_hex()
            .as_str(),
    )?;
    let timestamp = from_str_hex_to_u64(
        received_block
            .timestamp
            .ok_or_else(|| anyhow::anyhow!("Missing timestamp"))?
            .encode_hex()
            .as_str(),
    )?;

    let mut block = Block::new(
        received_block
            .hash
            .ok_or_else(|| anyhow::anyhow!("Missing hash"))?
            .to_string(),
        received_block
            .parent_hash

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Ensure the HyperSync query's field selection includes gas_used so it is returned for every block.
  2. Verify the chain actually exposes gas_used (some non-EVM chains do not); skip or handle such chains before transforming.
  3. If the field is legitimately optional for your use case, change the call site to provide a default (e.g. .unwrap_or_default()) instead of failing.
  4. Check the hypersync-client version matches the expected schema where gas_used is populated.

Example fix

// before
let gas_used = from_str_hex_to_u64(
    received_block.gas_used.ok_or_else(|| anyhow::anyhow!("Missing gas used"))?.encode_hex().as_str(),
)?;
// after (if optional for your chain)
let gas_used = received_block
    .gas_used
    .map(|g| from_str_hex_to_u64(g.encode_hex().as_str()))
    .transpose()?
    .unwrap_or(0);
Defensive patterns

Strategy: validation

Validate before calling

fn block_has_gas_used(b: &hypersync_client::simple_types::Block) -> bool {
    b.gas_used.is_some()
}
// call only if block_has_gas_used(&received_block)

Type guard

fn has_gas_used(b: &hypersync_client::simple_types::Block) -> bool {
    matches!(b.gas_used, Some(_))
}

Try / catch

match transform_hypersync_block(chain, block) {
    Ok(b) => process(b),
    Err(e) if e.to_string().contains("Missing gas used") => {
        tracing::warn!(block = ?block.number, "skipping block without gas_used");
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Calling pool_events_from_response (which calls transform_hypersync_block) when the HyperSync query response contains a block whose gas_used field is None — e.g. the block query did not request the gas_used column, or HyperSync returned a partial/placeholder block for a chain that does not report gas usage.

Common situations: Querying HyperSync with a projection that excludes gas_used; using a chain or HyperSync schema version where gas_used is not populated for pending/reorged blocks; deserializing a hand-built or stub Block in tests.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/936cc07c691493c5. Report an issue: GitHub.