Skip to content

feat(sensor): support more rpc methods#862

Merged
minhd-vu merged 1 commit intomainfrom
minhd-vu/rpc-methods
Apr 7, 2026
Merged

feat(sensor): support more rpc methods#862
minhd-vu merged 1 commit intomainfrom
minhd-vu/rpc-methods

Conversation

@minhd-vu
Copy link
Copy Markdown
Contributor

@minhd-vu minhd-vu commented Feb 25, 2026

Description

Jira / Linear Tickets

Testing

  • 👀
  • Deployed Amoy
  • Deployed Mainnet

@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch 2 times, most recently from 48a6745 to 865141a Compare February 28, 2026 03:16
@minhd-vu minhd-vu marked this pull request as ready for review March 3, 2026 12:45
@minhd-vu minhd-vu marked this pull request as draft March 3, 2026 12:45
@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch from 131e248 to 73bbd26 Compare March 3, 2026 22:32
@minhd-vu minhd-vu force-pushed the minhd-vu/sensor-broadcast branch from 00de538 to 77b474b Compare March 4, 2026 02:47
Base automatically changed from minhd-vu/sensor-broadcast to main March 4, 2026 02:51
@praetoriansentry
Copy link
Copy Markdown
Member

Code review

Found 2 issues:

  1. TOCTOU race condition when updating latestBlockHash and latestBlockNumber. The check-then-set pattern uses three separate lock operations (Get, Set, Set), so two goroutines handling different peers can both pass the > check and interleave their writes, leaving hash and number mismatched (e.g., hash from block N, number from block N+1). This appears in handleBlockRangeUpdate, handleNewBlockHashes, and handleNewBlock. (CLAUDE.md says "Race Conditions: Run with -race flag during testing; protect shared state with mutexes or channels")

polygon-cli/p2p/protocol.go

Lines 443 to 447 in d8ec9e3

// Update latest block info from the range update (thread-safe for API access)
if packet.LatestBlock > c.latestBlockNumber.Get() {
c.latestBlockHash.Set(packet.LatestBlockHash)
c.latestBlockNumber.Set(packet.LatestBlock)
}

polygon-cli/p2p/protocol.go

Lines 546 to 550 in d8ec9e3

// Update latest block info if this block is newer (thread-safe for API access)
if entry.Number > c.latestBlockNumber.Get() {
c.latestBlockHash.Set(hash)
c.latestBlockNumber.Set(entry.Number)
}

polygon-cli/p2p/protocol.go

Lines 1126 to 1129 in d8ec9e3

// Update latest block info for this peer (thread-safe for API access)
c.latestBlockHash.Set(hash)
c.latestBlockNumber.Set(packet.Block.Number().Uint64())

  1. Batch proxy silently drops already-validated transactions. In handleBatchRequest, when the loop encounters an unsupported method mid-batch, it proxies the entire original batch and returns early — without broadcasting transactions that were already validated and collected in txs from earlier iterations. For example, a batch of [eth_sendRawTransaction, eth_getBalance] with proxy enabled would validate the transaction but never broadcast it. (CLAUDE.md says "Completeness: Data collection operations must fetch ALL requested data or fail entirely - never produce partial results")

for _, req := range requests {
resp := processRequest(req, params, &txs)
// If any method not found and proxy is enabled, forward entire batch
if isMethodNotFound(resp) && params.proxy != nil {
for _, rpcReq := range requests {
params.counter.WithLabelValues(rpcReq.Method, "true").Inc()
}
proxyRPCRequest(w, r, body, params.proxy)
return
}
params.counter.WithLabelValues(req.Method, "false").Inc()
responses = append(responses, resp)
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch 2 times, most recently from 33ea396 to f2d33a1 Compare March 31, 2026 19:33
@minhd-vu minhd-vu marked this pull request as ready for review April 1, 2026 12:46
Copy link
Copy Markdown
Contributor

@jhkimqd jhkimqd left a comment

Choose a reason for hiding this comment

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

Few comments from claude

jhkimqd
jhkimqd previously approved these changes Apr 7, 2026
@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch from 3bcee24 to a3b81a1 Compare April 7, 2026 13:47
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 7, 2026

@minhd-vu minhd-vu merged commit 936ec0c into main Apr 7, 2026
16 checks passed
@minhd-vu minhd-vu deleted the minhd-vu/rpc-methods branch April 7, 2026 13:53
@minhd-vu minhd-vu restored the minhd-vu/rpc-methods branch April 7, 2026 13:54
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.

3 participants