Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded timeout counting to transport reads that aborts after 10 consecutive zero-byte reads and frees the JSON RPC buffer; tightened existence/type validation for several mining RPC params (notify, set_difficulty, set_version_mask, set_extranonce); ensured transports are destroyed after close in reconnect/shutdown paths. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Transport
participant StratumAPI
participant JSONBuffer
Client->>Transport: connect / read()
Transport-->>StratumAPI: return nbytes, data
alt nbytes > 0
StratumAPI->>StratumAPI: timeout_count = 0
StratumAPI->>JSONBuffer: realloc & append data
StratumAPI->>StratumAPI: parse JSON (STRATUM_V1_parse)
else nbytes == 0
StratumAPI->>StratumAPI: timeout_count++
alt timeout_count >= 10
StratumAPI->>JSONBuffer: free & null
StratumAPI->>Transport: close()
StratumAPI->>Transport: destroy()
StratumAPI-->>Client: return NULL / abort
else
StratumAPI->>Transport: retry read()
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/stratum/stratum_api.c`:
- Around line 382-390: Before any validation failure returns via the existing
cleanup/goto paths in the parsing routine, clear the parsed message state so
stale payloads cannot be reused; specifically, reset message->method (and any
other fields that indicate a populated StratumApiV1Message) to NULL/zero before
each of the early frees/goto done branches (the branches that free new_work and
then goto done, and the similar branches around the merkle/branch/extranonce
parsing). Update the validation blocks that currently free new_work and goto
done (including the other similar exits mentioned) to set message->method = NULL
(or memset the StratumApiV1Message to zero) immediately prior to freeing and
jumping to done so the shared StratumApiV1Message cannot replay stale data.
- Around line 172-176: The loop in stratum_api.c aborts after timeout_count
reaches 10, which conflicts with the longer socket receive timeout used
elsewhere; change the cutoff logic in the function that increments timeout_count
(refer to timeout_count and the branch that currently returns NULL) to compute
the max allowed zero-read iterations from the configured transport timeout
constants (e.g., use TRANSPORT_TIMEOUT_MS or the socket receive timeout constant
instead of hardcoded 10) or introduce a TRANSPORT_MAX_TIMEOUTS constant derived
from the liveness budget so the NULL return aligns with the socket's receive
timeout policy.
- Around line 172-176: Before returning NULL on repeated transport read
timeouts, clear the static framing state so future connections don't append to
stale data: reset json_rpc_buffer (e.g., set first byte to '\0' or zero out the
buffer) and reset its position/index variable (e.g., json_rpc_buffer_pos or any
json_rpc_* length counters) and any related state (timeout_count if appropriate)
in the same function that contains the nbytes/timeout_count timeout branch so
the buffered partial message is discarded prior to returning NULL.
- Around line 381-392: The handlers mining.notify, mining.set_difficulty and
mining.set_extranonce currently assume params is an array and directly
dereference items (e.g., params[5]->valuestring, p0->valueint, p1->valueint);
update each handler (mining.notify, mining.set_difficulty,
mining.set_extranonce) to first validate that the params cJSON pointer is a
cJSON array via cJSON_IsArray(), then use cJSON_GetArrayItem() and check each
returned item for NULL and the expected type with cJSON_IsString() or
cJSON_IsNumber() before reading ->valuestring or ->valueint; add error handling
paths that skip processing or return an error when validation fails to avoid
using uninitialized/invalid data.
🪄 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: e4e3c20d-16b1-4e8c-b060-11a703311378
📒 Files selected for processing (2)
components/stratum/stratum_api.cmain/tasks/stratum_task.c
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary by CodeRabbit
Bug Fixes
Chores