-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fault_proving(global_roots): service definition and initial tests #2722
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
Merged
netrome
merged 8 commits into
master
from
2707-fault_provingglobal_roots-service-definition-and-integration-tests
Feb 19, 2025
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
46afa90
refactor: rename `fraud_proofs` folder to `proof_system`
netrome 356deb4
chore: Scaffold service crate
netrome e4602f7
feat: Add tracing and missing docs
netrome 12edd22
chore: Update CHANGELOG
netrome 79ef630
chore: Appease Clippy-sama
netrome cfa53f3
fix: Fix build with all features enabled
netrome f5cc2e2
chore: Upgrade crate versions
netrome ad2108c
refactor: Use `new_service` function instead of wrapper struct
netrome 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| [package] | ||
| authors = { workspace = true } | ||
| categories = ["cryptography::cryptocurrencies"] | ||
| description = "Service definition for the global merkle root service." | ||
| edition = { workspace = true } | ||
| homepage = { workspace = true } | ||
| keywords = ["blockchain", "cryptocurrencies", "fuel-client", "fuel-core"] | ||
| license = { workspace = true } | ||
| name = "fuel-core-global-merkle-root-service" | ||
| repository = { workspace = true } | ||
| version = { workspace = true } | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| async-trait = { workspace = true } | ||
| fuel-core-global-merkle-root-storage = { workspace = true } | ||
| fuel-core-services = { workspace = true } | ||
| fuel-core-storage = { workspace = true, features = ["alloc"] } | ||
| fuel-core-types = { workspace = true, default-features = false, features = [ | ||
| "serde", | ||
| "alloc", | ||
| ] } | ||
| tokio = { workspace = true } | ||
| tracing = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| derive_more = { workspace = true } | ||
| fuel-core-global-merkle-root-storage = { workspace = true, features = [ | ||
| "test-helpers", | ||
| ] } | ||
| fuel-core-storage = { workspace = true, features = ["alloc", "test-helpers"] } | ||
| fuel-core-types = { workspace = true, default-features = false, features = [ | ||
| "serde", | ||
| "random", | ||
| "test-helpers", | ||
| ] } | ||
| rand = { workspace = true } | ||
|
|
||
| [features] | ||
| fault-proving = [ | ||
| "fuel-core-types/fault-proving", | ||
| "fuel-core-storage/fault-proving", | ||
| "fuel-core-global-merkle-root-storage/fault-proving", | ||
| ] |
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,16 @@ | ||
| //! The state root service | ||
|
|
||
| #![deny(clippy::arithmetic_side_effects)] | ||
| #![deny(clippy::cast_possible_truncation)] | ||
| #![deny(unused_crate_dependencies)] | ||
| #![deny(missing_docs)] | ||
| #![deny(warnings)] | ||
|
|
||
| /// Port definitions | ||
| pub mod ports; | ||
|
|
||
| /// Service definition | ||
| pub mod service; | ||
|
|
||
| #[cfg(test)] | ||
| mod tests; |
22 changes: 22 additions & 0 deletions
22
crates/proof_system/global_merkle_root/service/src/ports.rs
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,22 @@ | ||
| use std::future::Future; | ||
|
|
||
| use fuel_core_global_merkle_root_storage::column::Column; | ||
| use fuel_core_storage::{ | ||
| kv_store::KeyValueInspect, | ||
| transactional::Modifiable, | ||
| }; | ||
| use fuel_core_types::blockchain::block::Block; | ||
|
|
||
| /// A stream of blocks | ||
| pub trait BlockStream { | ||
| /// Error type | ||
| type Error; | ||
|
|
||
| /// Get the next block | ||
| fn next(&mut self) -> impl Future<Output = Result<Block, Self::Error>> + Send; | ||
| } | ||
|
|
||
| /// The storage requirements for the merkle root service | ||
| pub trait ServiceStorage: KeyValueInspect<Column = Column> + Modifiable {} | ||
|
|
||
| impl<T> ServiceStorage for T where T: KeyValueInspect<Column = Column> + Modifiable {} |
138 changes: 138 additions & 0 deletions
138
crates/proof_system/global_merkle_root/service/src/service.rs
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,138 @@ | ||
| use std::ops::Deref; | ||
|
|
||
| use fuel_core_global_merkle_root_storage::update::UpdateMerkleizedTables; | ||
| use fuel_core_services::{ | ||
| RunnableService, | ||
| RunnableTask, | ||
| ServiceRunner, | ||
| StateWatcher, | ||
| TaskNextAction, | ||
| }; | ||
| use fuel_core_storage::transactional::WriteTransaction; | ||
| use fuel_core_types::fuel_types::ChainId; | ||
|
|
||
| use crate::ports::{ | ||
| BlockStream, | ||
| ServiceStorage, | ||
| }; | ||
|
|
||
| /// Service definition as a thin wrapper over `ServiceRunner`. | ||
| pub struct Service<B, S>(ServiceRunner<UpdateMerkleRootTask<B, S>>) | ||
netrome marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| where | ||
| B: BlockStream + Send + 'static, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage + Send + 'static; | ||
netrome marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl<B, S> Service<B, S> | ||
| where | ||
| B: BlockStream + Send + 'static, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage + Send + 'static, | ||
| { | ||
| /// Construct a new service. | ||
| pub fn new(chain_id: ChainId, storage: S, blocks: B) -> Self { | ||
| Self(ServiceRunner::new(UpdateMerkleRootTask::new( | ||
| chain_id, storage, blocks, | ||
| ))) | ||
| } | ||
| } | ||
netrome marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| impl<B, S> Deref for Service<B, S> | ||
| where | ||
| B: BlockStream + Send + 'static, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage + Send + 'static, | ||
| { | ||
| type Target = ServiceRunner<UpdateMerkleRootTask<B, S>>; | ||
|
|
||
| fn deref(&self) -> &Self::Target { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| /// The inner task definition. Holds the state of the service. | ||
| pub struct UpdateMerkleRootTask<BlockStream, Storage> { | ||
| chain_id: ChainId, | ||
| storage: Storage, | ||
| blocks: BlockStream, | ||
| } | ||
|
|
||
| impl<B, S> UpdateMerkleRootTask<B, S> { | ||
| /// Create a new task | ||
| pub fn new(chain_id: ChainId, storage: S, blocks: B) -> Self { | ||
| Self { | ||
| chain_id, | ||
| storage, | ||
| blocks, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl<B, S> RunnableService for UpdateMerkleRootTask<B, S> | ||
| where | ||
| B: BlockStream + Send, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage + Send, | ||
| { | ||
| const NAME: &'static str = "MerkleRootService"; | ||
|
|
||
| type SharedData = (); | ||
|
|
||
| type Task = Self; | ||
|
|
||
| type TaskParams = (); | ||
|
|
||
| fn shared_data(&self) -> Self::SharedData {} | ||
|
|
||
| async fn into_task( | ||
| self, | ||
| _state_watcher: &StateWatcher, | ||
| _params: Self::TaskParams, | ||
| ) -> anyhow::Result<Self::Task> { | ||
| Ok(self) | ||
| } | ||
| } | ||
|
|
||
| impl<B, S> RunnableTask for UpdateMerkleRootTask<B, S> | ||
| where | ||
| B: BlockStream + Send, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage + Send, | ||
| { | ||
| #[tracing::instrument(skip(self, watcher))] | ||
| async fn run(&mut self, watcher: &mut StateWatcher) -> TaskNextAction { | ||
| tokio::select! { | ||
| biased; | ||
| _ = watcher.while_started() => { | ||
| TaskNextAction::Stop | ||
| } | ||
| _ = self.process_next_block() => { | ||
| TaskNextAction::Continue | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async fn shutdown(self) -> anyhow::Result<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| impl<B, S> UpdateMerkleRootTask<B, S> | ||
| where | ||
| B: BlockStream, | ||
| B::Error: std::error::Error + Send + Sync + 'static, | ||
| S: ServiceStorage, | ||
| { | ||
| #[tracing::instrument(skip(self))] | ||
| async fn process_next_block(&mut self) -> anyhow::Result<()> { | ||
| let block = self.blocks.next().await?; | ||
| let mut tx = self.storage.write_transaction(); | ||
|
|
||
| tx.update_merkleized_tables(self.chain_id, &block)?; | ||
|
|
||
| tx.commit()?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
Oops, something went wrong.
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.