Skip to content

feat: configure cache on CRE settings#169

Merged
MicBun merged 13 commits intotrufnetwork:mainfrom
QuantAMMProtocol:CRE-cache-settings
Jan 16, 2026
Merged

feat: configure cache on CRE settings#169
MicBun merged 13 commits intotrufnetwork:mainfrom
QuantAMMProtocol:CRE-cache-settings

Conversation

@bulkcade
Copy link
Copy Markdown
Contributor

@bulkcade bulkcade commented Jan 15, 2026

CRE provides cache settings. The initial implementation of the CRE transport did not allow this to be set.

Apart from the setting of the CRE cache settings there is a change to reqId creation. If there is any WaitForTx or any other issue like a retry / 401 the Id would move on rendering the caching invalid. The functionality of id generation is only changed for when cache settings are set.

How Has This Been Tested?

Structural go unit test extended and pass

CRE workflow truflation-sdk-test deployed to CRE mainnet.
Workflow references package whose location was overridden so that the local repo was referenced rather than the github release location.
Calls work fine.

Summary by CodeRabbit

  • New Features

    • CRE transport now supports optional HTTP request caching with configurable store and max-age, and a convenience option to create a signed transport preconfigured with HTTP caching. Caching enables stable per-call request keys; when disabled, request IDs remain monotonic.
  • Documentation

    • Added guidance and examples for CRE HTTP caching and integration.
  • Tests

    • Expanded coverage for cache behavior, request ID modes, and propagation of cache settings into transport calls.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 15, 2026

📝 Walkthrough

Walkthrough

Adds optional HTTP caching to CRE transport: new CREHTTPCacheConfig, cache-aware constructor and option, per-call CacheSettings and cache-key derivation (SHA-256 when caching), wiring CacheSettings into CRE HTTP requests, tests, and docs updates.

Changes

Cohort / File(s) Change Summary
Options Configuration
core/tnclient/options_cre.go
New option WithCRETransportAndSignerWithHTTPCache(runtime, endpoint, signer, cacheCfg) that sets the signer then constructs the transport via NewCRETransportWithHTTPCache.
Transport Core Implementation
core/tnclient/transport_cre.go
Adds CREHTTPCacheConfig, NewCRETransportWithHTTPCache, ApplyHTTPCacheConfig, cacheSettingsForJSONRPC(method, paramsJSON), and nextReqID(method, paramsJSON); introduces httpCacheStore/httpCacheMaxAge fields, defaults and max clamp, durationpb usage, and attaches CacheSettings into doJSONRPC/doJSONRPCWithResponse/execute flows.
Tests (unit & static analysis)
core/tnclient/transport_cre_test.go
New/expanded tests: endpoint normalization and default cache settings, ApplyHTTPCacheConfig behavior (nil/overrides/clamping), cache settings validation, deterministic vs monotonic NextReqID, and AST-driven check ensuring cacheSettings is produced and attached to HTTP requests; adds AST helper utilities.
Documentation
docs/CRE_INTEGRATION.md
Adds "CRE HTTP caching (recommended for non-idempotent writes)" section with example and new external "CRE HTTP documentation" link.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CRETransport
    participant Signer
    participant CRENode as CRE NodeRuntime
    participant HTTPCache as HTTP Cache/Store

    Client->>CRETransport: doJSONRPC(method, params)
    CRETransport->>CRETransport: paramsJSON := marshal(params)
    CRETransport->>CRETransport: cs := cacheSettingsForJSONRPC(method, paramsJSON)
    alt cs.Store == true
        CRETransport->>CRETransport: reqID := nextReqID(method, paramsJSON)  -- SHA256 deterministic
        CRETransport->>HTTPCache: check cache for reqID
        HTTPCache-->>CRETransport: cached response / miss
    else
        CRETransport->>CRETransport: reqID := nextMonotonicReqID()  -- non-cache path
    end
    CRETransport->>Signer: Sign request (includes reqID/payload)
    Signer-->>CRETransport: signature
    CRETransport->>CRENode: HTTP POST /rpc/v1 with body + CacheSettings
    CRENode-->>CRETransport: HTTP response
    alt cacheable and store enabled
        CRETransport->>HTTPCache: store response with reqID and max-age
    end
    CRETransport-->>Client: parsed JSON-RPC response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • feat: call TN action in ChainLink CRE #165: Modifies CRE transport and option helpers in core/tnclient (options_cre.go, transport_cre.go); likely related changes around CRE transport construction and signer handling.

Suggested labels

enhancement

Suggested reviewers

  • pr-time-tracker

Poem

🐰
I hop and hash each thumping call,
Keep echoes safe in cachey hall,
If repeats arrive, I skip the trip,
Return the answer—save the skip,
More carrots, fewer network hops! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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 'feat: configure cache on CRE settings' accurately describes the main change: adding HTTP cache configuration support to the CRE transport implementation.

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

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
core/tnclient/options_cre.go (1)

124-130: Ignored error from transport creation could mask failures.

The error from NewCRETransportWithHTTPCache is silently discarded. While this is consistent with the existing WithCRETransport and WithCRETransportAndSigner functions (lines 79, 107), if transport creation fails, c.transport will be nil, potentially causing nil pointer dereferences at runtime.

Since the Option type doesn't support returning errors, consider one of:

  1. Logging the error if a logger is available
  2. Storing the error in the Client struct for later retrieval
  3. Documenting this behavior so callers know to verify transport initialization
♻️ Suggested approach: Store initialization error for later inspection

If the Client struct has (or could add) an initErr field:

 func WithCRETransportAndSignerWithHTTPCache(runtime cre.NodeRuntime, endpoint string, signer auth.Signer, cacheCfg *CREHTTPCacheConfig) Option {
 	return func(c *Client) {
 		// Set signer first
 		c.signer = signer
 		// Then create CRE transport with the signer and HTTP cache
-		c.transport, _ = NewCRETransportWithHTTPCache(runtime, endpoint, signer, cacheCfg)
+		var err error
+		c.transport, err = NewCRETransportWithHTTPCache(runtime, endpoint, signer, cacheCfg)
+		if err != nil {
+			c.initErr = err // or use logging if available
+		}
 	}
 }

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f587321 and 7d57c7d.

📒 Files selected for processing (1)
  • core/tnclient/options_cre.go
🧰 Additional context used
🧬 Code graph analysis (1)
core/tnclient/options_cre.go (2)
core/tnclient/transport_cre.go (2)
  • CREHTTPCacheConfig (179-185)
  • NewCRETransportWithHTTPCache (116-123)
core/tnclient/client.go (1)
  • Option (29-29)
🔇 Additional comments (1)
core/tnclient/options_cre.go (1)

111-123: Documentation is clear and follows existing patterns.

The doc comment adequately describes the function's purpose, the order of operations (signer set before transport), and provides a usage example. This is consistent with WithCRETransportAndSigner documentation style.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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

🤖 Fix all issues with AI agents
In `@core/tnclient/transport_cre.go`:
- Around line 187-197: The comment in the cacheSettingsForJSONRPC method
contains an extraneous citation artifact
":contentReference[oaicite:2]{index=2}"; remove that artifact (or replace it
with a proper documentation link or plain explanatory text) so the comment reads
cleanly; locate the cacheSettingsForJSONRPC method on CRETransport and update
the inline comment above the return to omit the citation marker.
🧹 Nitpick comments (3)
docs/CRE_INTEGRATION.md (1)

171-199: Documentation is informative but could benefit from SDK-specific usage example.

The section explains the CRE caching concept well with the raw CRE HTTP example. However, since this PR introduces WithCRETransportAndSignerWithHTTPCache, consider adding an SDK-specific example showing how users can configure caching via the SDK:

// Configure CRE transport with custom cache settings
cacheCfg := &tnclient.CREHTTPCacheConfig{
    Store:         ptr(true),
    MaxAgeSeconds: ptr(int64(120)),
}
client, err := tnclient.NewClient(ctx, endpoint,
    tnclient.WithCRETransportAndSignerWithHTTPCache(nodeRuntime, endpoint, signer, cacheCfg),
)

