Conversation
WalkthroughThis change implements fee collection for taxonomy operations in the insert_taxonomy stored procedure. Non-exempt callers pay 2 TRUF per child stream with balance validation before the transfer. Callers with the system:network_writer role bypass fees entirely. A comprehensive test suite validates fee behavior across multiple scenarios. Changes
Sequence DiagramsequenceDiagram
actor User
participant Engine as Taxonomy Engine
participant RoleCheck as Role Check
participant Balance as Balance Validator
participant Ledger as Fee Ledger
participant DB as Database
User->>Engine: insert_taxonomy(children, weights...)
Engine->>RoleCheck: Check role (system:network_writer)?
alt Role Exempt
RoleCheck-->>Engine: Exempt (skip fee)
Engine->>DB: Insert taxonomy
DB-->>Engine: Success
else Role Non-Exempt
RoleCheck-->>Engine: Not exempt
Engine->>Balance: Calculate fee (2 TRUF × children_count)
Balance->>Balance: totalFee = 2 TRUF × N
Balance->>Ledger: Check caller balance ≥ totalFee
alt Sufficient Balance
Ledger-->>Balance: ✓ Balance OK
Balance-->>Engine: Fee validated
Engine->>Ledger: Transfer totalFee to leader_sender
Ledger-->>Engine: Fee transferred
Engine->>DB: Insert taxonomy
DB-->>Engine: Success
else Insufficient Balance
Ledger-->>Balance: ✗ Insufficient balance
Balance-->>Engine: Error (required: X, available: Y, children: N)
Engine-->>User: Transaction rejected
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (1)tests/streams/taxonomy_fee_test.go (5)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (2)
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. Comment |
Time Submission Status
|
resolves: https://github.com/trufnetwork/truf-network/issues/1313
Summary by CodeRabbit