Skip to content

fix: swap mainnet/testnet chain IDs and enforce 0.01 Gwei min 1559 tip#8

Merged
maoaixiao1314 merged 5 commits intomainfrom
hetu-subnet
Dec 10, 2025
Merged

fix: swap mainnet/testnet chain IDs and enforce 0.01 Gwei min 1559 tip#8
maoaixiao1314 merged 5 commits intomainfrom
hetu-subnet

Conversation

@maoaixiao1314
Copy link
Contributor

@maoaixiao1314 maoaixiao1314 commented Dec 10, 2025

Summary

  • Corrects two chain-id constants that were accidentally swapped between
    mainnet and testnet.
  • Adds a 0.01 Gwei floor to the EIP-1559 tip cap to prevent MetaMask
    from falling back to legacy mode when base-fee is very low.

Changes

File Description
utils/utils.go Swap MainnetChainIDTestnetChainID values
rpc/backend/chain_info.go Introduce minTipCap = 10 000 000 wei in SuggestGasTipCap

Breaking Change

None. The new tip floor only applies when the computed maxDelta is
smaller than 0.01 Gwei, so existing clients are unaffected.

Test Plan

  • Local net starts successfully with correct chain IDs
  • MetaMask 1559 tx defaults to EIP-1559 on fresh localnet
  • make test-backend PASS

Summary by CodeRabbit

  • New Features

    • Added support for an additional custom EVM network ID
  • Chores

    • Updated fee market parameters and increased default gentx fees
    • Swapped mainnet/testnet network identifiers
    • Moved block gas limit application to occur after gentx collection
    • Strengthened minimum gas tip calculation to enforce EIP-1559 usage
  • Other

    • Disabled automatic start invocation in launch script; temp dir cleanup behavior adjusted

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 10, 2025

Walkthrough

Genesis/init script reorders max_gas application and updates feemarket and gentx fees; RPC gas tip cap gains a 10,000,000 wei lower bound; mainnet/testnet chain ID constants are swapped; TempDir no longer auto-removes; EVM chain-ID checks broadened to allow 560000, 560001, 560002, and 565000.

Changes

Cohort / File(s) Change Summary
Initialization & Genesis Configuration
init.sh
Moved max_gas setting to after gentx collection; updated feemarket params (base_fee_change_denominator -> 64, min_gas_price -> 100000.0); increased gentx fees to 20000000000ahetu; commented out final hetud start
RPC Gas Pricing
rpc/backend/chain_info.go
Added lower-bound clamp in SuggestGasTipCap: ensure min tip of 10,000,000 wei when computed delta is smaller
Temp dir & Chain ID constants
utils/utils.go
Swapped MainnetChainID ("hetu_560000") and TestnetChainID ("hetu_560001"); TempDir no longer defers removal of the created directory
EVM Chain ID Validation
x/evm/keeper/keeper.go, x/evm/types/access_list_tx.go, x/evm/types/dynamic_fee_tx.go, x/evm/types/legacy_tx.go
Replaced hard-coded equality checks with an allowlist loop validating chain IDs [560000, 560001, 560002, 565000]; updated error messages to list supported IDs

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify consistent allowlist implementation and identical error messages across all EVM files and keeper.
  • Confirm max_gas relocation correctly applies limits after gentx collection and doesn’t conflict with earlier initialization steps.
  • Review SuggestGasTipCap math to ensure the 10,000,000 wei clamp integrates safely with existing fee calculations.
  • Check TempDir lifecycle impact where callers previously relied on automatic cleanup.

Poem

🐇 I nibbled bytes beneath the moonlit code,

Four IDs hop in the ledger's road.
Tips now have a small, firm floor,
Genesis gates rearranged once more.
Hooray — a carrot for every node! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the two main changes in the PR: swapping mainnet/testnet chain IDs and enforcing a 0.01 Gwei minimum EIP-1559 tip, which directly align with the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hetu-subnet

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between af8f046 and fd39ccb.

📒 Files selected for processing (1)
  • utils/utils.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (2)
utils/utils.go (2)

109-116: Flag inconsistency: AI summary mentions TempDir change, but no modifications shown.

The AI summary states "Behavioral change: TempDir cleanup semantics no longer defer removal of the created directory," but the TempDir function shows no marked changes. If cleanup behavior was modified, please clarify whether this was intentional and document the rationale, as leaving temporary directories unreleased could lead to disk space accumulation over time.


38-40: Chain ID swap is correct—no breaking hardcoded references found.

The swap correctly updates MainnetChainID to "hetu_560000" and TestnetChainID to "hetu_560001". All code using these constants through IsMainnet() and IsTestnet() functions will work correctly with the updated values. Hardcoded chain ID references in test files and scripts (e.g., "hetu_560000-1", "hetu_560001-1") are intentional test fixtures and remain consistent with the swap. No conflicts detected across the codebase.


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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
utils/utils.go (1)

109-117: TempDir returns a directory that is immediately scheduled for deletion

TempDir defers os.RemoveAll(dir) before returning dir, so by the time the caller uses the path, the directory may already have been deleted (or will be deleted at the end of the function’s stack frame).

This is a correctness issue: any caller that expects to write into the returned temp directory will fail unpredictably.

Consider removing the defer os.RemoveAll(dir) and letting callers explicitly clean up, or returning a cleanup function alongside the path.

 func TempDir(defaultHome string) string {
   dir, err := os.MkdirTemp("", "hetu")
   if err != nil {
     dir = defaultHome
   }
-  defer os.RemoveAll(dir)
-
   return dir
 }