This would help users understand how the SDK abstracts the raw CRE caching configuration.

core/tnclient/options_cre.go (1)

111-118: Error from transport creation is silently ignored.

The error from NewCRETransportWithHTTPCache is discarded. If transport creation fails, c.transport remains nil, which could cause nil pointer dereferences when the client attempts to use it.

This follows the existing pattern in WithCRETransport and WithCRETransportAndSigner, but consider whether the Option pattern should be refactored to surface initialization errors. At minimum, consider adding a comment explaining this design decision.

Alternative: Capture error for later surfacing

One approach used in some Go codebases is to store the first error and check it in NewClient:

func WithCRETransportAndSignerWithHTTPCache(runtime cre.NodeRuntime, endpoint string, signer auth.Signer, cacheCfg *CREHTTPCacheConfig) Option {
	return func(c *Client) {
		c.signer = signer
		var err error
		c.transport, err = NewCRETransportWithHTTPCache(runtime, endpoint, signer, cacheCfg)
		if err != nil && c.initErr == nil {
			c.initErr = fmt.Errorf("CRE transport initialization failed: %w", err)
		}
	}
}
core/tnclient/transport_cre_test.go (1)

454-459: Consider using strings.HasPrefix from the standard library.

The custom stringsHasPrefix function duplicates strings.HasPrefix. Since strings is already commonly imported in test files, using the stdlib version would be more idiomatic.

Suggested change in test usage
-assert.True(t, stringsHasPrefix(id1, "tn:"), "expected deterministic id to have tn: prefix")
+assert.True(t, strings.HasPrefix(id1, "tn:"), "expected deterministic id to have tn: prefix")

And remove the custom helper function.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c848ac7 and a62a37f.

📒 Files selected for processing (4)
  • core/tnclient/options_cre.go
  • core/tnclient/transport_cre.go
  • core/tnclient/transport_cre_test.go
  • docs/CRE_INTEGRATION.md
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: Chainlink Runtime Environment (CRE) has a limitation of 5 HTTP requests per workflow, which is why the truf-cre-demo example in trufnetwork/sdk-go is split into 3 separate workflows (write, read, cleanup).

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: In the trufnetwork/sdk-go repository's CRE examples, each workflow requires its own config.json file following the CRE CLI (`cre init`) format requirements, which necessitates config file duplication across workflows.

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: In the trufnetwork/sdk-go repository's examples/truf-cre-demo directory, the private key "0000000000000000000000000000000000000000000000000000000000000001" is a dummy/placeholder key used for demonstration purposes in the CRE workflow examples.

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-07-10T15:39:48.576Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 138
File: examples/cache_example.go:21-21
Timestamp: 2025-07-10T15:39:48.576Z
Learning: For example code in the trufnetwork/sdk-go repository, the maintainer MicBun prefers to keep examples simple and focused on demonstrating functionality rather than implementing production-ready security practices like environment variables for sensitive values.

Applied to files:

  • docs/CRE_INTEGRATION.md
🧬 Code graph analysis (2)
core/tnclient/options_cre.go (2)
core/tnclient/transport_cre.go (2)
  • CREHTTPCacheConfig (179-185)
  • NewCRETransportWithHTTPCache (116-123)
core/tnclient/client.go (1)
  • Option (29-29)
core/tnclient/transport_cre_test.go (1)
core/tnclient/transport_cre.go (3)
  • NewCRETransport (97-114)
  • CREHTTPCacheConfig (179-185)
  • CRETransport (59-75)
🔇 Additional comments (16)
docs/CRE_INTEGRATION.md (1)

219-219: LGTM!

Good addition of the CRE HTTP documentation link for reference.

core/tnclient/transport_cre.go (9)

8-9: LGTM!

Imports for SHA-256 hashing and hex encoding are appropriate for the cache key generation feature.


73-74: LGTM!

The cache configuration fields follow the same pattern as other initialization-time fields like endpoint and signer. Since ApplyHTTPCacheConfig is intended to be called during client setup (before concurrent use), no mutex protection is needed.


106-113: Caching enabled by default - verify this is the intended behavior.

The constructor now enables HTTP caching by default (Store: true, MaxAge: 60s). This is a behavioral change that affects all existing CRE transport users.

While the PR description suggests this is intentional for preventing duplicate requests across DON nodes, please verify this default won't cause issues for users who rely on fresh responses (e.g., polling for transaction status).

Note: WaitTx uses user.tx_query which will also be cached. This could cause delayed transaction confirmation detection if the cached response still shows Height: 0.


116-123: LGTM!

Clean constructor that composes NewCRETransport with ApplyHTTPCacheConfig.


125-147: LGTM!

Well-designed configuration application with:

  • Nil-safe handling (noop for nil config)
  • Proper clamping of negative values to zero
  • Enforcement of CRE's 10-minute max cache age limit
  • Pointer semantics allowing partial config updates

149-166: LGTM!

The cache-aware request ID generation is well-designed:

  • Uses SHA-256 hash of method + params for deterministic IDs across DON nodes
  • Null byte separator prevents method/params boundary collisions
  • 8-byte hash prefix provides sufficient uniqueness for cache keys
  • Preserves original monotonic counter behavior when caching is disabled

234-265: LGTM!

The doJSONRPC method correctly integrates cache settings:

  1. Computes paramsJSON first (needed for both the request body and cache key)
  2. Gets cacheSettings using the method and params
  3. Generates deterministic reqID using the same inputs
  4. Attaches CacheSettings to the HTTP request

538-567: LGTM!

The executeOnce method properly constructs the paramsJSON for cache key generation before attaching CacheSettings to the HTTP request. The additional marshaling step is necessary since this method manually constructs the JSON-RPC request.


868-889: LGTM!

The doJSONRPCWithResponse method follows the same pattern as doJSONRPC for cache settings integration, ensuring consistency across all RPC call paths.

core/tnclient/transport_cre_test.go (6)

7-16: LGTM!

Imports are appropriate for the AST-based static analysis tests and extended assertions.


27-45: LGTM!

Good test coverage for:

  • Endpoint normalization (/rpc/v1 suffix)
  • Default cache settings (Store: true, MaxAge: 60s)
  • cacheSettingsForJSONRPC producing valid settings

172-237: LGTM!

Excellent test coverage for ApplyHTTPCacheConfig:

  • Nil config handling (noop)
  • Override application
  • Negative value clamping
  • Maximum value clamping to CRE limit

The tests verify both the internal transport state and the cacheSettingsForJSONRPC output, ensuring the configuration flows through correctly.


239-262: LGTM!

Good coverage verifying that all JSON-RPC methods receive the default cache settings uniformly.


264-298: LGTM!

Thorough testing of nextReqID behavior:

  • Deterministic IDs when caching is active (idempotent for same inputs)
  • Different IDs for different params or methods
  • Correct format (tn: prefix + 16 hex chars)
  • Monotonic sequence when caching is disabled (backward compatibility)

300-338: LGTM - Creative AST-based verification!

This is a clever approach to verify that cache settings are properly wired into HTTP requests without requiring a CRE runtime. The test ensures implementation correctness at the source code level.

Note: This test is inherently coupled to the code structure and will need updates if the implementation is refactored (e.g., function renamed, variable names changed).

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@holdex
Copy link
Copy Markdown

holdex bot commented Jan 15, 2026

Time Submission Status

Member Status Time Action Last Update
@bulkcade ❌ Missing - ⚠️ Submit time -
MicBun ✅ Submitted 15min Update time Jan 16, 2026, 12:21 PM

bulkcade and others added 2 commits January 15, 2026 13:22
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@MicBun
Copy link
Copy Markdown
Member

MicBun commented Jan 16, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jan 16, 2026

✅ Actions performed

Full review triggered.

@MicBun MicBun changed the title Cre cache settings feat: configure cache on CRE settings Jan 16, 2026
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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/tnclient/transport_cre.go (1)

868-889: Authentication requests should not be cached.

Both kgw.authn_param (fetched nonce) and kgw.authn (signed auth request) are cached by default with a 60-second TTL. This creates several problems:

  1. Nonce reuse: A cached nonce could be reused across multiple authentication attempts within the 60-second window, causing duplicate or failed auth submissions.
  2. Stale auth cookies: Cached kgw.authn responses may return expired or invalid Set-Cookie headers if the auth credentials change.
  3. No per-request override: The current implementation does not support disabling caching on a per-request basis. Cache settings are configured only at transport initialization (NewCRETransportWithHTTPCache/ApplyHTTPCacheConfig) and apply globally.

The cacheSettingsForJSONRPC method accepts method and paramsJSON parameters but does not use them; future refactoring could add conditional logic to exclude authentication methods from caching, but this is not implemented.

Recommendation: Either (1) disable caching globally for authentication requests by excluding them from the cached HTTP calls, or (2) implement per-request cache override logic in cacheSettingsForJSONRPC to detect and skip caching for kgw.authn and kgw.authn_param methods.

♻️ Duplicate comments (1)
core/tnclient/transport_cre.go (1)

187-197: Past review comment has been addressed.

The citation artifact (contentReference[oaicite:2]{index=2}) from the previous review has been removed. The comment now reads cleanly.

🧹 Nitpick comments (2)
core/tnclient/options_cre.go (1)

111-118: Consider documenting the function and handling the error.

The function lacks a documentation comment unlike WithCRETransport and WithCRETransportAndSigner. Additionally, the error from NewCRETransportWithHTTPCache is silently discarded. While this is consistent with the existing options in this file, it means a misconfiguration could result in a nil transport with no indication of failure.

Consider at minimum adding a doc comment, and optionally logging or returning the error:

