Skip to content

refactor: use the built-in max/min to simplify the code#1672

Merged
MicBun merged 3 commits intotrufnetwork:mainfrom
nuxtreact:main
Mar 12, 2026
Merged

refactor: use the built-in max/min to simplify the code#1672
MicBun merged 3 commits intotrufnetwork:mainfrom
nuxtreact:main

Conversation

@nuxtreact
Copy link
Copy Markdown
Contributor

@nuxtreact nuxtreact commented Feb 12, 2026

Description

In Go 1.21, the standard library includes built-in max/min function, which can greatly simplify the code.

Related Issue

Motivation and Context

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update (including inline docs)
  • Other (please describe):

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Checklist Explanation:

How to Review this PR:

Additional Information:

Summary by CodeRabbit

  • Refactor
    • Simplified internal clamping and backoff calculations across several modules (using concise min-based expressions).
    • No functional changes to behavior or public interfaces; runtime behavior and exposed APIs remain unchanged.

Signed-off-by: nuxtreact <nuxtreact@outlook.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 12, 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: 90522e43-b14a-4524-afbc-1c3a92642b2a

📥 Commits

Reviewing files that changed from the base of the PR and between 4337eb3 and d11f289.

📒 Files selected for processing (2)
  • node/exts/erc20-bridge/erc20/meta_extension.go
  • node/exts/evm-sync/instance.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • node/exts/evm-sync/instance.go

📝 Walkthrough

Walkthrough

Consolidates conditional clamping into single min() expressions across multiple modules: block range calculations, scale computation, and exponential backoff delay updates. No exported APIs or behavioral changes introduced; only internal control-flow expressions were simplified.

Changes

Cohort / File(s) Summary
EVM Sync
node/exts/evm-sync/instance.go, node/exts/evm-sync/instance_test.go, node/exts/evm-sync/listener.go
Replaced explicit if-based clamping with min() for block boundary calculation and exponential backoff delay updates (condensed multiply-then-clamp into a single min() expression).
ERC20 Bridge
node/exts/erc20-bridge/erc20/meta_extension.go
Simplified scaleDownUint256 by capping scale via min(n.Scale(), decimals) instead of manual conditional cap; downstream precision calls unchanged.
ETH Deposits
extensions/listeners/eth_deposits/deposits.go
Replaced two-step toBlock adjustment with toBlock = min(lastHeight + BlockSyncChunkSize, currentHeight - RequiredConfirmations).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble on branches, tidy each line,
A tiny min() makes the boundaries fine,
Fewer forks to ponder, fewer paths to trace,
My hops leave the logic neat in their place,
Hop, commit, and celebrate—code in a calmer space ✨

🚥 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 accurately describes the main change: replacing custom max/min implementations with Go's built-in functions to simplify code across multiple files.
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
📝 Coding Plan for PR comments
  • Generate coding plan

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.

@MicBun MicBun self-requested a review February 18, 2026 20:58
@holdex
Copy link
Copy Markdown

holdex Bot commented Feb 18, 2026

Time Submission Status

Member Status Time Action Last Update
@nuxtreact ❌ Missing - ⚠️ Submit time -
MicBun ✅ Submitted 15min Update time Mar 12, 2026, 1:28 PM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

Copy link
Copy Markdown
Collaborator

@MicBun MicBun left a comment

Choose a reason for hiding this comment

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

lgtm

@MicBun MicBun merged commit e0a99e0 into trufnetwork:main Mar 12, 2026
4 of 5 checks passed
@MicBun
Copy link
Copy Markdown
Collaborator

MicBun commented Mar 16, 2026

hi @nuxtreact, sorry for the late merge and the late reply, thank you for the contribution!

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.

2 participants