Skip to content

Commit

Permalink
feat: add sov-modules-core (#1126)
Browse files Browse the repository at this point in the history
* feat: add sov-modules-core

This commit introduces `sov-modules-core`, a new workspace member that
will contain the required declarations for `no-std` `DispatchCall`
runtime message declarations.

The new module is re-exported via `sov-state` and `sov-modules-api` to
minimize breaking changes downstream.

Finally, it introduces a `RefCount` in `sov-rollup-interface` that will
contain atomic synchronization, if the compile target contains atomic
pointers. It safely fallback to `Rc`, that is a reference count without
atomic synchronization, but equivalent API, that will be the used type
on targets without synchronization. This can replace all the `Arc`
instances in the future, but for now, it is required only for the
previously `sov-state` storage/cache keys and values, so the `Storage`
trait can be properly defined.

* fix broken docs

* fix alloc vec

* move ModuleInfo & Genesis to sov-modules-core

* add sov-modules-core readme

* add mandatory documentation for core

* uniform style for sov-state borsh

* mod hierarchy for sov-core

* add docs for jmt version on core
  • Loading branch information
vlopes11 authored Nov 2, 2023
1 parent b8a0642 commit e6807ed
Show file tree
Hide file tree
Showing 76 changed files with 2,657 additions and 2,355 deletions.
35 changes: 25 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ members = [
"module-system/sov-modules-stf-template",
"module-system/sov-modules-rollup-template",
"module-system/sov-modules-macros",
"module-system/sov-modules-core",
"module-system/sov-state",
"module-system/sov-modules-api",
"module-system/module-schemas",
"module-system/utils/sov-first-read-last-write-cache",
"module-system/utils/sov-data-generators",
"module-system/module-implementations/sov-accounts",
"module-system/module-implementations/sov-bank",
Expand Down Expand Up @@ -89,8 +89,8 @@ sha2 = { version = "0.10.6", default-features = false }
thiserror = "1.0.50"
tiny-keccak = "2.0.2"
tracing = { version = "0.1.40", default-features = false }
bech32 = "0.9.1"
derive_more = "0.99.11"
bech32 = { version = "0.9.1", default-features = false }
derive_more = { version = "0.99.11", default-features = false }
clap = { version = "4.4.7", features = ["derive"] }
toml = "0.8.0"
jsonrpsee = { version = "0.20.1", features = ["jsonrpsee-types"] }
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ check-fuzz: ## Checks that fuzz member compiles

check-no-std: ## Checks that project compiles without std
$(MAKE) -C ./rollup-interface $@
$(MAKE) -C ./module-system/sov-modules-core $@

find-unused-deps: ## Prints unused dependencies for project. Note: requires nightly
cargo +nightly udeps --all-targets --all-features
Expand Down
2 changes: 1 addition & 1 deletion adapters/celestia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false

[dependencies]
borsh = { workspace = true, features = ["bytes"] }
bech32 = { workspace = true }
bech32 = { workspace = true, default-features = true }
prost = "0.12"
# I keep this commented as a reminder to opportunity to optimze this crate for non native compilation
#tendermint = { version = "0.32", default-features = false, features = ["std"] }
Expand Down
30 changes: 21 additions & 9 deletions examples/demo-rollup/provers/risc0/guest-celestia/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions examples/demo-rollup/provers/risc0/guest-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext};
use sov_modules_api::{Context, Event, Prefix, StateMap, WorkingSet};
use sov_modules_api::{Context, Event, ModulePrefix, StateMap, WorkingSet};
use sov_state::{ProverStorage, Storage, ZkStorage};

use super::helpers::module_c;
Expand Down Expand Up @@ -51,7 +51,7 @@ fn test_state_update<C: Context>(working_set: &mut WorkingSet<C>) {
let expected_value = "some_value".to_owned();

{
let prefix = Prefix::new_storage(
let prefix = ModulePrefix::new_storage(
"integration_tests::nested_modules::helpers::module_a",
"ModuleA",
"state_1_a",
Expand All @@ -63,7 +63,7 @@ fn test_state_update<C: Context>(working_set: &mut WorkingSet<C>) {
}

{
let prefix = Prefix::new_storage(
let prefix = ModulePrefix::new_storage(
"integration_tests::nested_modules::helpers::module_b",
"ModuleB",
"state_1_b",
Expand All @@ -75,7 +75,7 @@ fn test_state_update<C: Context>(working_set: &mut WorkingSet<C>) {
}

{
let prefix = Prefix::new_storage(
let prefix = ModulePrefix::new_storage(
"integration_tests::nested_modules::helpers::module_a",
"ModuleA",
"state_1_a",
Expand Down
2 changes: 1 addition & 1 deletion module-system/module-implementations/sov-evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jsonrpsee = { workspace = true, features = [
"server",
], optional = true }
tracing = { workspace = true }
derive_more = { workspace = true }
derive_more = { workspace = true, default-features = true }
lazy_static = "1.4.0"


Expand Down
1 change: 1 addition & 0 deletions module-system/module-schemas/schemas/sov-bank.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
],
"definitions": {
"Address": {
"description": "Module address representation",
"type": "object",
"required": [
"addr"
Expand Down
7 changes: 4 additions & 3 deletions module-system/sov-modules-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ resolver = "2"
jsonrpsee = { workspace = true, optional = true }
anyhow = { workspace = true }
arbitrary = { workspace = true, optional = true }
sov-first-read-last-write-cache = { path = "../utils/sov-first-read-last-write-cache", version = "0.3" }
sov-state = { path = "../sov-state", version = "0.3" }
sov-modules-core = { path = "../sov-modules-core", version = "0.3" }
sov-rollup-interface = { path = "../../rollup-interface", version = "0.3" }
sov-modules-macros = { path = "../sov-modules-macros", version = "0.3", optional = true }
serde = { workspace = true }
Expand All @@ -25,8 +25,8 @@ proptest = { workspace = true, optional = true }
proptest-derive = { workspace = true, optional = true }
thiserror = { workspace = true }
sha2 = { workspace = true }
bech32 = { workspace = true }
derive_more = { workspace = true }
bech32 = { workspace = true, default-features = true }
derive_more = { workspace = true, default-features = true }
jmt = { workspace = true }
serde_json = { workspace = true, optional = true }
hex = { workspace = true }
Expand Down Expand Up @@ -66,6 +66,7 @@ native = [
"clap",
"jsonrpsee",
"macros",
"sov-modules-core/native",
"sov-modules-macros/native",
"sov-state/native",
]
Expand Down
37 changes: 2 additions & 35 deletions module-system/sov-modules-api/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
# `sov-modules-api`

The `sov-modules-api` crate provides essential traits for the Module System. Here are the key traits defined by the
crate:

1. The `Module` trait: Defines how to initialize and change the state of a module. This is the main trait that module
developers need to implement. The author of a module must specify:

- Configuration upon rollup deployment: This includes the `genesis()` method and the `Config` type, which determine
how the module is set up initially. Note that the initialization for logic for modules is identical to
the `Genesis` trait (described below). We blanket implement `Genesis`
for all `Module`s, but keep it as a separate trait since some other structs need to implement it as well.

- Interaction with user messages: The module must define the `call` method and the `CallMessage` type, which handle
user messages. These messages typically result in changes to the module's state.

- Gas configuration: The module may use a `GasConfig` type, annotated by `#[gas]`, that will be loaded from the
constants manifest configuration.

1. The `ModuleInfo` trait: Provides additional information related to a module. This trait is automatically derived.

1. The `Spec` trait: It defines all the types that modules are generic over. This separation allows the module logic to
be independent of concerns such as the specific storage system or concrete signature schemes used for signing rollup
transactions. Currently acceptable hashes for `Spec` should fit into 32 bytes.

1. The `Context` trait implements the `Spec` and introduces additional methods accessible within modules. Currently, it
includes the `sender()` method, which returns the address of the transaction sender. This trait will be further
extended with other useful methods, such as `batch_hash()`, and more. This crate defines also the default
implementation for the `Context` trait.

1. The `Genesis` trait: Defines how the rollup is initialized during deployment phase.

1. The `DispatchCall` trait: Defines how messages are forwarded to the appropriate module and how the call message is
executed. The implementation of this trait can be generated automatically using a macro.

1. The `GasUnit` trait: Defines how the scalar gas value is deducted from the working set. This is implemented for
`[u64; N]`, and can be customized by the user.
The `sov-modules-api` crate provides concrete implementations from the essential traits defined under
`sov-modules-core`.
Loading

0 comments on commit e6807ed

Please sign in to comment.