Skip to content

chore: auto-register data provider on first stream creation#1385

Merged
MicBun merged 1 commit into
mainfrom
feat/permissionless-stream-creation
May 26, 2026
Merged

chore: auto-register data provider on first stream creation#1385
MicBun merged 1 commit into
mainfrom
feat/permissionless-stream-creation

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented May 26, 2026

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

Summary

  • Auto-create data_providers row when a wallet calls create_streams for the first time, removing the requirement for prior create_data_provider call or system:network_writer role grant
  • Uses INSERT ... ON CONFLICT (address) DO NOTHING — idempotent, matches existing pattern in helper_create_data_providers
  • Update taxonomy fee tests with correct funding amounts for 100 TRUF/stream pricing

Test plan

  • Both SQL files parse clean (kwil-cli utils parse)
  • TestStreamCreationFees — all 8 tests pass (7 existing + 1 new testPermissionlessOnboarding)
  • TestTaxonomyFees — all 5 tests pass with corrected funding amounts
  • Verify on devnet: fresh wallet with TRUF balance can call create_streams directly without prior registration

Summary by CodeRabbit

  • New Features

    • Data providers are now automatically registered when users create their first stream, streamlining the onboarding process.
  • Tests

    • Expanded test coverage for stream creation fees and flat per-transaction fee calculations.
    • Added validation for wallet onboarding scenarios and fee-charging mechanics during stream operations.

Review Change Stack

@holdex
Copy link
Copy Markdown

holdex Bot commented May 26, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time May 26, 2026, 4:59 AM

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 26, 2026

📝 Walkthrough

Walkthrough

Data providers are now auto-created when missing during stream creation via an upsert pattern. Both production and development migration versions implement permissionless onboarding. Stream and taxonomy fee tests are updated to reflect the new universal per-stream fee structure applied regardless of role.

Changes

Permissionless provider onboarding and fee updates

Layer / File(s) Summary
Permissionless onboarding in create_streams
internal/migrations/001-common-actions.prod.sql, internal/migrations/001-common-actions.sql
Both prod and dev versions replace the "must already exist" provider lookup with an upsert: insert a data_providers row using ON CONFLICT (address) DO NOTHING, then select the resulting data_provider_id for stream/metadata creation. The prior error-on-missing-provider flow is removed.
Stream creation fee test with auto-onboarding
tests/streams/stream_creation_fee_test.go
New test testPermissionlessOnboarding validates that a fresh wallet without pre-existing data provider registration can create streams; first stream triggers auto-registration, subsequent streams reuse the provider. Both operations correctly charge the per-stream fee.
Taxonomy fee test updates for new fee structure
tests/streams/taxonomy_fee_test.go
All five taxonomy fee tests are recalibrated to account for 100 TRUF per-stream creation fees applied universally. Funding amounts and balance assertions now include composed stream creation (100 TRUF) + child stream creation (100 TRUF each) + flat 1 TRUF taxonomy insertion (or zero when unenrolled). Tests cover writer-role enrollment, non-exempt wallets, insufficient balance, multi-child cases, and free insertion when unenrolled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • trufnetwork/node#1372: Modifies create_streams fee collection and transfer logic via hoodi_tt.
  • trufnetwork/node#1366: Related code-level changes to the create_streams action in both migration versions.
  • trufnetwork/node#1137: Implements similar auto-creation of missing data_providers records during grant_roles and via helper_create_data_providers.

Suggested labels

type: feat

Suggested reviewers

  • outerlook
  • williamrusdyputra

Poem

🐰 A wallet arrives at the gate with no proof,
But streams bloom unbidden—no prior rebuff.
Each genesis charges a tax, fair and bright,
While taxonomies stack in fees, day and night.
Permissionless pathways now open so wide! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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.
Title check ✅ Passed The PR title 'chore: auto-register data provider on first stream creation' accurately describes the main change: automatic data provider registration on first stream creation. The title is concise and clearly summarizes the primary feature addition.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 feat/permissionless-stream-creation

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 changed the title feat(streams): auto-register data provider on first stream creation feat: auto-register data provider on first stream creation May 26, 2026
@MicBun MicBun changed the title feat: auto-register data provider on first stream creation chore: auto-register data provider on first stream creation May 26, 2026
@MicBun MicBun self-assigned this May 26, 2026
@MicBun MicBun requested a review from pr-time-tracker May 26, 2026 04:44
@MicBun
Copy link
Copy Markdown
Contributor Author

MicBun commented May 26, 2026

@holdex pr submit-time 4h

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

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

390-410: ⚡ Quick win

Assert the onboarding side effect directly.

This proves both calls succeed and both fees are charged, but it never checks that the first call created exactly one data_providers row for the wallet and that the second call reused it. A small count query here would make the test validate the PR’s actual contract instead of inferring it from “no error”.

🤖 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/stream_creation_fee_test.go` around lines 390 - 410, The test
only infers data provider registration by balance changes; add an explicit
assertion that the data_providers row count for the wallet is exactly 1 after
the first create and remains 1 after the second create to verify the ON CONFLICT
reuse path. After calling createStream(...) the first time, run a count query
against the data_providers table (filter by the wallet address used in
createStream) and require it equals 1; after the second createStream(...) run
the same count and require it still equals 1. Use the same test helpers/DB
handle available in the test harness to perform these queries so the assertions
live alongside the existing getBalance(...) checks.
🤖 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`:
- Around line 145-153: The INSERT into data_providers uses COALESCE((SELECT
MAX(id) FROM data_providers), 0) + 1 for id while using ON CONFLICT (address) DO
NOTHING, which still allows primary-key collisions to abort create_streams;
switch id allocation to a collision-free mechanism (e.g., use the table
sequence/identity instead of MAX(id)+1). Concretely, update the schema to give
data_providers an IDENTITY/sequence or ensure a sequence like
data_providers_id_seq exists and change the INSERT in the data_providers
insertion block to use DEFAULT or nextval('data_providers_id_seq') for id,
keeping ON CONFLICT (address) DO NOTHING so address conflicts are safely ignored
and create_streams no longer fails due to PK collisions.

---

Nitpick comments:
In `@tests/streams/stream_creation_fee_test.go`:
- Around line 390-410: The test only infers data provider registration by
balance changes; add an explicit assertion that the data_providers row count for
the wallet is exactly 1 after the first create and remains 1 after the second
create to verify the ON CONFLICT reuse path. After calling createStream(...) the
first time, run a count query against the data_providers table (filter by the
wallet address used in createStream) and require it equals 1; after the second
createStream(...) run the same count and require it still equals 1. Use the same
test helpers/DB handle available in the test harness to perform these queries so
the assertions live alongside the existing getBalance(...) checks.
🪄 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: 634107ec-f2cf-4536-a0ab-4de3692db6d0

📥 Commits

Reviewing files that changed from the base of the PR and between 2140fea and a0e1f5d.

📒 Files selected for processing (4)
  • internal/migrations/001-common-actions.prod.sql
  • internal/migrations/001-common-actions.sql
  • tests/streams/stream_creation_fee_test.go
  • tests/streams/taxonomy_fee_test.go

Comment thread internal/migrations/001-common-actions.sql
@MicBun MicBun force-pushed the feat/permissionless-stream-creation branch from a0e1f5d to 57b5292 Compare May 26, 2026 04:59
@MicBun MicBun merged commit 1c418a2 into main May 26, 2026
7 of 8 checks passed
@MicBun MicBun deleted the feat/permissionless-stream-creation branch May 26, 2026 06:06
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