Skip to content

chore: adjust create_streams fee to 1 TRUF per transaction#1373

Merged
MicBun merged 2 commits into
mainfrom
changeFee1
May 12, 2026
Merged

chore: adjust create_streams fee to 1 TRUF per transaction#1373
MicBun merged 2 commits into
mainfrom
changeFee1

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented May 12, 2026

resolves: https://github.com/truflation/website/issues/3805

Summary by CodeRabbit

  • Fee Changes
    • Stream creation now costs a flat 1 TRUF per transaction, regardless of batch size. Previously charged 6 TRUF per individual stream.

Review Change Stack

@MicBun MicBun requested a review from pr-time-tracker May 12, 2026 09:04
@MicBun MicBun self-assigned this May 12, 2026
@holdex
Copy link
Copy Markdown

holdex Bot commented May 12, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 3h Update time May 12, 2026, 4:13 PM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16cda207-a965-432b-8676-a9fcd30c6b29

📥 Commits

Reviewing files that changed from the base of the PR and between e7179db and 321985f.

📒 Files selected for processing (13)
  • internal/migrations/001-common-actions.prod.sql
  • internal/migrations/001-common-actions.sql
  • tests/streams/allow_zeros_test.go
  • tests/streams/attestation/request_attestation_fee_test.go
  • tests/streams/attestation/test_helpers.go
  • tests/streams/primitive_batch_insert_alignment_test.go
  • tests/streams/roles/permission_gates_test.go
  • tests/streams/stream_creation_fee_test.go
  • tests/streams/utils/feefund/feefund_default.go
  • tests/streams/utils/feefund/feefund_kwiltest.go
  • tests/streams/utils/procedure/execute.go
  • tests/streams/utils/setup/common.go
  • tests/streams/utils/setup/primitive.go

📝 Walkthrough

Walkthrough

This PR consolidates the write-fee model across three stream actions (create_streams, insert_records, insert_taxonomy) from per-item pricing to a flat 1 TRUF per transaction. Migration SQL, test fee constants, funding helpers, and all affected test assertions are updated; test configurations migrate to the hoodi/hoodi_tt bridge.

Changes

Flat per-transaction write fee

Layer / File(s) Summary
Fee constant definitions
tests/streams/utils/feefund/feefund_default.go, tests/streams/utils/feefund/feefund_kwiltest.go
Export WriteFeeWei (1 TRUF flat per-transaction fee) in both build configurations, replacing prior per-stream fee constant.
Migration SQL fee collection
internal/migrations/001-common-actions.sql, internal/migrations/001-common-actions.prod.sql
Update create_streams fee logic to compute $total_fee as flat 1 TRUF independent of stream count; simplify insufficient-balance error to always report "Required: 1 TRUF".
Test infrastructure and utilities
tests/streams/utils/setup/common.go, tests/streams/utils/setup/primitive.go, tests/streams/utils/procedure/execute.go
Introduce fundForInsertCalls helper; refactor wallet funding throughout to use flat WriteFeeWei multiplied by planned call count instead of per-item calculations; remove math/big where no longer needed.
Stream creation fee test assertions
tests/streams/stream_creation_fee_test.go, tests/streams/allow_zeros_test.go
Update test configuration to hoodi/hoodi_tt; replace sixTRUF constant with oneTRUF from WriteFeeWei; revise all balance assertions to expect exactly 1 TRUF deduction per create_streams call regardless of role or batch size; verify insufficient-balance error with 0.5 TRUF funding.
Attestation fee test and bridge configuration
tests/streams/attestation/request_attestation_fee_test.go, tests/streams/attestation/test_helpers.go
Migrate test chain/escrow constants from sepolia to hoodi/hoodi_tt; expand documentation to specify ERC20 instance alignment for fee ledger operations.
Integration and batch alignment tests
tests/streams/primitive_batch_insert_alignment_test.go, tests/streams/roles/permission_gates_test.go
Update batch insert fee funding to use WriteFeeWei for per-record constant; refine permission-gates documentation to clarify universal 1 TRUF per transaction semantics independent of network_writer role.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • trufnetwork/node#1372: Modifies create_streams balance/transfer calls to hoodi_tt alongside fee policy updates.
  • trufnetwork/node#1246: Prior fee-logic changes to create_streams in migration SQL.
  • trufnetwork/node#1368: Related fee-collection updates for create_streams, insert_records, and insert_taxonomy with different pricing semantics.

Suggested reviewers

  • pr-time-tracker
  • williamrusdyputra

🐰 Fee flatness brings peace of mind,
One TRUF per call, a cleaner design,
Per-stream and per-child are gone with the tide,
Batch writes now free from the math's heavy stride!

🚥 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 clearly and accurately summarizes the main change: adjusting data provision fees from per-stream/per-record pricing to a flat 1 TRUF per transaction across multiple fee-related files and tests.
Docstring Coverage ✅ Passed Docstring coverage is 86.84% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 changeFee1

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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
Copy Markdown

@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: 1

Caution

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

⚠️ Outside diff range comments (2)
internal/migrations/003-primitive-insertion.sql (1)

40-69: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Re-enable batch size limit before deploying flat-fee model.

Lines 42-45 show a commented-out batch size cap (if $num_records > 10) with a TODO stating it "MUST be re-enabled once ingestors are updated." The flat 1 TRUF fee (lines 66-69) now makes unbounded batches economically attractive: inserting 1000 records costs the same as inserting 1 record. This combination creates an immediate DoS risk.

The batch size limit must be re-enabled (or a new appropriate limit set) before this fee change is deployed. Otherwise, malicious or cost-optimizing users can submit arbitrarily large insert_records calls for 1 TRUF, exhausting node resources.

Also applies to: 79-79

🤖 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 `@internal/migrations/003-primitive-insertion.sql` around lines 40 - 69, The
batch-size cap for insert_records was commented out and must be re-enabled to
prevent DoS under the new flat-fee ($total_fee) model: restore the conditional
that checks $num_records (e.g., "if $num_records > 10") and ERROR with a clear
message (same style as existing checks), or choose a new safe limit instead of
10; ensure the check uses the same NULL-safe patterns as the other validations
(use IS DISTINCT FROM where needed) and apply the same re-enable at the other
occurrence referenced (around the later occurrence of $num_records) so all entry
points enforce the cap before proceeding to fee collection.
internal/migrations/004-composed-taxonomy.sql (1)

33-44: ⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Add an upper bound on the number of children to prevent resource exhaustion.

Similar to create_streams, the flat 1 TRUF fee incentivizes submitting taxonomies with very large child arrays. While line 43 ensures at least 1 child, there's no upper bound on $num_children. A taxonomy with hundreds of children now costs the same 1 TRUF as one with a single child, creating a potential resource exhaustion vector (the FOR loop at lines 81-114 processes each child sequentially, performing lookups and inserts).

Consider adding a maximum child count validation before the fee collection block.

Also applies to: 47-66

🤖 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 `@internal/migrations/004-composed-taxonomy.sql` around lines 33 - 44, Add a
strict upper bound check for the number of children to prevent resource
exhaustion: validate $num_children (the variable computed from
array_length($child_stream_ids)) is between 1 and a defined MAX_CHILDREN before
any fee collection or processing occurs (i.e., before the FOR loop and before
fee collection), and raise an ERROR if it exceeds the limit; introduce a clear
constant name like MAX_CHILDREN (choose an appropriate value consistent with
create_streams) and apply the same check for the other child-array validation
block that compares $child_stream_ids, $child_data_providers and $weights so all
paths enforce the cap.
🧹 Nitpick comments (2)
internal/migrations/003-primitive-insertion.prod.sql (1)

30-31: ⚡ Quick win

Update comment to reflect fee calculation no longer uses record count.

The comment states $num_records is "used for both fee calculation and validation," but after the flat-fee change, the fee calculation (line 62) no longer depends on record count—it's always 1 TRUF per transaction. The variable is now only used for validation (lines 43–56).

📝 Suggested comment fix
-    -- Get record count (used for both fee calculation and validation)
+    -- Get record count (used for validation)
     $num_records INT := array_length($data_provider);
🤖 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 `@internal/migrations/003-primitive-insertion.prod.sql` around lines 30 - 31,
The comment above the declaration of $num_records (initialized from
array_length($data_provider)) is outdated — update it to state that $num_records
is used only for validation (not fee calculation) since fees are now a flat 1
TRUF per transaction; locate the declaration of $num_records and change the
comment to reflect "used for validation only" or similar, removing the reference
to fee calculation.
tests/streams/insert_records_fee_test.go (1)

34-41: ⚡ Quick win

Use the shared write-fee constant here to avoid cross-test drift.

This file hardcodes 1 TRUF while sibling fee tests now read from feefund.WriteFeeWei. Reusing the shared constant keeps policy changes centralized and prevents silent divergence across suites.

Proposed patch
 import (
 	"context"
 	"fmt"
 	"math/big"
 	"strings"
 	"testing"
@@
 	testutils "github.com/trufnetwork/node/tests/streams/utils"
 	testerc20 "github.com/trufnetwork/node/tests/streams/utils/erc20"
+	"github.com/trufnetwork/node/tests/streams/utils/feefund"
 	"github.com/trufnetwork/node/tests/streams/utils/setup"
@@
-	// Flat 1 TRUF per insert_records transaction (issue `#3805`): one call
-	// charges the same fee regardless of how many records it carries.
-	insertFeeAmount = "1000000000000000000" // 1 TRUF with 18 decimals per tx
+	// Flat 1 TRUF per insert_records transaction (issue `#3805`): one call
+	// charges the same fee regardless of how many records it carries.
+	insertFeeAmount = feefund.WriteFeeWei
 )