Suggested documentation
+// WithCRETransportAndSignerWithHTTPCache is a convenience function that combines
+// WithSigner and WithCRETransport with HTTP cache configuration.
+//
+// This ensures the signer is set before creating the CRE transport with the
+// specified cache settings, which is necessary for write operations that benefit
+// from CRE's request de-duplication.
 func WithCRETransportAndSignerWithHTTPCache(runtime cre.NodeRuntime, endpoint string, signer auth.Signer, cacheCfg *CREHTTPCacheConfig) Option {
core/tnclient/transport_cre_test.go (1)

473-478: Consider using strings.HasPrefix from the standard library.

The stringsHasPrefix helper function duplicates the functionality of strings.HasPrefix from the standard library. Since strings is a standard package and would have no additional cost, you could simplify by using it directly.

Suggested change
-func stringsHasPrefix(s, prefix string) bool {
-	if len(prefix) > len(s) {
-		return false
-	}
-	return s[:len(prefix)] == prefix
-}

And update line 293:

-		assert.True(t, stringsHasPrefix(id1, "tn:"), "expected deterministic id to have tn: prefix")
+		assert.True(t, strings.HasPrefix(id1, "tn:"), "expected deterministic id to have tn: prefix")
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c848ac7 and f587321.

📒 Files selected for processing (4)
  • core/tnclient/options_cre.go
  • core/tnclient/transport_cre.go
  • core/tnclient/transport_cre_test.go
  • docs/CRE_INTEGRATION.md
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: Chainlink Runtime Environment (CRE) has a limitation of 5 HTTP requests per workflow, which is why the truf-cre-demo example in trufnetwork/sdk-go is split into 3 separate workflows (write, read, cleanup).

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: In the trufnetwork/sdk-go repository's CRE examples, each workflow requires its own config.json file following the CRE CLI (`cre init`) format requirements, which necessitates config file duplication across workflows.

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-12-24T14:19:01.755Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 168
File: examples/truf-cre-demo/truf-read-workflow/config.json:1-5
Timestamp: 2025-12-24T14:19:01.755Z
Learning: In the trufnetwork/sdk-go repository's examples/truf-cre-demo directory, the private key "0000000000000000000000000000000000000000000000000000000000000001" is a dummy/placeholder key used for demonstration purposes in the CRE workflow examples.

Applied to files:

  • docs/CRE_INTEGRATION.md
📚 Learning: 2025-07-10T15:39:48.576Z
Learnt from: MicBun
Repo: trufnetwork/sdk-go PR: 138
File: examples/cache_example.go:21-21
Timestamp: 2025-07-10T15:39:48.576Z
Learning: For example code in the trufnetwork/sdk-go repository, the maintainer MicBun prefers to keep examples simple and focused on demonstrating functionality rather than implementing production-ready security practices like environment variables for sensitive values.

Applied to files:

  • docs/CRE_INTEGRATION.md
🧬 Code graph analysis (1)
core/tnclient/options_cre.go (2)
core/tnclient/transport_cre.go (2)
  • CREHTTPCacheConfig (179-185)
  • NewCRETransportWithHTTPCache (116-123)
core/tnclient/client.go (1)
  • Option (29-29)
⏰ 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: test
🔇 Additional comments (9)
docs/CRE_INTEGRATION.md (2)

171-198: LGTM! Clear documentation for CRE HTTP caching.

The documentation clearly explains the purpose of CRE HTTP caching for non-idempotent operations and provides a practical code example. The guidance about when to use caching (POST/PUT/PATCH/DELETE operations) is helpful for developers.


219-219: Good addition of the CRE HTTP documentation link.

The external reference to the official CRE HTTP documentation is a useful resource for developers seeking more details.

core/tnclient/transport_cre_test.go (3)

319-357: Clever use of AST parsing for verifying internal wiring.

The static analysis approach to verify that CacheSettings is properly wired into HTTP requests is a good solution given the CRE runtime limitations. This ensures the caching logic is correctly integrated without needing to execute the actual CRE HTTP client.


283-317: Good test coverage for both caching modes.

The tests appropriately verify both the deterministic ID generation when caching is active (using SHA-256 hash) and the monotonic sequence when caching is disabled. The assertions for ID format (prefix and length) are correct.


191-256: Comprehensive tests for ApplyHTTPCacheConfig edge cases.

The tests cover nil config (no-op), explicit overrides, negative value clamping, and maximum value clamping. This ensures the configuration handling is robust.

core/tnclient/transport_cre.go (4)

149-166: Good cache-aware request ID implementation.

The logic correctly generates deterministic IDs (using SHA-256 of method + params) when caching is active, which ensures CRE can deduplicate requests across nodes. The fallback to monotonic IDs when caching is disabled maintains backward compatibility. The null byte separator between method and params prevents collision between e.g. method "a" + params "bc" and method "ab" + params "c".


125-147: Robust configuration handling with proper bounds clamping.

The ApplyHTTPCacheConfig method correctly handles nil configs, applies overrides only when values are provided, and clamps values to valid ranges (negative → 0, excessive → max). This defensive approach prevents invalid cache configurations.


177-185: Well-documented configuration type.

The CREHTTPCacheConfig struct is clearly documented with default behavior and clamping rules. The use of pointers for optional fields allows distinguishing "not set" from "explicitly set to false/zero".


538-546: Verify the necessity of re-marshaling params for broadcast cache key.

The paramsJSON is constructed by re-marshaling the transaction JSON into a broadcastParams struct. This works correctly, but note that the cache key will be derived from {"tx":<txJSON>} rather than just txJSON. This is functionally correct since the same transaction will produce the same cache key, but it's worth documenting this behavior if the cache key format matters for debugging.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Copy Markdown
Member

@MicBun MicBun left a comment

Choose a reason for hiding this comment

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

LGTM

Feel free to look at minor comments provided by coderabbit if you want. You can merge the PR once acknowledged
@bulkcade

@bulkcade
Copy link
Copy Markdown
Contributor Author

@MicBun the PR is blocked on cost submission for holdex which I am not part of. I would rather not give it auth to act on my github behalf. Anyway we can disable that check to be able to merge the PR?

Copy link
Copy Markdown
Member

@MicBun MicBun left a comment

Choose a reason for hiding this comment

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

Lgtm

@MicBun MicBun merged commit 4fa5deb into trufnetwork:main Jan 16, 2026
5 of 6 checks passed
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.

2 participants