-
Notifications
You must be signed in to change notification settings - Fork 3
feat: use datastore directly for state store #66
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
""" WalkthroughThe changes refactor the storage layer in the adapter by replacing the usage of the Rollkit-specific Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Adapter
participant Store as *Store (ds.Batching wrapper)
participant RollkitStore as rstore.Store
Client->>Adapter: NewABCIExecutor(ds.Batching)
Adapter->>Store: LoadState / SaveState using ds.Key "s"
Adapter->>RollkitStore: GetTxs calls Height(ctx)
RpcProvider->>RollkitStore: Block data & height queries
RpcProvider->>Store: LoadState for Validators, Status, ConsensusParams
Server->>Adapter: Start with ds.Batching store
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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used🧬 Code Graph Analysis (1)pkg/rpc/provider/info.go (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
🔇 Additional comments (2)
✨ 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:
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: 3
🔭 Outside diff range comments (2)
pkg/adapter/store.go (1)
16-23
:⚠️ Potential issueHandle
ds.ErrNotFound
to avoid boot-time failures
ipfs/go-datastore
returnsds.ErrNotFound
when the key is missing.
Today that bubbles up as an error, so a brand-new node panics instead of starting
with an empty state.-func loadState(ctx context.Context, s ds.Batching) (*cmtstate.State, error) { - data, err := s.Get(ctx, ds.NewKey(stateKey)) - if err != nil { - return nil, fmt.Errorf("failed to get state metadata: %w", err) - } - if data == nil { - return &cmtstate.State{}, nil - } +func loadState(ctx context.Context, s ds.Batching) (*cmtstate.State, error) { + data, err := s.Get(ctx, ds.NewKey(stateKey)) + if errors.Is(err, ds.ErrNotFound) { + // first start – return an empty state and let the caller initialise it + return &cmtstate.State{}, nil + } + if err != nil { + return nil, fmt.Errorf("failed to get state metadata: %w", err) + }
errors
must also be imported:-import ( - "context" - "fmt" +import ( + "context" + "errors" + "fmt"pkg/adapter/adapter.go (1)
61-70
: 🛠️ Refactor suggestionExtend constructor to receive the Rollkit store
-func NewABCIExecutor( - app servertypes.ABCI, - store ds.Batching, - p2pClient *rollkitp2p.Client, +func NewABCIExecutor( + app servertypes.ABCI, + store ds.Batching, + rollkitStore store.Store, // NEW + p2pClient *rollkitp2p.Client, @@ - a := &Adapter{ - App: app, - Store: store, + a := &Adapter{ + App: app, + Store: store, + RollkitStore: rollkitStore, // NEWAll call-sites must be updated accordingly.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pkg/adapter/adapter.go
(5 hunks)pkg/adapter/store.go
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: lint / golangci-lint
currentHeight, err := a.RollkitStore.Height(ctx) | ||
if err != nil { | ||
return nil, err | ||
} |
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.
Guard against nil RollkitStore
before calling Height
Even with the constructor fix, defensive code is advisable:
- currentHeight, err := a.RollkitStore.Height(ctx)
+ if a.RollkitStore == nil {
+ return nil, fmt.Errorf("RollkitStore not initialised")
+ }
+ currentHeight, err := a.RollkitStore.Height(ctx)
📝 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.
currentHeight, err := a.RollkitStore.Height(ctx) | |
if err != nil { | |
return nil, err | |
} | |
if a.RollkitStore == nil { | |
return nil, fmt.Errorf("RollkitStore not initialised") | |
} | |
currentHeight, err := a.RollkitStore.Height(ctx) | |
if err != nil { | |
return nil, err | |
} |
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.
Left one comment but looks good
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.
Pull Request Overview
This PR refactors the state storage mechanism to use datastore.Batching directly and creates an internal Rollkit interface to access Rollkit's data.
- Replace the old store interface with datastore.Batching in server/start.go and propagate changes to retrieve block heights and block data.
- Update the RPC providers to use the new RollkitStore, ensuring consistency across different RPC endpoints.
- Refactor the adapter and store packages to create a prefixed store for ABCI data while initializing a separate RollkitStore from the same underlying datastore.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
server/start.go | Replaced store reference with executor.RollkitStore for height retrieval and initialization. |
pkg/rpc/provider/provider.go | Updated block height and data retrieval to use RollkitStore instead of the old store. |
pkg/rpc/provider/blockchain.go | Switched to RollkitStore for obtaining block data, height, and block search functionality. |
pkg/adapter/store.go | Converted state load/save functions to use datastore.Batching along with key prefixing. |
pkg/adapter/adapter.go | Modified adapter initialization to wrap the datastore with a prefixed store and create a separate RollkitStore. |
Files not reviewed (1)
- go.mod: Language not supported
Comments suppressed due to low confidence (1)
pkg/adapter/store.go:18
- [nitpick] Consider renaming 'stateKey' to a more descriptive name (e.g., 'stateMetadataKey') to enhance code readability.
stateKey = "s"
pkg/adapter/adapter.go
Outdated
|
||
// Create a prefixed store for ABCI data | ||
prefixedStore := NewPrefixedStore(store) | ||
rollkitStore := rstore.New(store) // do not use prefixedStore for Rollkit |
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.
[nitpick] Consider adding a brief explanation of why RollkitStore is initialized using the original store rather than the prefixedStore to improve maintainability and clarity.
rollkitStore := rstore.New(store) // do not use prefixedStore for Rollkit | |
// RollkitStore requires access to the full, unmodified datastore to function correctly. | |
// Using the prefixedStore would restrict or alter its behavior, which is not desirable. | |
rollkitStore := rstore.New(store) |
Copilot uses AI. Check for mistakes.
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.
left two comments, otherwise looks good
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.
👍 The changes look good!
Bonus points would be available for some regression tests.
pkg/adapter/adapter.go
Outdated
Mempool mempool.Mempool | ||
MempoolIDs *mempoolIDs | ||
App servertypes.ABCI | ||
Store ds.Batching |
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.
personal preference: this is not used somewhere else and can be private
not sure if this is the same idea as @tac0turtle mentioned below but if you would replace batch with a custom state store type, you could encapsulate load/store and avoid the verbose db type.
This may even enable features like caching in the future
@@ -120,7 +120,7 @@ func (p *RpcProvider) BlockResults(ctx context.Context, height *int64) (*coretyp | |||
// Commit implements client.CometRPC. | |||
func (p *RpcProvider) Commit(ctx context.Context, height *int64) (*coretypes.ResultCommit, error) { | |||
heightValue := p.normalizeHeight(height) | |||
header, data, err := p.adapter.Store.GetBlockData(ctx, heightValue) | |||
header, data, err := p.adapter.RollkitStore.GetBlockData(ctx, heightValue) |
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.
could you open an issue, this block structure is not the one we want to use. the header is not compatible with ibc here
Overview
Now we use datastore.Batching directly and create the rollkit interface internally in order to access Rollkit's data.
Closes #64
Summary by CodeRabbit