{"record":{"id":"936cc07c691493c5","repo":"nautechsystems/nautilus_trader","slug":"missing-gas-used","errorCode":null,"errorMessage":"Missing gas used","messagePattern":"Missing gas used","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/hypersync/transform.rs","lineNumber":44,"sourceCode":"/// Returns an error if required block fields are missing or if hex parsing fails.\npub fn transform_hypersync_block(\n    chain: Blockchain,\n    received_block: hypersync_client::simple_types::Block,\n) -> Result<Block, anyhow::Error> {\n    let number = received_block\n        .number\n        .ok_or_else(|| anyhow::anyhow!(\"Missing block number\"))?;\n    let gas_limit = from_str_hex_to_u64(\n        received_block\n            .gas_limit\n            .ok_or_else(|| anyhow::anyhow!(\"Missing gas limit\"))?\n            .encode_hex()\n            .as_str(),\n    )?;\n    let gas_used = from_str_hex_to_u64(\n        received_block\n            .gas_used\n            .ok_or_else(|| anyhow::anyhow!(\"Missing gas used\"))?\n            .encode_hex()\n            .as_str(),\n    )?;\n    let timestamp = from_str_hex_to_u64(\n        received_block\n            .timestamp\n            .ok_or_else(|| anyhow::anyhow!(\"Missing timestamp\"))?\n            .encode_hex()\n            .as_str(),\n    )?;\n\n    let mut block = Block::new(\n        received_block\n            .hash\n            .ok_or_else(|| anyhow::anyhow!(\"Missing hash\"))?\n            .to_string(),\n        received_block\n            .parent_hash","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/hypersync/transform.rs#L26-L62","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the HyperSync query's field selection includes gas_used so it is returned for every block.","Verify the chain actually exposes gas_used (some non-EVM chains do not); skip or handle such chains before transforming.","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.","Check the hypersync-client version matches the expected schema where gas_used is populated."],"exampleFix":"// before\nlet gas_used = from_str_hex_to_u64(\n    received_block.gas_used.ok_or_else(|| anyhow::anyhow!(\"Missing gas used\"))?.encode_hex().as_str(),\n)?;\n// after (if optional for your chain)\nlet gas_used = received_block\n    .gas_used\n    .map(|g| from_str_hex_to_u64(g.encode_hex().as_str()))\n    .transpose()?\n    .unwrap_or(0);","handlingStrategy":"validation","validationCode":"fn block_has_gas_used(b: &hypersync_client::simple_types::Block) -> bool {\n    b.gas_used.is_some()\n}\n// call only if block_has_gas_used(&received_block)","typeGuard":"fn has_gas_used(b: &hypersync_client::simple_types::Block) -> bool {\n    matches!(b.gas_used, Some(_))\n}","tryCatchPattern":"match transform_hypersync_block(chain, block) {\n    Ok(b) => process(b),\n    Err(e) if e.to_string().contains(\"Missing gas used\") => {\n        tracing::warn!(block = ?block.number, \"skipping block without gas_used\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always select gas_used in HyperSync block queries.","Validate block completeness before transforming.","Decide per chain whether gas_used is guaranteed and document it."],"tags":["blockchain","hypersync","missing-field","deserialization"],"backgroundTag":"missing-required-argument","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}