Skip to content

refactor: extract gas buffer helpers into public custody functions#26

Open
maxpushka wants to merge 1 commit intolayer-3:masterfrom
maxpushka:feat/gas-price-estimation-buffer
Open

refactor: extract gas buffer helpers into public custody functions#26
maxpushka wants to merge 1 commit intolayer-3:masterfrom
maxpushka:feat/gas-price-estimation-buffer

Conversation

@maxpushka
Copy link
Contributor

@maxpushka maxpushka commented Mar 8, 2026

Summary by CodeRabbit

  • New Features

    • Added automatic gas buffering for Ethereum withdrawal transactions with 75% buffer applied to gas limit and 30% buffer applied to gas price.
  • Refactor

    • Consolidated gas buffer logic into a dedicated utility module, eliminating duplication across withdrawal operations for improved maintainability.

@coderabbitai
Copy link

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc1bd6a0-b332-40d1-bf10-a879dc4803c1

📥 Commits

Reviewing files that changed from the base of the PR and between b14002d and f6b8850.

📒 Files selected for processing (2)
  • custody/gas_buffer.go
  • service/service.go

📝 Walkthrough

Walkthrough

A new GasBuffer utility is introduced in the custody package with constants and functions for gas buffering Ethereum transactions. The service package is refactored to use these new custody utilities instead of maintaining its own gas buffering logic.

Changes

Cohort / File(s) Summary
Gas Buffer Utilities
custody/gas_buffer.go
New file adding gas buffering constants (75% for gas limit, 30% for price) and four public functions: ApplyGasPriceBuffer, StartWithdrawWithGasBuffer, FinalizeWithdrawWithGasBuffer, and RejectWithdrawWithGasBuffer. Each operation performs a dry-run, applies buffers, and executes the transaction.
Service Refactoring
service/service.go
Removed local gas buffer constant and replaced manual buffer logic in finalization and rejection functions with calls to custody.FinalizeWithdrawWithGasBuffer and custody.RejectWithdrawWithGasBuffer.

Sequence Diagram

sequenceDiagram
    actor Caller
    participant Service as Service
    participant Custody as Custody Package
    participant Contract as IWithdraw Contract
    participant EthBackend as Ethereum Backend
    
    Caller->>Service: Call withdraw operation
    Service->>Custody: Call buffered operation
    Custody->>Contract: Dry-run transaction (estimate gas)
    Contract->>EthBackend: Execute dry-run
    EthBackend-->>Contract: Gas estimation result
    Contract-->>Custody: Gas estimate returned
    Custody->>EthBackend: Fetch suggested gas price
    EthBackend-->>Custody: Gas price + apply buffers
    Custody->>Contract: Execute actual operation<br/>(with buffered gas limit & price)
    Contract->>EthBackend: Submit transaction
    EthBackend-->>Contract: Transaction confirmation
    Contract-->>Custody: Transaction result
    Custody-->>Service: Return transaction
    Service-->>Caller: Return result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Poem

🐰 Hop, hop, buffering flows,
Gas prices rise, our safety grows!
Custody guards with seventy-five,
Thirty percent keeps us all alive!
🌟 Sweet protection, transaction-wise.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'refactor: extract gas buffer helpers into public custody functions' accurately describes the main change: moving gas buffer logic from service.go into public functions in the custody package.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant