Skip to content

feat: deploy and configure streams to allow 0 value#190

Merged
MicBun merged 2 commits into
mainfrom
allowZerosStreams
Apr 30, 2026
Merged

feat: deploy and configure streams to allow 0 value#190
MicBun merged 2 commits into
mainfrom
allowZerosStreams

Conversation

@MicBun

@MicBun MicBun commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

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

Summary by CodeRabbit

  • New Features

    • Added per-stream allow_zeros setting to control zero-value persistence during inserts.
    • New SetAllowZeros and GetAllowZeros actions to manage the setting after stream creation.
    • Updated stream deployment with DeployStreamWithOptions to configure allow_zeros at creation.
  • Documentation

    • Added API reference for new stream options and zero-handling behavior.
  • Tests

    • Added test coverage for reserved metadata key protection and new allow_zeros functionality.

@MicBun MicBun requested a review from pr-time-tracker April 30, 2026 07:02
@MicBun MicBun self-assigned this Apr 30, 2026
@MicBun MicBun added the enhancement New feature or request label Apr 30, 2026
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@MicBun has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 1 second before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 05848df5-9c8a-4471-9254-f92ff30b442d

📥 Commits

Reviewing files that changed from the base of the PR and between 45ceaf3 and cfbb35e.

📒 Files selected for processing (3)
  • core/contractsapi/allow_zeros_guard_test.go
  • core/contractsapi/batch_deploy_streams.go
  • core/contractsapi/deploy_stream.go
📝 Walkthrough

Walkthrough

The pull request introduces explicit per-stream allow_zeros management, enabling control over whether zero-value inserts are persisted. Changes include new interface methods, deployment options with parameter threading through client and transport layers, metadata guards preventing reserved key modification, corresponding tests, and documentation updates.

Changes

Cohort / File(s) Summary
Type System & Constants
core/types/contract_values.go, core/types/stream_types.go, core/types/stream.go
Adds AllowZerosKey metadata constant, AllowZeros field to StreamDefinition, and extends IAction interface with SetAllowZeros and GetAllowZeros methods.
Core API Implementation
core/contractsapi/abstract_api.go, core/contractsapi/stream_procedures.go
Implements SetAllowZeros and GetAllowZeros actions invoking contract procedures; adds ErrReservedMetadataKey sentinel error and guard logic preventing modification of AllowZerosKey in insertMetadata.
Deployment & Streams
core/contractsapi/deploy_stream.go, core/contractsapi/batch_deploy_streams.go
Adds AllowZeros field to DeployStreamInput; threads parameter through DeployStream and BatchDeployStreams to create_stream contract calls.
Client Layer
core/tnclient/client.go, core/tnclient/actions_transport.go
Introduces DeployStreamOptions struct and DeployStreamWithOptions method; refactors DeployStream to delegate; adds stub implementations of SetAllowZeros/GetAllowZeros in transport layer.
Tests
core/contractsapi/allow_zeros_guard_test.go, core/types/allow_zeros_test.go
Validates reserved metadata key guard behavior in insertion and disabling operations; verifies AllowZerosKey type mapping and StreamDefinition field defaults.
Documentation
docs/api-reference.md
Documents new DeployStreamWithOptions entry point, updated action methods, zero-value handling behavior, and per-stream AllowZeros semantics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • pr-time-tracker

Poem

🐰 A bunny hops through metadata keys,
With allow_zeros guarding with ease,
Per-stream control, now clearly defined,
No reserved keys shall be maligned,
New options bloom, defaults align! 🌱

🚥 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 accurately captures the main change: adding functionality to deploy and configure streams to allow zero values, which is directly reflected in the changeset across multiple files.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch allowZerosStreams

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
Review rate limit: 0/1 reviews remaining, refill in 36 minutes and 1 second.

Comment @coderabbitai help to get the list of available commands and usage tips.

@holdex

holdex Bot commented Apr 30, 2026

Copy link
Copy Markdown

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Apr 30, 2026, 7:26 AM

You can submit time with the command. Example:

@holdex pr submit-time 15m

See available commands to help comply with our Guidelines.

@MicBun

MicBun commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator Author

@holdex pr submit-time 4h

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
core/contractsapi/allow_zeros_guard_test.go (1)

