-
Notifications
You must be signed in to change notification settings - Fork 2
Add proofs to rpc response #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughA new mechanism for generating and returning Merkle proofs for transactions was implemented in the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant RPC_Core
participant RollkitStore
Client->>RPC_Core: Tx / TxSearch (prove=true)
RPC_Core->>RollkitStore: GetBlockData(height)
RollkitStore-->>RPC_Core: BlockData (transactions)
RPC_Core->>RPC_Core: Build Merkle proof for tx at index
RPC_Core-->>Client: Tx result with Merkle proof
Assessment against linked issues
Suggested reviewers
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Nitpick comments (2)
pkg/rpc/core/tx.go (1)
108-113
: RepeatedGetBlockData
calls hurt performance – cache per block height
TxSearch
may contain many transactions belonging to the same block (e.g. the
two height-10 txs in your new test).
At the moment we fetch and rebuild the whole block data once per tx, which is
O(N·B) instead of O(N+B).A lightweight map keyed by
height
(or even the already-filled
proofCache[height]
) would cut redundant store reads and Merkle calculations.pkg/rpc/core/tx_test.go (1)
53-72
: Consider asserting proof RootHash / Data for stronger guaranteesThe current test only checks
Total
,Index
, and thatLeafHash
is non-empty.
VerifyingRootHash
and thatProof.Data
equals the originalsampleTx
would provide end-to-end confidence that the proof is built from the correct
transaction bytes.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pkg/rpc/core/tx.go
(4 hunks)pkg/rpc/core/tx_test.go
(6 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
pkg/rpc/core/tx_test.go (4)
pkg/rpc/core/mocks_test.go (1)
MockRollkitStore
(113-115)pkg/rpc/core/env.go (1)
Environment
(27-33)pkg/adapter/adapter.go (1)
Adapter
(53-69)pkg/rpc/core/tx.go (2)
Tx
(22-49)TxSearch
(54-125)
pkg/rpc/core/tx.go (1)
pkg/adapter/adapter.go (1)
Adapter
(53-69)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: lint / golangci-lint
- GitHub Check: test / Run Unit Tests
- GitHub Check: Test with Rollkit Chain
func proofTXExists(txs []rlktypes.Tx, i uint32) cmttypes.TxProof { | ||
hl := hashList(txs) | ||
root, proofs := merkle.ProofsFromByteSlices(hl) | ||
|
||
return cmttypes.TxProof{ | ||
RootHash: root, | ||
Data: cmttypes.Tx(txs[i]), | ||
Proof: *proofs[i], | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Return early when txs
is empty to prevent invalid proofs
merkle.ProofsFromByteSlices
panics on an empty slice. A quick guard keeps the
node stable when encountering an unexpected empty block.
func proofTXExists(txs []rlktypes.Tx, i uint32) cmttypes.TxProof {
+ if len(txs) == 0 {
+ return cmttypes.TxProof{}
+ }
hl := hashList(txs)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func proofTXExists(txs []rlktypes.Tx, i uint32) cmttypes.TxProof { | |
hl := hashList(txs) | |
root, proofs := merkle.ProofsFromByteSlices(hl) | |
return cmttypes.TxProof{ | |
RootHash: root, | |
Data: cmttypes.Tx(txs[i]), | |
Proof: *proofs[i], | |
} | |
} | |
func proofTXExists(txs []rlktypes.Tx, i uint32) cmttypes.TxProof { | |
if len(txs) == 0 { | |
return cmttypes.TxProof{} | |
} | |
hl := hashList(txs) | |
root, proofs := merkle.ProofsFromByteSlices(hl) | |
return cmttypes.TxProof{ | |
RootHash: root, | |
Data: cmttypes.Tx(txs[i]), | |
Proof: *proofs[i], | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, nice cleanup
* main: Add proofs to rpc response (#96)
Resolves #89
Add proofs to TX get + search response
Overview
Summary by CodeRabbit
New Features
prove
flag in transaction queries.Tests