Skip to content

Conversation

@Savid
Copy link
Member

@Savid Savid commented Dec 18, 2025

Add a new gas_used field that computes the actual gas consumed by each opcode using the difference between consecutive gas values at the same depth level. This provides accurate gas accounting that differs from the pre-calculated gas_cost in cases like:

  • CALL/CREATE opcodes (includes child execution gas)
  • Dynamic gas costs (memory expansion, cold/warm storage access)
  • Last opcodes in call contexts (keeps pre-calculated cost)

The gas_cost field is preserved unchanged for backwards compatibility.

New files:

  • gas_cost.go: ComputeGasUsed() depth-tracking algorithm
  • gas_cost_test.go: Comprehensive test coverage

Schema migration required:
ALTER TABLE structlog ADD COLUMN gas_used UInt64 AFTER gas_cost;

Add a new gas_used field that computes the actual gas consumed by each
opcode using the difference between consecutive gas values at the same
depth level. This provides accurate gas accounting that differs from
the pre-calculated gas_cost in cases like:

- CALL/CREATE opcodes (includes child execution gas)
- Dynamic gas costs (memory expansion, cold/warm storage access)
- Last opcodes in call contexts (keeps pre-calculated cost)

The gas_cost field is preserved unchanged for backwards compatibility.

Also fix transaction return value handling to convert "0x" (empty hex)
to nil for proper nullable storage.

New files:
- gas_cost.go: ComputeGasUsed() depth-tracking algorithm
- gas_cost_test.go: Comprehensive test coverage

Schema migration required:
ALTER TABLE structlog ADD COLUMN gas_used UInt64 AFTER gas_cost;
@Savid Savid force-pushed the feature/compute-actual-gas-used branch from 7561c0a to 1b8c454 Compare December 19, 2025 00:16
@Savid Savid merged commit c4bf29a into master Dec 19, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants