Skip to content

refactors the BlobPool  #31

@Dargon789

Description

@Dargon789

Reviewer's Guide

This PR refactors the BlobPool to drop its unused validation hook and centralizes gas-limit filtering, adds file-based trie journaling with safe atomic writes, extends EIP-4844 support to post-Osaka per EIP-7918, enforces new block-size and tx-gas caps (EIPs 7825, 7934), introduces the CLZ opcode and secp256r1 (P256VERIFY) precompile, and harmonizes GetBlockNumber/ReadHeaderNumber calls to a (uint64,bool) API across the chain reader and rawdb.

Class diagram for ChainConfig and BlobScheduleConfig fork extensions

classDiagram
    class ChainConfig {
        +*uint64 BPO1Time
        +*uint64 BPO2Time
        +*uint64 BPO3Time
        +*uint64 BPO4Time
        +*uint64 BPO5Time
        +IsBPO1(num *big.Int, time uint64) bool
        +IsBPO2(num *big.Int, time uint64) bool
        +IsBPO3(num *big.Int, time uint64) bool
        +IsBPO4(num *big.Int, time uint64) bool
        +IsBPO5(num *big.Int, time uint64) bool
    }
    class BlobScheduleConfig {
        +*BlobConfig BPO1
        +*BlobConfig BPO2
        +*BlobConfig BPO3
        +*BlobConfig BPO4
        +*BlobConfig BPO5
    }
    ChainConfig "1" -- "1" BlobScheduleConfig : BlobScheduleConfig
    BlobScheduleConfig "1" -- "0..1" BlobConfig : BPO1..BPO5
Loading

Class diagram for BlobTxSidecar and related changes

classDiagram
    class BlobTxSidecar {
        +byte Version
        +[]kzg4844.Blob Blobs
        +[]kzg4844.Commitment Commitments
        +[]kzg4844.Proof Proofs
        +Copy() *BlobTxSidecar
        +ToV1() error
        +CellProofsAt(idx int) ([]kzg4844.Proof, error)
        +NewBlobTxSidecar(version byte, blobs, commitments, proofs)
    }
    class BlobTx {
        +*BlobTxSidecar Sidecar
    }
    BlobTx "1" -- "0..1" BlobTxSidecar : Sidecar
Loading

Class diagram for PendingFilter and gas limit cap

classDiagram
    class PendingFilter {
        +*uint256.Int MinTip
        +*uint256.Int BaseFee
        +*uint256.Int BlobFee
        +uint64 GasLimitCap
        +bool OnlyPlainTxs
        +bool OnlyBlobTxs
    }
Loading

Class diagram for environment and block size tracking (miner/worker.go)

classDiagram
    class environment {
        +uint64 size
        +txFitsSize(tx *types.Transaction) bool
    }
Loading

Class diagram for BlockChainConfig and trie journal directory

classDiagram
    class BlockChainConfig {
        +string TrieJournalDirectory
    }
Loading

Class diagram for triedb.Config and journal directory

classDiagram
    class Config {
        +string JournalDirectory
    }
Loading

Class diagram for HeaderChain and GetBlockNumber API change

classDiagram
    class HeaderChain {
        +GetBlockNumber(hash common.Hash) (uint64, bool)
    }
Loading

Class diagram for rawdb.ReadHeaderNumber API change

classDiagram
    class rawdb {
        +ReadHeaderNumber(db ethdb.KeyValueReader, hash common.Hash) (uint64, bool)
    }
Loading

Class diagram for new precompile: p256Verify

classDiagram
    class p256Verify {
        +RequiredGas(input []byte) uint64
        +Run(input []byte) ([]byte, error)
    }
Loading

Class diagram for new opcode: CLZ (EIP-7939)

classDiagram
    class EVMInterpreter {
        +opCLZ(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error)
    }
Loading

Class diagram for params/protocol_params.go new constants

classDiagram
    class params {
        +const MaxTxGas uint64
        +const MaxBlockSize uint64
        +const P256VerifyGas uint64
        +const BlobBaseCost uint64
    }
Loading

File-Level Changes

Change Details Files
Remove unused txValidationFn and unify gas-limit capping in BlobPool
  • Dropped the txValidationFn field
  • Added GasLimitCap to PendingFilter and respect it in BlobPool.Pending
  • Removed test-only bypass in limbo code
core/txpool/blobpool/blobpool.go
core/txpool/subpool.go
Implement file-based trie DB journaling
  • New JournalDirectory config and journalPath() helper
  • loadJournal reads from file or rawdb, Journal writes to temp file + atomic rename
  • Added syncDir to fsync dirs, per-platform fileutils implementations
triedb/pathdb/journal.go
triedb/pathdb/fileutils_unix.go
triedb/pathdb/fileutils_windows.go
core/rawdb/database.go
Extend EIP-4844 for post-Osaka (EIP-7918)
  • CalcExcessBlobGas splits pre-/post-Osaka formula, uses reservePrice vs blobPrice
  • Extracted latestBlobConfig to drive target/max/UpdateFraction
  • Updated CalcBlobFee, MaxBlobsPerBlock, targetBlobsPerBlock to use latestBlobConfig
consensus/misc/eip4844/eip4844.go
consensus/misc/eip4844/eip4844_test.go
Refactor BlobTxSidecar API and test usage
  • Introduce NewBlobTxSidecar factory and Copy, ToV1, CellProofsAt methods
  • Replace inline sidecar literals with NewBlobTxSidecar in tests and code
  • Propagate BlobSidecarVersion constants and error handling
core/types/tx_blob.go
cmd/devp2p/internal/ethtest/suite.go
eth/catalyst/api.go
core/types/tx_blob_test.go
Enforce block size and transaction gas caps
  • Track env.size in miner, add txFitsSize to cap blocks under MaxBlockSize
  • Add maxBlockSizeBufferZone constant and enforce in generateWork
  • BlockValidator and stateTransition check MaxBlockSize and MaxTxGas
miner/worker.go
core/block_validator.go
core/state_transition.go
params/protocol_params.go
Add CLZ opcode and P256VERIFY precompile
  • Implement opCLZ and enable via enable7939 in osakaInstructionSet
  • Add p256Verify precompile contract, hook into PrecompiledContractsOsaka
  • Include gas cost constant and tests/benchmarks
core/vm/instructions.go
core/vm/jump_table.go
core/vm/contracts.go
crypto/secp256r1/verifier.go
Standardize GetBlockNumber/ReadHeaderNumber to (uint64,bool)
  • Change signature across headerchain, blockchain_reader, rawdb accessors
  • Update callers in GetBody, GetBlockByHash/Number, Receipts, txindexer
  • Remove pointer-based branches in favor of bool flag
core/headerchain.go
core/blockchain_reader.go
core/rawdb/accessors_chain.go
core/rawdb/accessors_body.go
core/txindexer.go

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Originally posted by @sourcery-ai[bot] in #30 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingdependenciesPull requests that update a dependency filedocumentationImprovements or additions to documentationduplicateThis issue or pull request already existsenhancementNew feature or requestgoPull requests that update go codegood first issueGood for newcomersinvalidThis doesn't seem rightquestionFurther information is requestedwontfixThis will not be worked on

Projects

Status

Backlog

Status

Todo

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions