Skip to content

Conversation

@cloud-j-luna
Copy link
Member

📝 Description

[Explain what this PR does in 2-3 sentences. Include context about the feature or problem being solved]

🔧 Purpose of the Change

  • New feature implementation
  • Bug fix
  • Documentation update
  • Code refactoring
  • Dependency upgrade
  • Other: [specify]

📌 Related Issues

  • Closes #ISSUE_NUMBER
  • References #ISSUE_NUMBER

✅ Checklist

  • I've updated relevant documentation
  • Code follows Akash Network's style guide
  • I've added/updated relevant unit tests
  • Dependencies have been properly updated
  • I agree and adhered to the Contribution Guidelines

📎 Notes for Reviewers

[Include any additional context, architectural decisions, or specific areas to focus on]

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Walkthrough

Adds a sentinel error for missing context values, wraps context-access errors with it, guards client discovery behind offline checks, adds a nil-check for certQuerier in provider TLS verification, and updates CLI broadcast paths and tests to propagate the new wrapped errors.

Changes

Cohort / File(s) Summary
Context error handling
go/cli/context.go
Added exported ErrContextValueNotSet; wrapped missing-context errors in ClientFromContext, LightClientFromContext, MustAddressCodecFromContext, and MustValidatorCodecFromContext using fmt.Errorf("%w: %s", ErrContextValueNotSet, ...).
Client discovery & tx init
go/cli/tx.go, go/node/client/client.go
go/cli/tx.go: replaced direct aclient.DiscoverClient usage with a guarded pattern (declare zero-value client; call discovery.DiscoverClient only when not offline) and propagate discovery errors. go/node/client/client.go: added early return in DiscoverQueryClient when queryClientInfo errors.
Provider certificate validation
go/provider/client/client.go
In verifyPeerCertificate single-leaf mTLS path, added nil-check for c.opts.certQuerier; return an error if nil instead of calling GetAccountCertificate, preserving on-chain cert handling when present.
CLI broadcast flow
go/cli/broadcast.go
Replaced MustClientFromContext(ctx) with ClientFromContext(ctx) that returns (cl, err); added error handling; derive cctx from cl.ClientContext() and proceed only on successful client retrieval.
Test expectations
go/cli/auth_suite_test.go
Updated tests to expect wrapped error message "context does not have value set: context-client" instead of previous offline-mode message.

Sequence Diagram

sequenceDiagram
    participant User
    participant Broadcast as broadcast.RunE
    participant Context as context.ClientFromContext
    participant TxInit as tx.InitClientContext
    participant Discovery as discovery.DiscoverClient
    participant Provider as Provider/Network

    User->>Broadcast: run broadcast command
    Broadcast->>Context: ClientFromContext(ctx)
    alt client present
        Context-->>Broadcast: (client, nil)
    else missing
        Context-->>Broadcast: (nil, ErrContextValueNotSet)
        Broadcast-->>User: return error
    end

    Broadcast->>TxInit: Init client context using client
    alt not offline
        TxInit->>Discovery: DiscoverClient(ctx, cctx, opts...)
        Discovery->>Provider: network discovery
        alt success
            Discovery-->>TxInit: (client, nil)
        else fail
            Discovery-->>TxInit: (nil, error)
            TxInit-->>Broadcast: return error
            Broadcast-->>User: return error
        end
    else offline
        TxInit-->>Broadcast: use zero-value client (no discovery)
    end

    Broadcast->>Broadcast: process and broadcast transaction
    Broadcast-->>User: success or tx error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • troian

"I nibble at bugs with careful nose,
I wrap each missing context where it goes.
No nil will trip my hopping feet,
Discovery waits when offline we meet.
A tiny hop, a codebase cheer — hooray!" 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description only contains the unfilled template placeholders and does not provide any actual implementation details, selected purpose, related issue references, checklist statuses, or reviewer notes, so it does not meet the required template requirements. Please fill out each section of the PR description template by adding a concise summary in the Description section, selecting the appropriate purpose checkbox, listing any related issue numbers under Related Issues, marking completed items in the Checklist, and including any Notes for Reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title clearly states the main change by indicating the addition of offline mode support in the CLI and its propagation through context, making it concise and directly related to the changeset without extraneous detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch luna/offline-mode-context

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb3161c and 02661ce.

📒 Files selected for processing (1)
  • go/provider/client/client.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: cloud-j-luna
PR: akash-network/chain-sdk#118
File: go/cli/tx.go:48-63
Timestamp: 2025-10-16T10:32:01.602Z
Learning: In the Akash chain-sdk CLI (Go), when `cctx.Offline` is true, nil clients are intentionally stored in the context using `ContextTypeClient` and `ContextTypeQueryClient` keys. Operations that support offline mode should check for `ErrContextValueNotSet` when retrieving clients from context using `ClientFromContext()` or `QueryClientFromContext()`, rather than using the `Must*` variants which panic on nil values.
⏰ 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). (3)
  • GitHub Check: coverage
  • GitHub Check: test
  • GitHub Check: go
🔇 Additional comments (1)
go/provider/client/client.go (1)

224-226: LGTM! Defensive nil-check prevents panic.

The nil-check appropriately guards against nil pointer dereference when certQuerier is not configured (e.g., in offline mode). The error message clearly indicates the issue.


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

Copy link
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: 4

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 07fc041 and 06143e1.

📒 Files selected for processing (7)
  • go/cli/cctx.go (1 hunks)
  • go/cli/context.go (5 hunks)
  • go/cli/flags/flags.go (2 hunks)
  • go/cli/query.go (1 hunks)
  • go/cli/tx.go (3 hunks)
  • go/node/client/client.go (1 hunks)
  • go/provider/client/client.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
go/cli/cctx.go (1)
go/cli/context.go (1)
  • ContextTypeProviderURL (29-29)
go/cli/tx.go (3)
go/cli/flags/flags.go (1)
  • FlagProviderURL (89-89)
go/cli/context.go (3)
  • ContextTypeProviderURL (29-29)
  • ContextTypeClient (23-23)
  • ContextTypeQueryClient (24-24)
go/node/client/client.go (2)
  • DiscoverClient (78-102)
  • DiscoverQueryClient (135-159)
go/cli/query.go (2)
go/cli/flags/flags.go (1)
  • FlagProviderURL (89-89)
go/cli/context.go (1)
  • ContextTypeProviderURL (29-29)
go/provider/client/client.go (1)
go/util/tls/verify.go (2)
  • CertificateInvalidError (29-32)
  • Expired (23-23)
⏰ 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). (3)
  • GitHub Check: go
  • GitHub Check: test
  • GitHub Check: coverage
🔇 Additional comments (2)
go/node/client/client.go (1)

137-139: LGTM! Critical bug fix that prevents nil pointer dereference.

This early return is essential and makes DiscoverQueryClient consistent with DiscoverClient (lines 79-82) and DiscoverLightClient (lines 105-108). Without this check, if queryClientInfo returns an error, result would be nil, causing a panic when accessing result.ClientInfo.ApiVersion on line 143.

go/cli/tx.go (1)

10-11: LGTM! Import refactoring aligns with the new discovery pattern.

The imports correctly separate the core client types (aclient) from the discovery functions (discovery), which aligns with the relevant code snippets showing DiscoverClient and DiscoverQueryClient in the discovery package.

@cloud-j-luna cloud-j-luna changed the title feat: add offline mode to cli propagated through context Draft: feat: add offline mode to cli propagated through context Oct 15, 2025
@cloud-j-luna cloud-j-luna force-pushed the luna/offline-mode-context branch from f1139de to b88cf74 Compare October 16, 2025 11:33
Copy link
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: 0

🧹 Nitpick comments (1)
go/cli/context.go (1)

99-111: Consider enhancing type mismatch panic messages for consistency.

The updates to lines 102 and 116 improve error clarity by using fmt.Errorf with ErrContextValueNotSet. For additional consistency with the pattern used in ClientFromContext (line 42), consider updating the type mismatch panics on lines 107 and 121 to include the actual type information:

// Line 107
panic(fmt.Errorf("invalid context value, expected \"address.Codec\", actual \"%s\"", reflect.TypeOf(val)))

// Line 121  
panic(fmt.Errorf("invalid context value, expected \"address.Codec\", actual \"%s\"", reflect.TypeOf(val)))

This would make debugging easier by showing what type was actually present when the assertion fails.

Also applies to: 113-125

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 06143e1 and e927e89.

📒 Files selected for processing (1)
  • go/cli/context.go (5 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: cloud-j-luna
PR: akash-network/chain-sdk#118
File: go/cli/tx.go:23-27
Timestamp: 2025-10-16T10:30:51.243Z
Learning: In the chain-sdk repository (go/cli/tx.go and go/cli/query.go), the ContextTypeProviderURL context value is intentionally set for consumption by external codebases, specifically the provider codebase, even though it's not consumed within chain-sdk itself.
📚 Learning: 2025-10-16T10:30:51.243Z
Learnt from: cloud-j-luna
PR: akash-network/chain-sdk#118
File: go/cli/tx.go:23-27
Timestamp: 2025-10-16T10:30:51.243Z
Learning: In the chain-sdk repository (go/cli/tx.go and go/cli/query.go), the ContextTypeProviderURL context value is intentionally set for consumption by external codebases, specifically the provider codebase, even though it's not consumed within chain-sdk itself.

Applied to files:

  • go/cli/context.go
⏰ 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). (3)
  • GitHub Check: test
  • GitHub Check: coverage
  • GitHub Check: go
🔇 Additional comments (3)
go/cli/context.go (3)

29-29: LGTM! Provider URL context type added as intended.

The new ContextTypeProviderURL constant follows the existing pattern and aligns with the PR's objective of propagating provider URL through context for external consumption.

Based on learnings.


32-32: Excellent error handling improvement.

The introduction of ErrContextValueNotSet as a sentinel error is a best practice that enables callers to detect missing context values using errors.Is(). The consistent wrapping pattern across all accessor functions (ClientFromContext, QueryClientFromContext, LightClientFromContext, MustAddressCodecFromContext, MustValidatorCodecFromContext) provides both context-specific information and error type detection.

Also applies to: 37-37, 51-51, 76-76, 102-102, 116-116


48-60: Well-implemented QueryClient accessor.

The QueryClientFromContext function follows the established pattern with proper error handling:

  • Returns wrapped ErrContextValueNotSet for missing values
  • Performs type assertion with descriptive error messages
  • Correctly references "aclient.QueryClient" in the error message

Copy link
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: 0

🧹 Nitpick comments (1)
go/cli/broadcast.go (1)

45-45: Consider using non-Must variant for defensive programming.

While MustClientFromContext is safe here (the offline check at line 36 ensures we're not in offline mode, and the client should be available in context), using ClientFromContext with explicit error handling would be more defensive and consistent with the codebase pattern.

Apply this diff:

-cl := MustClientFromContext(ctx)
+cl, err := ClientFromContext(ctx)
+if err != nil {
+	return err
+}

Based on learnings: operations should prefer checking for ErrContextValueNotSet using non-Must variants, though the broadcast operation's explicit offline check makes the panic unlikely.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e927e89 and d091f21.

📒 Files selected for processing (1)
  • go/cli/broadcast.go (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: cloud-j-luna
PR: akash-network/chain-sdk#118
File: go/cli/tx.go:48-63
Timestamp: 2025-10-16T10:32:01.585Z
Learning: In the Akash chain-sdk CLI (Go), when `cctx.Offline` is true, nil clients are intentionally stored in the context using `ContextTypeClient` and `ContextTypeQueryClient` keys. Operations that support offline mode should check for `ErrContextValueNotSet` when retrieving clients from context using `ClientFromContext()` or `QueryClientFromContext()`, rather than using the `Must*` variants which panic on nil values.
Learnt from: cloud-j-luna
PR: akash-network/chain-sdk#118
File: go/cli/tx.go:23-27
Timestamp: 2025-10-16T10:30:51.243Z
Learning: In the chain-sdk repository (go/cli/tx.go and go/cli/query.go), the ContextTypeProviderURL context value is intentionally set for consumption by external codebases, specifically the provider codebase, even though it's not consumed within chain-sdk itself.
🧬 Code graph analysis (1)
go/cli/broadcast.go (2)
go/cli/cctx.go (1)
  • GetClientTxContext (81-84)
go/cli/context.go (1)
  • MustClientFromContext (62-69)
⏰ 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). (4)
  • GitHub Check: proto
  • GitHub Check: go
  • GitHub Check: test
  • GitHub Check: coverage
🔇 Additional comments (1)
go/cli/broadcast.go (1)

31-34: LGTM: Proper error handling for context retrieval.

The explicit error handling for GetClientTxContext is a clear improvement over any previous direct retrieval pattern.

@cloud-j-luna cloud-j-luna changed the title Draft: feat: add offline mode to cli propagated through context feat: add offline mode to cli propagated through context Oct 16, 2025
@cloud-j-luna cloud-j-luna force-pushed the luna/offline-mode-context branch 2 times, most recently from 07d164a to d730edc Compare October 16, 2025 15:44
- Add offline flag support to CLI commands
- Propagate offline mode through context to prevent network calls
- Fix broadcast command to check offline mode before accessing client
- Add context value helpers for client and query client management
- Update client initialization to skip when in offline mode
@cloud-j-luna cloud-j-luna force-pushed the luna/offline-mode-context branch from 297a2cf to 1c86640 Compare October 16, 2025 15:49
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.

2 participants