Skip to content

chore: add stream info on attestation table#1259

Merged
williamrusdyputra merged 3 commits into
mainfrom
chore/extend-attestation-fields
Nov 19, 2025
Merged

chore: add stream info on attestation table#1259
williamrusdyputra merged 3 commits into
mainfrom
chore/extend-attestation-fields

Conversation

@williamrusdyputra
Copy link
Copy Markdown
Contributor

@williamrusdyputra williamrusdyputra commented Nov 19, 2025

resolves: https://github.com/trufnetwork/trufscan/issues/125

Summary by CodeRabbit

  • New Features

    • Attestations now include data provider and stream identifiers; listing and retrieval surfaces these fields and support filtering by them.
  • Chores

    • Database migration adds columns and indexes to improve query performance when filtering by provider, stream, or both.
  • Tests

    • Updated tests to assert data provider and stream values are stored and returned with attestations.

@williamrusdyputra williamrusdyputra self-assigned this Nov 19, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Nov 19, 2025

Walkthrough

Adds two nullable text columns, data_provider and stream_id, to the attestations table (with indexes), updates the request_attestation INSERT and list_attestations RETURN/SELECT to include them, and updates tests to store and assert these new fields.

Changes

Cohort / File(s) Summary
Schema & Actions
internal/migrations/024-attestation-actions.sql, internal/migrations/028-attestation-add-provider-stream.sql
Add data_provider TEXT and stream_id TEXT to attestations (028 uses ADD COLUMN IF NOT EXISTS); include these columns in request_attestation INSERT and in list_attestations RETURN/SELECT; create indexes ix_att_data_provider, ix_att_stream_id, and composite ix_att_provider_stream.
Tests
tests/streams/attestation/attestation_request_test.go, tests/streams/attestation/attestation_retrieval_test.go
Extend test row struct and DB scanning to include dataProvider and streamID; adjust SELECT column order/mappings; add assertions verifying persisted data_provider and stream_id.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant DB as Database
  rect rgba(192,223,255,0.25)
  Note over Client,DB: Create attestation (request_attestation)
  Client->>DB: CALL request_attestation(..., data_provider, stream_id, ...)
  DB-->>Client: INSERT row including data_provider, stream_id
  end

  rect rgba(212,255,192,0.25)
  Note over Client,DB: Retrieve attestations (list_attestations)
  Client->>DB: CALL list_attestations(...)
  DB-->>Client: SELECT rows with data_provider, stream_id in result set
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Check migration ordering and ensure 024 vs 028 do not conflict (duplicate adds).
  • Verify list_attestations RETURN TABLE signature matches SELECT projection and tests.
  • Confirm tests' SELECT column indices and NULL handling align with migration changes.

Possibly related PRs

Suggested reviewers

  • MicBun

Poem

🐇 I hopped through rows and found two more,
data_provider and stream_id at the core.
Indexes planted, tests gave a cheer,
The rabbit stamped, "New fields are here!" 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Linked Issues check ❓ Inconclusive Linked issue #125 lacks specific acceptance criteria, making it difficult to fully validate that all requirements are met. Review issue #125 and parent issue #64 for complete acceptance criteria to ensure all requirements are addressed.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title clearly describes the primary change: adding stream information (data_provider and stream_id fields) to the attestation table.
Out of Scope Changes check ✅ Passed All changes are directly related to adding stream info (data_provider and stream_id) to the attestation table and related queries.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/extend-attestation-fields

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e7aa25 and f7bcebb.

📒 Files selected for processing (1)
  • internal/migrations/028-attestation-add-provider-stream.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/migrations/028-attestation-add-provider-stream.sql
⏰ 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)
  • GitHub Check: acceptance-test
  • GitHub Check: lint

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

🧹 Nitpick comments (1)
internal/migrations/028-attestation-add-provider-stream.sql (1)

16-26: Consider removing redundant index.

The composite index ix_att_provider_stream on (data_provider, stream_id) can efficiently serve queries filtering by data_provider alone (due to index prefix matching). The standalone ix_att_data_provider index is therefore redundant.

If you want to keep both for clarity or future-proofing, that's fine. Otherwise, you can remove the standalone index:

--- Create index on data_provider for efficient querying
-CREATE INDEX IF NOT EXISTS ix_att_data_provider
-    ON attestations(data_provider);
-
 -- Create index on stream_id for efficient querying
 CREATE INDEX IF NOT EXISTS ix_att_stream_id
     ON attestations(stream_id);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 04fa68d and 5fd4018.

