Skip to content

chore: restrict attestation to single-row actions only#1349

Merged
MicBun merged 2 commits into
mainfrom
attestation1row
Mar 31, 2026
Merged

chore: restrict attestation to single-row actions only#1349
MicBun merged 2 commits into
mainfrom
attestation1row

Conversation

@MicBun
Copy link
Copy Markdown
Contributor

@MicBun MicBun commented Mar 31, 2026

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

Summary by CodeRabbit

  • New Features

    • Added two attestation actions: get_high_value and get_low_value for range-based high/low queries.
  • Bug Fixes

    • Adjusted attestation eligibility and date-range validation: multi-row actions are now rejected for certain action IDs; date-range validation now applies to the new high/low actions and requires both endpoints.
  • Tests

    • Updated tests and helpers to use get_last_record and the new high/low actions, and to match revised argument shapes and validation expectations.

@MicBun MicBun requested a review from pr-time-tracker March 31, 2026 10:31
@MicBun MicBun self-assigned this Mar 31, 2026
@holdex
Copy link
Copy Markdown

holdex Bot commented Mar 31, 2026

Time Submission Status

Member Status Time Action Last Update
MicBun ✅ Submitted 4h Update time Mar 31, 2026, 8:35 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 Mar 31, 2026

📝 Walkthrough

Walkthrough

This PR adds public attestation actions get_high_value/get_low_value (IDs 10–11), shifts date-range validation to those actions, blocks multi-row actions 1–3 for attestation, and updates tests and helpers to use get_last_record and the new high/low actions.

Changes

