-
Notifications
You must be signed in to change notification settings - Fork 59
Add event-based offchain indexer with Runtime API and RPC for pallet-robonomics-cps #488
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
Open
Copilot
wants to merge
12
commits into
release/4.1
Choose a base branch
from
copilot/add-offchain-worker-indexer
base: release/4.1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5177b44
Initial plan
Copilot 872950e
Add CPS offchain indexer with Runtime API and RPC extension
Copilot 1885810
Fix warnings and verify CPS pallet builds with and without offchain-w…
Copilot 56d6073
Address code review feedback - improve error messages and add perform…
Copilot 9a37c10
Add security considerations to documentation
Copilot ce0d328
Address PR feedback: rename feature, add node_id, use OperationType e…
Copilot 7a0f707
Improve indexer: double-map storage (node_id first), optional from/to…
Copilot 5c78cc5
Refactor: node_id first param, return structs directly, use block num…
Copilot 2335411
Use sp_io::offchain_index for data indexing and add node index for ef…
Copilot a998f32
Implement efficient event-based offchain indexing with single write p…
Copilot 54358ae
Update documentation to reflect event-based indexing architecture
Copilot b48dc0f
[WIP] Fix compilation, extract runtime events for indexer
akru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| [package] | ||
| name = "pallet-robonomics-cps-rpc" | ||
| description = "RPC extension for Robonomics CPS Indexer" | ||
| version = "0.1.0" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| license = "Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| jsonrpsee = { workspace = true, features = ["client-core", "server", "macros"] } | ||
| serde = { workspace = true, features = ["derive"] } | ||
| hex = { workspace = true } | ||
| parity-scale-codec = { workspace = true } | ||
| sp-api = { workspace = true } | ||
| sp-blockchain = { workspace = true } | ||
| sp-runtime = { workspace = true } | ||
| pallet-robonomics-cps = { path = "..", default-features = false, features = ["offchain-indexer"] } | ||
| pallet-robonomics-cps-rpc-runtime-api = { path = "./runtime-api", default-features = false } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "parity-scale-codec/std", | ||
| "sp-api/std", | ||
| "sp-runtime/std", | ||
| "pallet-robonomics-cps/std", | ||
| "pallet-robonomics-cps-rpc-runtime-api/std", | ||
| ] | ||
| offchain-indexer = ["pallet-robonomics-cps/offchain-indexer"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
| name = "pallet-robonomics-cps-rpc-runtime-api" | ||
| description = "Runtime API for Robonomics CPS Indexer" | ||
| version = "0.1.0" | ||
| authors.workspace = true | ||
| edition.workspace = true | ||
| homepage.workspace = true | ||
| repository.workspace = true | ||
| license = "Apache-2.0" | ||
|
|
||
| [dependencies] | ||
| parity-scale-codec = { workspace = true } | ||
| sp-api = { workspace = true } | ||
| sp-std = { workspace = true } | ||
| pallet-robonomics-cps = { path = "../..", default-features = false } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "parity-scale-codec/std", | ||
| "sp-api/std", | ||
| "sp-std/std", | ||
| "pallet-robonomics-cps/std", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| // | ||
| // Copyright 2018-2025 Robonomics Network <research@robonomics.network> | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| //! Runtime API for CPS Offchain Indexer | ||
| //! | ||
| //! This API provides access to historical CPS data collected by the offchain worker. | ||
|
|
||
| #![cfg_attr(not(feature = "std"), no_std)] | ||
|
|
||
| use sp_std::vec::Vec; | ||
|
|
||
| // Re-export the storage types for use in runtime API implementations | ||
| pub use pallet_robonomics_cps::NodeId; | ||
|
|
||
| #[cfg(feature = "std")] | ||
| pub use pallet_robonomics_cps::offchain::storage::{MetaRecord, PayloadRecord, NodeOperation}; | ||
|
|
||
| sp_api::decl_runtime_apis! { | ||
| /// Runtime API for querying indexed CPS data | ||
| pub trait CpsIndexerApi { | ||
| /// Get meta records within optional time range | ||
| /// | ||
| /// # Arguments | ||
| /// * `from` - Start timestamp (inclusive), None for all | ||
| /// * `to` - End timestamp (inclusive), None for all | ||
| /// * `node_id` - Optional node_id filter | ||
| /// | ||
| /// # Returns | ||
| /// Vector of encoded MetaRecord structures | ||
| fn get_meta_records(from: Option<u64>, to: Option<u64>, node_id: Option<NodeId>) -> Vec<Vec<u8>>; | ||
|
|
||
| /// Get payload records within optional time range | ||
| /// | ||
| /// # Arguments | ||
| /// * `from` - Start timestamp (inclusive), None for all | ||
| /// * `to` - End timestamp (inclusive), None for all | ||
| /// * `node_id` - Optional node_id filter | ||
| /// | ||
| /// # Returns | ||
| /// Vector of encoded PayloadRecord structures | ||
| fn get_payload_records(from: Option<u64>, to: Option<u64>, node_id: Option<NodeId>) -> Vec<Vec<u8>>; | ||
|
|
||
| /// Get node operations within optional time range | ||
| /// | ||
| /// # Arguments | ||
| /// * `from` - Start timestamp (inclusive), None for all | ||
| /// * `to` - End timestamp (inclusive), None for all | ||
| /// * `node_id` - Optional node_id filter | ||
| /// | ||
| /// # Returns | ||
| /// Vector of encoded NodeOperation structures | ||
| fn get_node_operations(from: Option<u64>, to: Option<u64>, node_id: Option<NodeId>) -> Vec<Vec<u8>>; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.