📒 Files selected for processing (4)
  • internal/migrations/024-attestation-actions.sql (4 hunks)
  • internal/migrations/028-attestation-add-provider-stream.sql (1 hunks)
  • tests/streams/attestation/attestation_request_test.go (3 hunks)
  • tests/streams/attestation/attestation_retrieval_test.go (1 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: outerlook
Repo: trufnetwork/node PR: 1207
File: internal/migrations/023-attestation-schema.sql:20-21
Timestamp: 2025-10-10T13:00:13.731Z
Learning: In the attestations table (internal/migrations/023-attestation-schema.sql), the primary key is (requester, created_height, attestation_hash) because attestation_hash is computed deterministically from user input only (version|algo|data_provider|stream_id|action_id|args) and does not include created_height. This allows the same user to request the same attestation at different block heights.
Learnt from: outerlook
Repo: trufnetwork/node PR: 1207
File: internal/migrations/024-attestation-actions.sql:58-76
Timestamp: 2025-10-10T13:00:14.189Z
Learning: In the attestation system for internal/migrations/024-attestation-actions.sql, the attestation_hash is computed from (version|algo|data_provider|stream_id|action_id|args) and intentionally excludes created_height. This design ensures the hash is deterministic based only on user input, not network state like block height.
📚 Learning: 2025-10-10T13:00:13.731Z
Learnt from: outerlook
Repo: trufnetwork/node PR: 1207
File: internal/migrations/023-attestation-schema.sql:20-21
Timestamp: 2025-10-10T13:00:13.731Z
Learning: In the attestations table (internal/migrations/023-attestation-schema.sql), the primary key is (requester, created_height, attestation_hash) because attestation_hash is computed deterministically from user input only (version|algo|data_provider|stream_id|action_id|args) and does not include created_height. This allows the same user to request the same attestation at different block heights.

Applied to files:

  • internal/migrations/028-attestation-add-provider-stream.sql
  • tests/streams/attestation/attestation_retrieval_test.go
  • internal/migrations/024-attestation-actions.sql
  • tests/streams/attestation/attestation_request_test.go
📚 Learning: 2025-10-10T13:00:14.189Z
Learnt from: outerlook
Repo: trufnetwork/node PR: 1207
File: internal/migrations/024-attestation-actions.sql:58-76
Timestamp: 2025-10-10T13:00:14.189Z
Learning: In the attestation system for internal/migrations/024-attestation-actions.sql, the attestation_hash is computed from (version|algo|data_provider|stream_id|action_id|args) and intentionally excludes created_height. This design ensures the hash is deterministic based only on user input, not network state like block height.

Applied to files:

  • internal/migrations/028-attestation-add-provider-stream.sql
  • tests/streams/attestation/attestation_retrieval_test.go
  • internal/migrations/024-attestation-actions.sql
  • tests/streams/attestation/attestation_request_test.go
🧬 Code graph analysis (1)
tests/streams/attestation/attestation_retrieval_test.go (1)
tests/streams/attestation/test_helpers.go (2)
  • TestDataProviderHex (31-31)
  • TestStreamID (30-30)
⏰ 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). (1)
  • GitHub Check: acceptance-test
🔇 Additional comments (7)
internal/migrations/028-attestation-add-provider-stream.sql (1)

8-14: LGTM on column definitions.

The new columns use appropriate types and constraints. The DEFAULT '' ensures existing rows (if any) get valid values, while NOT NULL enforces the requirement for new insertions.

tests/streams/attestation/attestation_retrieval_test.go (1)

163-172: LGTM on test updates.

The test correctly validates the two new columns:

  • Updates expected column count from 6 to 8
  • Verifies data_provider and stream_id are present at the correct positions (indices 3 and 4)
  • Asserts values match the test constants TestDataProviderHex and TestStreamID
tests/streams/attestation/attestation_request_test.go (2)

88-89: LGTM on new assertions.

The test correctly verifies that data_provider and stream_id are stored and match the input values passed to request_attestation.


185-207: LGTM on column mapping updates.

The fetchAttestationRow function correctly:

  • Adds data_provider and stream_id to the SELECT statement
  • Maps them from indices 2 and 3
  • Shifts all subsequent column indices by 2 positions

The mapping is consistent with the updated schema.

internal/migrations/024-attestation-actions.sql (3)

150-156: INSERT statement structure is correct.

Assuming the migration ordering issue is resolved, the INSERT statement correctly:

  • Adds data_provider and stream_id to the column list
  • Inserts the corresponding parameter values in the correct positions
  • Maintains proper alignment between columns and values

287-292: RETURN TABLE signature correctly updated.

The list_attestations action's return signature now includes data_provider TEXT and stream_id TEXT, maintaining consistency with the updated schema and matching test expectations.


315-351: All SELECT statements correctly include new columns.

Each of the five SELECT branches in list_attestations consistently includes data_provider and stream_id in the projection, ensuring uniform output regardless of which query path is taken.

Comment thread internal/migrations/024-attestation-actions.sql
@holdex
Copy link
Copy Markdown

holdex Bot commented Nov 19, 2025

Time Submission Status

Member Status Time Action Last Update
williamrusdyputra ✅ Submitted 3h Update time Nov 19, 2025, 5:52 AM

@williamrusdyputra
Copy link
Copy Markdown
Contributor Author

log: test passed, this issue dragged too long, I will merge then continue

@williamrusdyputra williamrusdyputra merged commit b40a3c1 into main Nov 19, 2025
6 checks passed
@williamrusdyputra williamrusdyputra deleted the chore/extend-attestation-fields branch November 19, 2025 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant