Skip to content

chore: name the bridge a transfer charged its fee in - #1410

Merged
MicBun merged 1 commit into
mainfrom
fee-event-bridge
Jul 29, 2026
Merged

chore: name the bridge a transfer charged its fee in#1410
MicBun merged 1 commit into
mainfrom
fee-event-bridge

Conversation

@MicBun

@MicBun MicBun commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

A peer-to-peer transfer records which bridge it charged its fee in, so the fee ledger describes its own token instead of leaving a reader to infer it.

Why

transaction_events carries no token column, and a transfer is the one method whose fee is not charged in $TRUF: it charges in the bridge it moves. eth_truf_transfer takes 1 TRUF at 1e18, eth_usdc_transfer takes 1 USDC at 1e6, and both are booked under the same method_id = 4. The mainnet migration already documents this — "fee is paid in the SAME bridge as the transfer (not always in TRUF)" — but nothing recorded which one.

A reader with only the ledger has to infer the token from the amount. That works while the two fees stay different constants and stops working the moment they do not, or a third bridge appears. One base unit differs between the two tokens by a factor of 1e12, so an inference that goes wrong is not a rounding matter.

What changes

record_transaction_event already takes a metadata argument, and every call site in the repo passes NULL. The transfer actions now pass the bridge instead:

  • eth_truf_transfer'{"bridge":"eth_truf"}'
  • eth_usdc_transfer'{"bridge":"eth_usdc"}'

metadata is TEXT holding a JSON object — 026-transaction-schemas.sql notes it would be JSONB if the engine supported it, and the ledger test helper already parses it as JSON — so the bridge is one key inside it rather than the whole value. It is empty on all 3,985,000+ existing mainnet rows, so nothing is displaced.

The four dev transfer actions get the same treatment for parity. Note these reach no deployed network on their own: scripts/migrate.sh globs ./internal/migrations/*.sql non-recursively, and the internal/migrations embed is imported only by tests, so erc20-bridge/*.sql is applied by hand exactly as the .prod.sql header describes.

Test

TestTransactionEventsLedger asserted a transfer carries no metadata, which is the behaviour being changed. It now asserts the bridge, so the stamp cannot be dropped silently.

Scope

No schema change, no new method id, no new migration file, and no change to any fee amount or recipient. Rolling back is re-applying the previous revision of the action.

Worth knowing for review: .prod.sql is excluded from the //go:embed and from go test, so no automated check parses or executes those two literals. They were verified by reading them back out of info.actions on the mainnet leader after the migration was applied.

Related

Summary by CodeRabbit

  • Bug Fixes

    • Improved ledger transfer records by identifying the originating bridge.
    • Ensured bridge-specific fees can be correctly attributed across supported token transfer actions.
  • Tests

    • Updated ledger event validation to confirm bridge metadata is included and correctly identified.

@MicBun MicBun self-assigned this Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@MicBun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cf0d7c44-ba58-4768-990c-a35b042cb517

📥 Commits

Reviewing files that changed from the base of the PR and between 501438c and e0cca26.

📒 Files selected for processing (3)
  • internal/migrations/erc20-bridge/002-public-transfer-actions.prod.sql
  • internal/migrations/erc20-bridge/002-public-transfer-actions.sql
  • tests/streams/transaction_events_ledger_test.go
📝 Walkthrough

Walkthrough

Public ERC20 bridge transfer actions now record their originating bridge in transaction-event metadata. The ledger test updates its expectation to validate the new bridge field for transfer events.

Changes

Bridge metadata attribution

Layer / File(s) Summary
Record bridge metadata
internal/migrations/erc20-bridge/002-public-transfer-actions*.sql
Public transfer actions now pass bridge-identifying JSON metadata to record_transaction_event; production comments document why the metadata is required.
Validate ledger metadata
tests/streams/transaction_events_ledger_test.go
The transfer ledger expectation now checks that metadata identifies sepolia_bridge.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • trufnetwork/node#1245: Introduced the internal transfer fee in the same bridge transfer actions later updated with bridge metadata.

Suggested labels: type: fix

Suggested reviewers: pr-time-tracker

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: recording which bridge charged each transfer fee in event metadata.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fee-event-bridge

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.

@holdex

holdex Bot commented Jul 29, 2026

Copy link
Copy Markdown

Time Submission Status

Member # Time Running Total Status Last Update
MicBun 2h ✅ Submitted Jul 29, 2026, 5:52 AM

Submit or update total time with:

@holdex pr submit-time 2h

Add time on top of previous submission with:

@holdex pr add-time 1h30m

See available commands to help comply with our Guidelines.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/streams/transaction_events_ledger_test.go (1)

277-285: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Cover all updated transfer actions.

This test exercises only sepolia_transfer, so changes to ethereum_transfer, hoodi_tt_transfer, hoodi_tt2_transfer, eth_truf_transfer, and eth_usdc_transfer could regress without detection. Add focused or parameterized cases asserting the expected bridge for each action.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/streams/transaction_events_ledger_test.go` around lines 277 - 285,
Extend the transfer-event metadata tests around the existing sepolia_transfer
case to cover ethereum_transfer, hoodi_tt_transfer, hoodi_tt2_transfer,
eth_truf_transfer, and eth_usdc_transfer. Add focused or table-driven cases that
assert each action’s expected bridge via the existing meta.String("bridge")
check, preserving the current sepolia_bridge assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/streams/transaction_events_ledger_test.go`:
- Around line 277-285: Extend the transfer-event metadata tests around the
existing sepolia_transfer case to cover ethereum_transfer, hoodi_tt_transfer,
hoodi_tt2_transfer, eth_truf_transfer, and eth_usdc_transfer. Add focused or
table-driven cases that assert each action’s expected bridge via the existing
meta.String("bridge") check, preserving the current sepolia_bridge assertion.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 26065d74-b73b-4277-9e33-0118a3f5e117

📥 Commits

Reviewing files that changed from the base of the PR and between 6ba0ff7 and 501438c.

📒 Files selected for processing (3)
  • internal/migrations/erc20-bridge/002-public-transfer-actions.prod.sql
  • internal/migrations/erc20-bridge/002-public-transfer-actions.sql
  • tests/streams/transaction_events_ledger_test.go

@MicBun

MicBun commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

@holdex pr submit-time 2h

@MicBun
MicBun force-pushed the fee-event-bridge branch from 501438c to e0cca26 Compare July 29, 2026 05:55
@MicBun
MicBun merged commit 6328d0d into main Jul 29, 2026
7 checks passed
@MicBun
MicBun deleted the fee-event-bridge branch July 29, 2026 05:57
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