Skip to content

chore: charge the write fee on every wallet without exception#1402

Merged
MicBun merged 1 commit into
mainfrom
chore/universal-write-fee
Jul 3, 2026
Merged

chore: charge the write fee on every wallet without exception#1402
MicBun merged 1 commit into
mainfrom
chore/universal-write-fee

Conversation

@MicBun

@MicBun MicBun commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

resolves: https://github.com/truflation/website/issues/4203
resolves: https://github.com/truflation/website/issues/3808

What changes

The per-transaction write fee is now charged on every wallet — the system:fee_required phased-rollout whitelist is gone. During the phased rollout only wallets enrolled in that role were charged, so write wallets could be funded one at a time before switching everyone to universal charging. That rollout is complete, so the gate is removed:

  • insert_records (003) and insert_taxonomy (004) now charge the flat 1 TRUF unconditionally — matching create_streams (001), which already charged universally.
  • truflation_insert_records (009) now charges the same flat 1 TRUF (previously it was fee-free). 009 is registered as a fee target in scripts/generate_prod_migrations.py, so its new 009-truflation-query.prod.sql mainnet override routes the fee through eth_truf.
  • The system:fee_required role bootstrap migration (047) is removed from the embedded seed. The role is now inert (nothing reads it); the one-off mainnet drop lives in maintenance/ and is applied manually.

The dev *.sql sources were edited and the *.prod.sql overrides regenerated via the existing generator (hoodi_tteth_truf); only the 003/004/009 prod files change.

Tests

  • insert_records_fee_test.go / taxonomy_fee_test.go: removed the role-enrollment setup; inverted the previous "un-enrolled writes free" cases to assert universal charging.
  • transaction_events_ledger_test.go: fees now fire without enrollment.
  • maa/data_agent_test.go: reworked so each agent insert is charged from the wallet's escrow.
  • truflation_insert_fee_test.go (new): asserts truflation_insert_records charges a flat 1 TRUF per transaction and reverts on insufficient balance.
  • utils/setup/primitive.go: the shared truflation-insert helper now funds the provider for the fee.

Full suites pass: roles, truflation, the insert/taxonomy/ledger fee suites, and all MAA tests.

Rollout notes (consensus-critical)

  1. Apply the regenerated 003/004/009 *.prod.sql overrides via kwil-cli exec-sql (after erc20-bridge/000-extension.prod.sql, so eth_truf exists) — the same path as the existing 003/004 overrides.
  2. Before applying, confirm every active write wallet holds enough TRUF to pay the fee: once the overrides are live there is no longer any way to exempt a wallet, and an unfunded provider's writes will revert.
  3. Drop the now-inert role on mainnet at any time afterward with the manual maintenance/050-drop-fee-required-role.sql (behavioural no-op — the actions no longer read the role).

Summary by CodeRabbit

  • New Features
    • Added support for batched Truflation record inserts with consistent fee handling.
  • Bug Fixes
    • Write actions now charge a flat 1 TRUF fee for every caller, without relying on prior enrollment.
    • Failed inserts now clearly enforce balance checks before charging.
    • Fee records and leader payouts are now applied consistently across insert and taxonomy actions.
  • Documentation
    • Updated agent guidance to match the new fee behavior.

@holdex

holdex Bot commented Jul 2, 2026

Copy link
Copy Markdown

Time Submission Status

Member # Time Running Total Status Last Update
MicBun 4h ✅ Submitted Jul 2, 2026, 4:59 PM

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 commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR removes the phased, role-gated (system:fee_required) write-fee model for insert_records and insert_taxonomy, replacing it with universal flat 1 TRUF fee charging for every caller. It adds a new truflation_insert_records public action with the same fee model, updates the prod migration generator, deletes the obsolete role-bootstrap migration, and revises tests and docs accordingly.

Changes

Universal fee charging migration

Layer / File(s) Summary
insert_records universal fee logic and tests
internal/migrations/003-primitive-insertion.sql, internal/migrations/003-primitive-insertion.prod.sql, tests/streams/insert_records_fee_test.go
Fee collection is unconditional: fixed 1 TRUF fee, required @leader_sender, balance check, transfer to leader; role-gated $fee_required logic removed. Tests drop fee_required role enrollment and replace the "unenrolled writes free" test with one asserting unenrolled wallets are still charged.
insert_taxonomy universal fee logic and tests
internal/migrations/004-composed-taxonomy.sql, internal/migrations/004-composed-taxonomy.prod.sql, tests/streams/taxonomy_fee_test.go
Same universal flat-fee change applied to insert_taxonomy; tests remove role enrollment steps and add a regression test confirming unenrolled wallets still pay the fee.
Modular agent lifecycle and ledger test updates
tests/streams/maa/data_agent_test.go, tests/streams/transaction_events_ledger_test.go, docs/modular-agent-addresses.md
Data agent lifecycle test updated so both insert_records calls charge fees immediately with revised balance expectations; ledger test removes role enrollment; docs drop the enrollment-dependent fee note.
New truflation_insert_records action and tests
internal/migrations/009-truflation-query.sql, internal/migrations/009-truflation-query.prod.sql, scripts/generate_prod_migrations.py, tests/streams/truflation_insert_fee_test.go, tests/streams/utils/setup/primitive.go
Adds a new public action performing batch validation, insertion, and flat per-transaction fee charging; registers it in the prod migration generator; adds tests for flat-fee and insufficient-balance scenarios plus a pre-funding helper update. Also removes the obsolete 047-fee-required-role.sql role-bootstrap migration.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Action as insert_records / insert_taxonomy / truflation_insert_records
    participant Ledger as eth_truf balance
    participant Leader as leader_sender

    Caller->>Action: invoke action
    Action->>Action: set total_fee = 1 TRUF
    Action->>Leader: require `@leader_sender` present
    Action->>Ledger: check caller balance >= total_fee
    alt insufficient balance
        Action-->>Caller: error "Insufficient balance for write fee"
    else sufficient balance
        Action->>Ledger: transfer fee to leader
        Action->>Action: set fee_total / fee_recipient
        Action->>Action: perform insert/validation logic
        Action->>Action: record_transaction_event(fee_total, fee_recipient)
        Action-->>Caller: success
    end
Loading

Possibly related PRs

  • trufnetwork/node#1371: Both PRs remove write-fee whitelisting/role-gating for insert_records and insert_taxonomy, making them charge all callers universally.
  • trufnetwork/node#1382: Both PRs directly modify the same insert_records/insert_taxonomy fee-gating logic introduced/changed by that prior PR.
  • trufnetwork/node#1372: Both PRs modify the same fee-collection code paths in 003-primitive-insertion.sql and 004-composed-taxonomy.sql, one changing timing/gating and the other the transfer backend.

Suggested labels: type: chore

Suggested reviewers: outerlook, williamrusdyputra

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: universal write-fee charging for all wallets.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/universal-write-fee

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.

@MicBun MicBun self-assigned this Jul 2, 2026
@MicBun MicBun changed the title Charge the write fee on every wallet without exception feat: charge the write fee on every wallet without exception Jul 2, 2026
@MicBun

MicBun commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@holdex pr submit-time 4h

@MicBun MicBun changed the title feat: charge the write fee on every wallet without exception chore: charge the write fee on every wallet without exception Jul 2, 2026
@MicBun MicBun requested a review from vinarmani July 3, 2026 07:08
@MicBun MicBun merged commit 1efd883 into main Jul 3, 2026
8 of 11 checks passed
@MicBun MicBun deleted the chore/universal-write-fee branch July 3, 2026 07:09
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