🤖 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/insert_records_fee_test.go` around lines 34 - 41, Replace the
hardcoded "1 TRUF" fee with the shared feefund.WriteFeeWei value: remove or stop
using insertFeeAmount and instead call
mustParseInsertBigInt(feefund.WriteFeeWei.String() or feefund.WriteFeeWei if
already a string) when initializing oneTRUFInsert; ensure any place referencing
insertFeeAmount uses feefund.WriteFeeWei so the test reads the centralized
write-fee constant (symbols: insertFeeAmount, oneTRUFInsert,
mustParseInsertBigInt, feefund.WriteFeeWei).
🤖 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.

Inline comments:
In `@internal/migrations/001-common-actions.sql`:
- Line 57: Add an explicit batch-size guard in the create_streams procedure:
before the fee collection block and right after computing
array_length($stream_ids) (e.g., where $num_streams is derived), check if
$num_streams exceeds a shared MAX_BATCH_SIZE constant and raise an ERROR like
"create_streams: batch size exceeds maximum of [MAX_BATCH_SIZE] streams"; use
the same MAX_BATCH_SIZE value used by other batch operations (see pattern in
003-primitive-insertion.sql) to keep limits consistent and prevent resource
exhaustion during validation and writes.

---

Outside diff comments:
In `@internal/migrations/003-primitive-insertion.sql`:
- Around line 40-69: The batch-size cap for insert_records was commented out and
must be re-enabled to prevent DoS under the new flat-fee ($total_fee) model:
restore the conditional that checks $num_records (e.g., "if $num_records > 10")
and ERROR with a clear message (same style as existing checks), or choose a new
safe limit instead of 10; ensure the check uses the same NULL-safe patterns as
the other validations (use IS DISTINCT FROM where needed) and apply the same
re-enable at the other occurrence referenced (around the later occurrence of
$num_records) so all entry points enforce the cap before proceeding to fee
collection.

In `@internal/migrations/004-composed-taxonomy.sql`:
- Around line 33-44: Add a strict upper bound check for the number of children
to prevent resource exhaustion: validate $num_children (the variable computed
from array_length($child_stream_ids)) is between 1 and a defined MAX_CHILDREN
before any fee collection or processing occurs (i.e., before the FOR loop and
before fee collection), and raise an ERROR if it exceeds the limit; introduce a
clear constant name like MAX_CHILDREN (choose an appropriate value consistent
with create_streams) and apply the same check for the other child-array
validation block that compares $child_stream_ids, $child_data_providers and
$weights so all paths enforce the cap.

---

Nitpick comments:
In `@internal/migrations/003-primitive-insertion.prod.sql`:
- Around line 30-31: The comment above the declaration of $num_records
(initialized from array_length($data_provider)) is outdated — update it to state
that $num_records is used only for validation (not fee calculation) since fees
are now a flat 1 TRUF per transaction; locate the declaration of $num_records
and change the comment to reflect "used for validation only" or similar,
removing the reference to fee calculation.

In `@tests/streams/insert_records_fee_test.go`:
- Around line 34-41: Replace the hardcoded "1 TRUF" fee with the shared
feefund.WriteFeeWei value: remove or stop using insertFeeAmount and instead call
mustParseInsertBigInt(feefund.WriteFeeWei.String() or feefund.WriteFeeWei if
already a string) when initializing oneTRUFInsert; ensure any place referencing
insertFeeAmount uses feefund.WriteFeeWei so the test reads the centralized
write-fee constant (symbols: insertFeeAmount, oneTRUFInsert,
mustParseInsertBigInt, feefund.WriteFeeWei).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0ef5c7eb-c947-483e-af63-2b3f35a6e67a

📥 Commits

Reviewing files that changed from the base of the PR and between c0693b9 and e7179db.

📒 Files selected for processing (19)
  • extensions/tn_settlement/settlement_integration_test.go
  • internal/migrations/001-common-actions.prod.sql
  • internal/migrations/001-common-actions.sql
  • internal/migrations/003-primitive-insertion.prod.sql
  • internal/migrations/003-primitive-insertion.sql
  • internal/migrations/004-composed-taxonomy.prod.sql
  • internal/migrations/004-composed-taxonomy.sql
  • tests/streams/allow_zeros_test.go
  • tests/streams/insert_records_fee_test.go
  • tests/streams/primitive_batch_insert_alignment_test.go
  • tests/streams/roles/permission_gates_test.go
  • tests/streams/stream_creation_fee_test.go
  • tests/streams/taxonomy_fee_test.go
  • tests/streams/transaction_events_ledger_test.go
  • tests/streams/utils/feefund/feefund_default.go
  • tests/streams/utils/feefund/feefund_kwiltest.go
  • tests/streams/utils/procedure/execute.go
  • tests/streams/utils/setup/common.go
  • tests/streams/utils/setup/primitive.go

Comment thread internal/migrations/001-common-actions.sql
@MicBun
Copy link
Copy Markdown
Contributor Author

MicBun commented May 12, 2026

@holdex pr submit-time 3h

@MicBun MicBun merged commit 0645737 into main May 12, 2026
4 of 7 checks passed
@MicBun MicBun deleted the changeFee1 branch May 12, 2026 16:13
@MicBun MicBun changed the title chore: adjust data provision fee to 1 TRUF per transactions chore: adjust create_streams fee to 1 TRUF per transaction May 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant