Skip to content

Fallback of RPC selection#692

Merged
feruzm merged 7 commits into
developfrom
fallback
Mar 5, 2026
Merged

Fallback of RPC selection#692
feruzm merged 7 commits into
developfrom
fallback

Conversation

@feruzm
Copy link
Copy Markdown
Member

@feruzm feruzm commented Mar 5, 2026

Summary by CodeRabbit

  • New Features

    • Adds a verification phase for missing posts with a dedicated loading and retry UI; verifies on alternate nodes when primary returns no data.
  • Bug Fixes

    • Reduces false "deleted" screens by distinguishing optimistic vs non-optimistic flows and improving verification/failover behavior.
  • Tests

    • Adds comprehensive tests for alternate-node verification and post-query behaviors.
  • Documentation

    • Adds "Updated" translation key (en-US).
  • Chores

    • Adjusts default node ordering and failover threshold; exposes verification helpers via the SDK.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 5, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 427f4e60-d7b6-4395-a742-b90e8ba9c813

📥 Commits

Reviewing files that changed from the base of the PR and between a7e0116 and f2e053a.

⛔ Files ignored due to path filters (6)
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (9)
  • apps/web/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/entry-not-found-fallback.tsx
  • packages/sdk/CHANGELOG.md
  • packages/sdk/package.json
  • packages/sdk/src/modules/bridge/verify-on-alternate-node.spec.ts
  • packages/sdk/src/modules/bridge/verify-on-alternate-node.ts
  • packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts
  • packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts
  • packages/wallets/CHANGELOG.md
  • packages/wallets/package.json

📝 Walkthrough

Walkthrough

Adds non‑optimistic verification polling for missing entries, a new verifyPostOnAlternateNode utility (exported from bridge) with tests to query up to two alternate Hive nodes, tweaks SDK Hive client defaults, and wires alternate-node verification into post query flows and related tests.

Changes

Cohort / File(s) Summary
Entry Component Polling & I18n
apps/web/src/app/(dynamicPages)/entry/.../entry-not-found-fallback.tsx, apps/web/src/features/i18n/locales/en-US.json
Adds VERIFY_MAX_POLLS, verifyPollCount, isVerifying and useRef tracking for verification polling; introduces verification UI states (loading, retry) and adds "updated" translation key.
Bridge: Alternate Node Verification
packages/sdk/src/modules/bridge/index.ts, packages/sdk/src/modules/bridge/verify-on-alternate-node.ts, packages/sdk/src/modules/bridge/verify-on-alternate-node.spec.ts
Adds verifyPostOnAlternateNode and MAX_ALTERNATE_NODES = 2, re-exports it from bridge index, implements alternate-node verification with per-node 10s client timeout, and adds Vitest tests covering success/failure and edge cases.
SDK Config
packages/sdk/src/modules/core/config.ts
Reorders DEFAULT_HIVE_NODES (moves one node to end) and lowers HIVE_CLIENT_OPTIONS.failoverThreshold from 3 → 2.
Post Query Logic & Tests
packages/sdk/src/modules/posts/queries/get-post-query-options.ts, packages/sdk/src/modules/posts/queries/get-post-query-options.spec.ts, packages/sdk/src/modules/posts/queries/get-account-posts-query-options.ts, packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts, packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.ts, packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts
Wires in alternate-node verification when primary get_post returns null (captures primaryNode to exclude it), constructs/returns verified Entry when alternates succeed, adjusts account-posts RPC parameter flow and error handling, adds type checks for ranked responses, and expands tests to cover verification and new behaviors.
Packaging & Changelog Updates
packages/sdk/CHANGELOG.md, packages/sdk/package.json, packages/wallets/CHANGELOG.md, packages/wallets/package.json
Bumps SDK and wallets package versions, adds CHANGELOG entries referencing fallback/RPC selection changes.

Sequence Diagram

sequenceDiagram
    participant Client
    participant QueryCache as Query Cache
    participant Bridge
    participant PrimaryNode as Primary Hive Node
    participant AlternateNodes as Alternate Hive Nodes

    Client->>Bridge: getPost(author, permlink, observer)
    Bridge->>PrimaryNode: bridge.get_post(...)
    alt Primary returns Entry
        PrimaryNode-->>Bridge: Entry
        Bridge->>QueryCache: update cache
        Bridge-->>Client: return Entry
    else Primary returns null
        PrimaryNode-->>Bridge: null
        Bridge->>AlternateNodes: verifyPostOnAlternateNode(author, permlink, observer, primaryNode)
        alt Alternate returns Entry
            AlternateNodes-->>Bridge: Entry
            Bridge->>QueryCache: update cache
            Bridge-->>Client: return verified Entry
        else All alternates null/failed
            AlternateNodes-->>Bridge: null
            Bridge-->>Client: return null
        end
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hop through nodes both near and far,
When primary's silent, I seek another star,
Two alternates checked with patient pace,
Polls that watch until a verified trace,
Hooray — a found post snug in place!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fallback of RPC selection' is directly related to the main objective of the PR, which implements RPC failover and verification mechanisms across multiple files.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fallback

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.

coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@feruzm feruzm marked this pull request as draft March 5, 2026 08:38
@feruzm feruzm marked this pull request as ready for review March 5, 2026 08:38
coderabbitai[bot]

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

@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

🧹 Nitpick comments (2)
packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts (1)

72-91: Strengthen the success-case assertion to actually prove sorting/filtering.

At Line 72, the test says “sorted and filtered,” but the fixture is already in descending order and no filtering effect is asserted, so this can pass even if sorting/filtering regresses.

Suggested test adjustment
-  it('should return sorted and filtered entries on success', async () => {
+  it('should return entries sorted by created desc on success', async () => {
     const mockEntries = [
-      { author: 'a', permlink: 'p1', created: '2026-01-02T00:00:00', stats: null },
-      { author: 'b', permlink: 'p2', created: '2026-01-01T00:00:00', stats: null }
+      { author: 'b', permlink: 'p2', created: '2026-01-01T00:00:00', stats: null },
+      { author: 'a', permlink: 'p1', created: '2026-01-02T00:00:00', stats: null }
     ]
     vi.mocked(CONFIG.hiveClient.call).mockResolvedValue(mockEntries)

     const options = getPostsRankedInfiniteQueryOptions('created', 'hive')
     const result = await options.queryFn({
@@
-    expect(result).toHaveLength(2)
-    // Sorted by created desc
-    expect(result[0].author).toBe('a')
+    expect(result.map((e) => e.author)).toEqual(['a', 'b'])
   })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`
around lines 72 - 91, The test currently uses mockEntries already in descending
order so it doesn't prove sorting/filtering; modify the spec for
getPostsRankedInfiniteQueryOptions by providing mockEntries in unsorted order
and/or adding an entry that should be filtered out, then call options.queryFn
(the existing call that uses CONFIG.hiveClient.call) and assert the returned
array is sorted descending by created (e.g., check that result[0] has the newest
created timestamp) and that any filtered entries are absent (e.g., assert result
does not contain the filtered permlink/author); this ensures the test fails if
getPostsRankedInfiniteQueryOptions' sorting or filtering regresses.
packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts (1)

24-107: Reduce duplicated infinite-query context setup in tests.

The repeated options.queryFn({...}) payload makes this suite harder to maintain. Extract a small helper for the infinite query context.

♻️ Suggested refactor
+const buildInfiniteQueryContext = (queryKey: unknown, pageParam: { author?: string; permlink?: string; hasNextPage: boolean }) => ({
+  pageParam,
+  meta: undefined as any,
+  direction: "forward" as const,
+  queryKey,
+  signal: new AbortController().signal,
+});
+
 it('should return [] when pageParam.hasNextPage is false', async () => {
   const options = getAccountPostsInfiniteQueryOptions('testuser')
-  const result = await options.queryFn({
-    pageParam: { author: undefined, permlink: undefined, hasNextPage: false },
-    meta: undefined as any,
-    direction: 'forward',
-    queryKey: options.queryKey,
-    signal: new AbortController().signal
-  })
+  const result = await options.queryFn(
+    buildInfiniteQueryContext(options.queryKey, { author: undefined, permlink: undefined, hasNextPage: false })
+  )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts`
around lines 24 - 107, Tests repeat the same infinite-query context payload for
options.queryFn; extract a small helper to build that context to reduce
duplication. Add a function (e.g., makeInfiniteQueryContext) used by all cases
that returns an object with keys pageParam, meta, direction, queryKey:
options.queryKey, and signal so each test calls
options.queryFn(makeInfiniteQueryContext({ pageParam: {...} })) instead of
inlining the whole payload; update references in tests that call
getAccountPostsInfiniteQueryOptions and ensure mockGetAccountPosts usage remains
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@apps/web/src/app/`(dynamicPages)/entry/[category]/[author]/[permlink]/_components/entry-not-found-fallback.tsx:
- Around line 41-42: The non-optimistic "deleted" fallback can fire after
handleSuccess flips transition state because current guards use isVerifying =
!isOptimistic && verifyPollCount < VERIFY_MAX_POLLS without checking
hasTransitioned; update all places that decide non-optimistic polling/fallback
(the isVerifying computation and the conditional checks around
verifyPollCount/VERIFY_MAX_POLLS at the other occurrences) to include
hasTransitioned (e.g., require !isOptimistic && hasTransitioned &&
verifyPollCount < VERIFY_MAX_POLLS) so the component stops treating the post as
deleted once a transition has occurred (affecting the logic that renders
DeletedPostScreen and any code paths that call router.refresh()).

In `@packages/sdk/src/modules/bridge/verify-on-alternate-node.ts`:
- Around line 41-49: The code currently returns any truthy response from
client.call("bridge","get_post") as an Entry; instead, validate the identity
before accepting it by checking that the returned object's author and permlink
match the requested author and permlink. In the verify-on-alternate-node flow
(look for the client.call("bridge", "get_post", { author, permlink, observer })
call and the response variable), ensure response is an object with
response.author === author and response.permlink === permlink (and optionally
has required Entry properties) before returning it as an Entry; if the check
fails, treat it as an invalid result (e.g., reject/skip/return null) so
malformed or mismatched payloads are not accepted.

---

Nitpick comments:
In
`@packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts`:
- Around line 24-107: Tests repeat the same infinite-query context payload for
options.queryFn; extract a small helper to build that context to reduce
duplication. Add a function (e.g., makeInfiniteQueryContext) used by all cases
that returns an object with keys pageParam, meta, direction, queryKey:
options.queryKey, and signal so each test calls
options.queryFn(makeInfiniteQueryContext({ pageParam: {...} })) instead of
inlining the whole payload; update references in tests that call
getAccountPostsInfiniteQueryOptions and ensure mockGetAccountPosts usage remains
unchanged.

In
`@packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts`:
- Around line 72-91: The test currently uses mockEntries already in descending
order so it doesn't prove sorting/filtering; modify the spec for
getPostsRankedInfiniteQueryOptions by providing mockEntries in unsorted order
and/or adding an entry that should be filtered out, then call options.queryFn
(the existing call that uses CONFIG.hiveClient.call) and assert the returned
array is sorted descending by created (e.g., check that result[0] has the newest
created timestamp) and that any filtered entries are absent (e.g., assert result
does not contain the filtered permlink/author); this ensures the test fails if
getPostsRankedInfiniteQueryOptions' sorting or filtering regresses.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4fae5d25-d64f-40d1-afc8-263bde91708a

📥 Commits

Reviewing files that changed from the base of the PR and between d99efc0 and a7e0116.

⛔ Files ignored due to path filters (6)
  • packages/sdk/dist/browser/index.js is excluded by !**/dist/**
  • packages/sdk/dist/browser/index.js.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.cjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.cjs.map is excluded by !**/dist/**, !**/*.map
  • packages/sdk/dist/node/index.mjs is excluded by !**/dist/**
  • packages/sdk/dist/node/index.mjs.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (5)
  • apps/web/src/app/(dynamicPages)/entry/[category]/[author]/[permlink]/_components/entry-not-found-fallback.tsx
  • packages/sdk/src/modules/bridge/verify-on-alternate-node.spec.ts
  • packages/sdk/src/modules/bridge/verify-on-alternate-node.ts
  • packages/sdk/src/modules/posts/queries/get-account-posts-query-options.spec.ts
  • packages/sdk/src/modules/posts/queries/get-posts-ranked-query-options.spec.ts

Comment thread packages/sdk/src/modules/bridge/verify-on-alternate-node.ts
@feruzm feruzm added the patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR label Mar 5, 2026
@feruzm feruzm merged commit 23fa370 into develop Mar 5, 2026
@feruzm feruzm deleted the fallback branch March 5, 2026 10:39
@coderabbitai coderabbitai Bot mentioned this pull request Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch Bug fixes and patches (1.0.0 → 1.0.1), add this only if any packages/ have patch changes in PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant