Skip to content

feat(sensor): support more rpc methods#862

Open
minhd-vu wants to merge 90 commits intomainfrom
minhd-vu/rpc-methods
Open

feat(sensor): support more rpc methods#862
minhd-vu wants to merge 90 commits 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 from d9c8647 to 48a6745 Compare February 27, 2026 15:27
@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch from 48a6745 to 865141a Compare February 28, 2026 03:16
minhd-vu and others added 15 commits March 19, 2026 02:01
fix: update p2p package for go-ethereum 1.17.0 RawList API changes

go-ethereum 1.17.0 changed eth protocol types to use rlp.RawList for
lazy decoding optimization:
- BlockHeadersPacket.List replaces BlockHeadersRequest
- BlockBodiesPacket.List replaces BlockBodiesResponse
- PooledTransactionsPacket.List replaces PooledTransactionsResponse
- BlockBody fields now use rlp.RawList instead of slices
- TransactionsPacket embeds rlp.RawList

Updated all p2p code to use .Len() instead of len(), .Items() for
decoding, and rlp.EncodeToRawList() for encoding.
@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 from 2c33ec7 to 33ea396 Compare March 31, 2026 19:25
Combined latestBlockHash and latestBlockNumber into a single
latestBlockInfo struct protected by ds.Locked. This ensures
atomic updates and prevents race conditions where hash and
number could become mismatched when multiple goroutines
update concurrently.

Affected handlers:
- handleBlockRangeUpdate: uses atomic Update with conditional check
- handleNewBlockHashes: uses atomic Update with conditional check
- handleNewBlock: uses atomic Set (always authoritative)
@minhd-vu minhd-vu force-pushed the minhd-vu/rpc-methods branch 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
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

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