♻️ Duplicate comments (3)
x/evm/types/legacy_tx.go (1)

217-237: Chain ID validation matches dynamic-fee tx behavior

The allowlist for chain IDs and the loop-based validation are correct and consistent with DynamicFeeTx.Validate (supporting 560000, 560001, 560002, 565000 with a clear error message).

The duplication of this block across several files is already noted in the DynamicFeeTx review; consider centralizing the allowlist and predicate there to avoid drift.

x/evm/types/access_list_tx.go (1)

240-260: Access-list tx chain ID checks are aligned with the rest of the EVM stack

This allowlist (560000, 560001, 560002, 565000) and the membership loop are correct and consistent with the other transaction types and keeper logic.

As mentioned in the DynamicFeeTx review, you might want to centralize this allowlist / predicate to avoid having to edit multiple call sites when supported networks change.

x/evm/keeper/keeper.go (1)

144-162: Keeper’s chain ID enforcement is correct and consistent with tx validation

The WithChainID method now enforces the same supported set (560000, 560001, 560002, 565000) as the tx validators, panicking if the context’s chain ID falls outside this set. That’s a good guard to prevent running the EVM on unexpected networks.

As with the other sites, consider centralizing the supported chain ID list / predicate so this logic doesn’t need to be kept in sync manually across multiple files.

🧹 Nitpick comments (3)
x/evm/types/dynamic_fee_tx.go (1)

272-292: Chain ID allowlist logic is correct but duplicated across multiple files

The new loop-based validation over validChainIDs is functionally correct and matches the intended supported set (560000, 560001, 560002, 565000). However, the exact same allowlist and loop now appear in several places (dynamic fee, legacy, access list txs, and the keeper).

To avoid drift when adding/removing supported IDs, consider centralizing this into a shared helper (e.g. types.IsSupportedChainID(*big.Int)) or a shared []*big.Int constant, and call that from each validation site. This keeps the single source of truth for supported Hetu chain IDs.

rpc/backend/chain_info.go (1)

284-295: Min tip cap behavior matches intent; consider extracting a named constant

Clamping maxDelta to a minimum of 10_000_000 wei (0.01 Gwei) ensures SuggestGasTipCap never returns zero once EIP-1559 is active, which should help keep MetaMask in 1559 mode on very low base fees. The placement after the existing negative-guard is sensible.

For clarity and future reuse, consider:

  • Extracting this into a named constant, e.g. const minPriorityFeeWei int64 = 10_000_000, with a short doc comment about MetaMask behavior and units.
  • (Optional, longer-term) If you ever expect base fees that approach math.MaxInt64, consider rewriting maxDelta in terms of big.Int instead of Int64() to avoid potential overflow; this is a pre-existing pattern, but the clamp won’t fix it.
init.sh (1)

105-105: Script no longer auto-starts the node

With hetud start commented out, this script now only initializes and validates the genesis, then exits. That can be desirable for automation, but it’s a behavior change compared to an auto-starting init script.

If consumers previously relied on it to start the node, consider updating any docs or wrappers to explicitly start hetud after running this script.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c14217d and af8f046.

📒 Files selected for processing (7)
  • init.sh (3 hunks)
  • rpc/backend/chain_info.go (1 hunks)
  • utils/utils.go (1 hunks)
  • x/evm/keeper/keeper.go (1 hunks)
  • x/evm/types/access_list_tx.go (1 hunks)
  • x/evm/types/dynamic_fee_tx.go (1 hunks)
  • x/evm/types/legacy_tx.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
x/evm/types/legacy_tx.go (1)
types/errors.go (1)
  • ErrInvalidChainID (27-27)
x/evm/types/dynamic_fee_tx.go (1)
types/errors.go (1)
  • ErrInvalidChainID (27-27)
x/evm/types/access_list_tx.go (1)
types/errors.go (1)
  • ErrInvalidChainID (27-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build
🔇 Additional comments (3)
utils/utils.go (1)

38-40: Mainnet/Testnet chain ID strings now align with numeric IDs

Swapping MainnetChainID to "hetu_560000" and TestnetChainID to "hetu_560001" looks consistent with the EIP-155 numeric IDs used elsewhere (560000 mainnet, 560001 testnet). The IsMainnet/IsTestnet prefix checks will still work correctly with suffixed IDs like hetu_560000-1.

init.sh (2)

64-64: Feemarket min_gas_price and gentx fees are now consistent

min_gas_price is set to "100000.0" and the gentx uses --fees 20000000000ahetu --gas 200000, which yields an effective gas price of exactly 100000 ahetu/gas. That keeps the initial validator transaction in line with the fee market’s minimum and avoids startup failures due to underpriced gentx fees.

No functional issues here; just keep these two values in sync if you tune gas economics in the future.

Also applies to: 86-86


71-72: Setting consensus_params.block.max_gas after collect-gentxs is the right ordering

Commenting out the earlier max_gas mutation and applying it after hetud collect-gentxs avoids the genesis builder overwriting your block gas limit. The jq path and value ("10000000") are unchanged, just moved.

This ordering change is sound and should make the configured block gas limit stable across init runs.

Also applies to: 91-93

… default directory that should have been kept. After removing defer, the directory will be left for the caller to use, and cleaning needs to be handled by the caller themselves.
@maoaixiao1314 maoaixiao1314 merged commit ccbb969 into main Dec 10, 2025
4 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.

1 participant