Cohort / File(s) Summary
Attestation Handler Logic
extensions/tn_utils/precompiles.go
Reworks validateAttestationDateRangeHandler: blocks multi-row actions action_id 1–3, restricts date-range validation to action_id 10–11, changes argument-index expectations and error messages, and requires both from and to for validated actions.
New High/Low Value Actions (DB)
internal/migrations/045-high-low-attestation-actions.sql
Adds registrations for get_high_value (10) and get_low_value (11) with primitive implementations and public facades; implements primitive query, deduplication, and composed-stream aggregation to return single (event_time,value) rows.
Attestation Range Tests
tests/streams/attestation/attestation_date_range_test.go
Reworks test matrix: blocks prior multi-row actions for attestation; introduces range validation tests for get_high_value/get_low_value (180-day limit, inverted ranges, nil endpoints, exact 90-day success); adds get_last_record single-point checks.
Attestation Request Helpers / Tests
tests/streams/attestation/request_attestation_fee_test.go, tests/streams/attestation/test_helpers.go
Switches test invocations from get_recordget_last_record (single-point) and range requests → get_high_value; refactors request helper encoding paths and updates TestActionIDRequest constant (10 → 100).
Integration & Other Tests Updated
extensions/tn_settlement/settlement_integration_test.go, tests/streams/order_book/*, tests/streams/transaction_events_ledger_test.go
Replaces get_record with get_last_record in attestation argument encoding and query-component construction across various tests; adjusts encoded argument shapes to match before/frozen_at/use_cache semantics.

Sequence Diagram

sequenceDiagram
    participant Client as Client
    participant Facade as Public Facade
    participant Check as Stream Checker
    participant Prim as Primitive Action
    participant Comp as Composed Aggregator
    participant DB as Database

    Client->>Facade: get_high_value($provider,$stream_id,$from,$to,$frozen_at)
    Facade->>Facade: normalize $data_provider
    Facade->>Check: is_primitive_stream($stream_id)?
    alt primitive
        Check-->>Facade: true
        Facade->>Prim: call primitive get_high_value
        Prim->>DB: authorize (is_allowed_to_read_core)
        DB-->>Prim: auth result
        Prim->>DB: query primitive_events within bounds
        DB-->>Prim: deduplicated rows (ROW_NUMBER)
        Prim-->>Facade: single (event_time,value)
    else composed
        Check-->>Facade: false
        Facade->>Comp: iterate get_record(..., FALSE)
        Comp->>DB: fetch composed records
        DB-->>Comp: record rows
        Comp->>Comp: compute max/min value & event_time
        Comp-->>Facade: single (event_time,value) or NULL
    end
    Facade-->>Client: return result or NULL
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • outerlook

Poem

🐰 I hopped through code, between each row,
Highs and lows now ready to show,
Streams tidy up, ranges set right,
Action IDs hopped into the light,
A tiny rabbit cheers—attestations take flight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: restricting attestation functionality to single-row actions only, which is the primary focus across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ 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 attestation1row

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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@extensions/tn_utils/precompiles.go`:
- Around line 767-770: validate_attestation_date_range was updated to accept
actionIDs 10 and 11 (get_high_value/get_low_value) but getActionIDNumber still
maps only 1–9 causing compute_attestation_hash to return "unknown action";
update getActionIDNumber to include mappings for 10 -> get_high_value and 11 ->
get_low_value (or otherwise ensure compute_attestation_hash recognizes IDs 10
and 11) so the hash path includes these actions consistently with
validate_attestation_date_range and any callers of compute_attestation_hash.

In `@tests/streams/attestation/request_attestation_fee_test.go`:
- Around line 368-385: callRequestAttestationActionWithTimeRange currently
always builds args for get_high_value/get_low_value, which mismatches callers in
attestation_date_range_test.go that call get_record, get_index, and
get_change_over_time; update callRequestAttestationActionWithTimeRange to branch
on actionName and construct the correct ABI-shaped actionArgs per action (e.g.,
for "get_high_value"/"get_low_value" use [dataProvider, streamID, from, to,
frozen_at], for "get_record"/"get_index"/"get_change_over_time" build the
specific argument list those ABIs expect), or alternatively restrict this helper
to only high/low actions and update callers to use a different helper; implement
the branch by switching on actionName in
callRequestAttestationActionWithTimeRange and producing the appropriate
actionArgs before calling tn_utils.EncodeActionArgs and
callRequestAttestationWithBytes.
🪄 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: b4c22208-dafd-4e6e-8bcc-d60a1b449ab1

📥 Commits

Reviewing files that changed from the base of the PR and between e07573f and 6ab328f.

📒 Files selected for processing (5)
  • extensions/tn_utils/precompiles.go
  • internal/migrations/045-high-low-attestation-actions.sql
  • tests/streams/attestation/attestation_date_range_test.go
  • tests/streams/attestation/request_attestation_fee_test.go
  • tests/streams/attestation/test_helpers.go

Comment thread extensions/tn_utils/precompiles.go
Comment thread tests/streams/attestation/request_attestation_fee_test.go
@MicBun MicBun marked this pull request as draft March 31, 2026 11:13
@MicBun MicBun marked this pull request as ready for review March 31, 2026 20:30
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.

🧹 Nitpick comments (1)
tests/streams/order_book/settlement_test.go (1)

706-709: Potential argument mismatch when argsBytes is nil.

The encodeQueryComponentsForTests helper (per relevant snippet at test_helpers_orderbook.go:143-200) uses default args with get_record semantics (6 args: data_provider, stream_id, from, to, frozen_at, use_cache) when argsBytes is nil. However, get_last_record expects 5 args: (data_provider, stream_id, before, frozen_at, use_cache).

While this test intentionally creates a market without a matching attestation (to verify the "no attestation" error path), the argument mismatch could cause issues if the validation logic ever inspects the args structure. Consider explicitly encoding the correct args for consistency:

🔧 Suggested fix
-		fakeQueryComponents, err := encodeQueryComponentsForTests(dataProvider, streamID, "get_last_record", nil)
+		fakeArgsBytes, err := tn_utils.EncodeActionArgs([]any{
+			dataProvider, streamID, int64(1500), nil, false,
+		})
+		require.NoError(t, err)
+		fakeQueryComponents, err := encodeQueryComponentsForTests(dataProvider, streamID, "get_last_record", fakeArgsBytes)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/streams/order_book/settlement_test.go` around lines 706 - 709, The test
calls encodeQueryComponentsForTests with argsBytes == nil which makes the helper
default to the 6-arg get_record signature, but this test uses action
"get_last_record" which expects 5 args; fix by constructing and passing explicit
argsBytes for get_last_record (populate data_provider, stream_id, before,
frozen_at, use_cache) and pass that into encodeQueryComponentsForTests instead
of nil so the encoded query matches get_last_record semantics; locate the call
site in settlement_test.go and update the argsBytes creation near where
encodeQueryComponentsForTests is invoked.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/streams/order_book/settlement_test.go`:
- Around line 706-709: The test calls encodeQueryComponentsForTests with
argsBytes == nil which makes the helper default to the 6-arg get_record
signature, but this test uses action "get_last_record" which expects 5 args; fix
by constructing and passing explicit argsBytes for get_last_record (populate
data_provider, stream_id, before, frozen_at, use_cache) and pass that into
encodeQueryComponentsForTests instead of nil so the encoded query matches
get_last_record semantics; locate the call site in settlement_test.go and update
the argsBytes creation near where encodeQueryComponentsForTests is invoked.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b3ae8cc-969c-4aff-8e21-6cb13224e259

📥 Commits

Reviewing files that changed from the base of the PR and between 6ab328f and 300d5de.

📒 Files selected for processing (6)
  • extensions/tn_settlement/settlement_integration_test.go
  • extensions/tn_utils/precompiles.go
  • tests/streams/order_book/hash_compatibility_test.go
  • tests/streams/order_book/order_events_test.go
  • tests/streams/order_book/settlement_test.go
  • tests/streams/transaction_events_ledger_test.go

@MicBun MicBun merged commit 41fee66 into main Mar 31, 2026
10 of 12 checks passed
@MicBun MicBun deleted the attestation1row branch March 31, 2026 20:47
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