69-78: ⚡ Quick win

TestInsertMetadata_AllowsOtherKeys is currently vacuous.

This only asserts constants differ, so it will still pass even if insertMetadata starts rejecting non-reserved keys. Please exercise the helper path and assert the failure (if any) is not ErrReservedMetadataKey.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@core/contractsapi/allow_zeros_guard_test.go` around lines 69 - 78, Update
TestInsertMetadata_AllowsOtherKeys to exercise the actual validation path
instead of only comparing constants: for each key (types.ReadVisibilityKey,
types.ComposeVisibilityKey, types.AllowReadWalletKey) call the same
insertion/validation function used by production (e.g., insertMetadata or the
test helper used elsewhere in this package) and assert that the returned error
is either nil or, if non-nil, is not errors.Is(err, ErrReservedMetadataKey);
keep the existing t.Run(name) structure and retain the require.NotEqual check if
desired, but replace the vacuous assertion with the actual call and the error
check against ErrReservedMetadataKey.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@core/contractsapi/batch_deploy_streams.go`:
- Around line 57-60: The code currently sets args = [][]any{{streamIds,
streamTypes, nil}} which still sends a third parameter (nil) and breaks callers
expecting a 2-arg signature; change the construction of args so when you want
the legacy 2-arg call you create a two-element inner slice (e.g.,
[]any{streamIds, streamTypes}) instead of including nil. Locate the
batch_deploy_streams.go logic that builds args (the variable named args and the
values streamIds and streamTypes) and branch so that you only append the third
element when metadata is present; otherwise build args entries with exactly two
elements to preserve compatibility with create_streams' 2-arg signature.

In `@core/contractsapi/deploy_stream.go`:
- Around line 25-29: The current call to input.KwilClient.Execute always passes
a third argument value for "create_stream", breaking legacy 2-argument behavior;
change the call in deploy_stream.go to conditionally build the args slice: if
input.AllowZeros is false, call input.KwilClient.Execute with args containing
only input.StreamId.String() and input.StreamType.String(); if input.AllowZeros
is true, include the third boolean value in the args. Modify the single
invocation of input.KwilClient.Execute to use a small conditional that
constructs [][]any with either two elements ({input.StreamId.String(),
input.StreamType.String()}) or three elements ({input.StreamId.String(),
input.StreamType.String(), input.AllowZeros}) so the 2-argument wire shape is
preserved when AllowZeros is false.

---

Nitpick comments:
In `@core/contractsapi/allow_zeros_guard_test.go`:
- Around line 69-78: Update TestInsertMetadata_AllowsOtherKeys to exercise the
actual validation path instead of only comparing constants: for each key
(types.ReadVisibilityKey, types.ComposeVisibilityKey, types.AllowReadWalletKey)
call the same insertion/validation function used by production (e.g.,
insertMetadata or the test helper used elsewhere in this package) and assert
that the returned error is either nil or, if non-nil, is not errors.Is(err,
ErrReservedMetadataKey); keep the existing t.Run(name) structure and retain the
require.NotEqual check if desired, but replace the vacuous assertion with the
actual call and the error check against ErrReservedMetadataKey.
🪄 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: 88fd4e35-57aa-4bb9-8c02-678e94f4f1c1

📥 Commits

Reviewing files that changed from the base of the PR and between 6a692c7 and 45ceaf3.

📒 Files selected for processing (12)
  • core/contractsapi/abstract_api.go
  • core/contractsapi/allow_zeros_guard_test.go
  • core/contractsapi/batch_deploy_streams.go
  • core/contractsapi/deploy_stream.go
  • core/contractsapi/stream_procedures.go
  • core/tnclient/actions_transport.go
  • core/tnclient/client.go
  • core/types/allow_zeros_test.go
  • core/types/contract_values.go
  • core/types/stream.go
  • core/types/stream_types.go
  • docs/api-reference.md

Comment thread core/contractsapi/batch_deploy_streams.go Outdated
Comment thread core/contractsapi/deploy_stream.go Outdated
@MicBun MicBun merged commit edc0cff into main Apr 30, 2026
4 checks passed
@MicBun MicBun deleted the allowZerosStreams branch April 30, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant