Skip to content

Commit

Permalink
Move fork module to rollup interface (#1098)
Browse files Browse the repository at this point in the history
* Move fork module to rollup interface

* Use fork manager in native

* Fix nostd

* Remove tracing dep from cargo lock of guest code

* Fix imports

* Fix udeps
  • Loading branch information
rakanalh authored Sep 4, 2024
1 parent 9feedd5 commit 63ed217
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 70 deletions.
5 changes: 1 addition & 4 deletions Cargo.lock

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

3 changes: 0 additions & 3 deletions bin/citrea/provers/risc0/guest-bitcoin/Cargo.lock

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

3 changes: 0 additions & 3 deletions bin/citrea/provers/risc0/guest-mock/Cargo.lock

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

2 changes: 1 addition & 1 deletion bin/citrea/src/rollup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::anyhow;
use async_trait::async_trait;
use citrea_fullnode::{CitreaFullnode, FullNode};
use citrea_primitives::fork::ForkManager;
use citrea_primitives::forks::FORKS;
use citrea_prover::{CitreaProver, Prover};
use citrea_sequencer::{CitreaSequencer, Sequencer, SequencerConfig};
Expand All @@ -11,6 +10,7 @@ use sov_modules_api::storage::HierarchicalStorageManager;
use sov_modules_api::Spec;
use sov_modules_rollup_blueprint::RollupBlueprint;
use sov_modules_stf_blueprint::{Runtime as RuntimeTrait, StfBlueprint};
use sov_rollup_interface::fork::ForkManager;
use sov_state::storage::NativeStorage;
use sov_stf_runner::{FullNodeConfig, InitVariant, ProverConfig};
use tokio::sync::broadcast;
Expand Down
2 changes: 1 addition & 1 deletion crates/fullnode/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use anyhow::{anyhow, bail};
use backoff::future::retry as retry_backoff;
use backoff::ExponentialBackoffBuilder;
use borsh::de::BorshDeserialize;
use citrea_primitives::fork::ForkManager;
use citrea_primitives::types::SoftConfirmationHash;
use citrea_primitives::{get_da_block_at_height, L1BlockCache, SyncError};
use jsonrpsee::core::client::Error as JsonrpseeError;
Expand All @@ -25,6 +24,7 @@ use sov_rollup_interface::da::{
BlobReaderTrait, BlockHeaderTrait, DaDataBatchProof, DaDataLightClient, DaSpec,
SequencerCommitment,
};
use sov_rollup_interface::fork::ForkManager;
use sov_rollup_interface::rpc::SoftConfirmationStatus;
use sov_rollup_interface::services::da::{DaService, SlotData};
use sov_rollup_interface::spec::SpecId;
Expand Down
3 changes: 1 addition & 2 deletions crates/fullnode/tests/runner_initialization_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::collections::HashMap;
use std::sync::Arc;

use citrea_fullnode::CitreaFullnode;
use citrea_primitives::fork::ForkManager;
use sov_db::ledger_db::LedgerDB;
use sov_mock_da::{MockAddress, MockDaConfig, MockDaService, MockDaSpec, MockValidityCond};
use sov_mock_zkvm::{MockCodeCommitment, MockZkvm};
use sov_prover_storage_manager::ProverStorageManager;
use sov_rollup_interface::fork::Fork;
use sov_rollup_interface::fork::{Fork, ForkManager};
use sov_rollup_interface::spec::SpecId;
use sov_state::DefaultStorageSpec;
use sov_stf_runner::{
Expand Down
7 changes: 0 additions & 7 deletions crates/primitives/src/fork/mod.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod constants;
mod da;
#[cfg(feature = "native")]
mod error;
pub mod fork;
pub mod forks;
pub mod types;
#[cfg(feature = "native")]
Expand Down
2 changes: 1 addition & 1 deletion crates/prover/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use anyhow::{anyhow, bail};
use backoff::exponential::ExponentialBackoffBuilder;
use backoff::future::retry as retry_backoff;
use borsh::de::BorshDeserialize;
use citrea_primitives::fork::ForkManager;
use citrea_primitives::types::SoftConfirmationHash;
use citrea_primitives::utils::merge_state_diffs;
use citrea_primitives::{get_da_block_at_height, L1BlockCache, MAX_STATEDIFF_SIZE_PROOF_THRESHOLD};
Expand All @@ -23,6 +22,7 @@ use sov_modules_api::storage::HierarchicalStorageManager;
use sov_modules_api::{BlobReaderTrait, Context, SignedSoftConfirmation, SlotData, StateDiff};
use sov_modules_stf_blueprint::StfBlueprintTrait;
use sov_rollup_interface::da::{BlockHeaderTrait, DaData, DaSpec, SequencerCommitment};
use sov_rollup_interface::fork::ForkManager;
use sov_rollup_interface::rpc::SoftConfirmationStatus;
use sov_rollup_interface::services::da::DaService;
use sov_rollup_interface::spec::SpecId;
Expand Down
2 changes: 1 addition & 1 deletion crates/sequencer/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use anyhow::{anyhow, bail};
use borsh::BorshDeserialize;
use citrea_evm::{CallMessage, Evm, RlpEvmTransaction, MIN_TRANSACTION_GAS};
use citrea_primitives::basefee::calculate_next_block_base_fee;
use citrea_primitives::fork::ForkManager;
use citrea_primitives::types::SoftConfirmationHash;
use citrea_primitives::utils::merge_state_diffs;
use citrea_primitives::MAX_STATEDIFF_SIZE_COMMITMENT_THRESHOLD;
Expand Down Expand Up @@ -38,6 +37,7 @@ use sov_modules_api::{
};
use sov_modules_stf_blueprint::StfBlueprintTrait;
use sov_rollup_interface::da::{BlockHeaderTrait, DaData, DaSpec, SequencerCommitment};
use sov_rollup_interface::fork::ForkManager;
use sov_rollup_interface::services::da::{DaService, SenderWithNotifier};
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::storage::HierarchicalStorageManager;
Expand Down
17 changes: 5 additions & 12 deletions crates/sovereign-sdk/full-node/db/sov-db/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "sov-db"
description = "A high-level DB interface for the Sovereign SDK"
license = "Apache-2.0" # This license is inherited from Aptos
edition = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = "Apache-2.0" # This license is inherited from Aptos
repository = { workspace = true }
description = "A high-level DB interface for the Sovereign SDK"

version = { workspace = true }
readme = "README.md"
Expand All @@ -16,21 +16,14 @@ resolver = "2"
[dependencies]
# Maintained by sovereign labs
jmt = { workspace = true }
sov-rollup-interface = { path = "../../../rollup-interface", features = [
"native",
] }
sov-rollup-interface = { path = "../../../rollup-interface", features = ["native"] }
sov-schema-db = { path = "../sov-schema-db" }

citrea-primitives = { path = "../../../../primitives" }

# External
anyhow = { workspace = true, default-features = true }
arbitrary = { workspace = true, optional = true }
bincode = { workspace = true }
borsh = { workspace = true, default-features = true, features = [
"bytes",
"rc",
] }
borsh = { workspace = true, default-features = true, features = ["bytes", "rc"] }
byteorder = { workspace = true, default-features = true }
hex = { workspace = true }
proptest = { workspace = true, optional = true, default-features = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::path::Path;
use std::sync::{Arc, Mutex};

use citrea_primitives::fork::ForkMigration;
use serde::de::DeserializeOwned;
use serde::Serialize;
use sov_rollup_interface::da::{DaSpec, SequencerCommitment};
use sov_rollup_interface::fork::Fork;
use sov_rollup_interface::fork::{Fork, ForkMigration};
use sov_rollup_interface::services::da::SlotData;
use sov_rollup_interface::stf::{BatchReceipt, Event, SoftConfirmationReceipt, StateDiff};
use sov_rollup_interface::zk::Proof;
Expand Down
4 changes: 0 additions & 4 deletions crates/sovereign-sdk/full-node/sov-stf-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ futures = { workspace = true, optional = true }
hex = { workspace = true }
hyper = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = ["http-client", "server"], optional = true }
num_cpus = { workspace = true }
rand = { workspace = true, optional = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand All @@ -34,9 +33,6 @@ sov-db = { path = "../db/sov-db", optional = true }
sov-modules-api = { path = "../../module-system/sov-modules-api", default-features = false }
sov-rollup-interface = { path = "../../rollup-interface" }

# Citrea-Deps
citrea-primitives = { path = "../../../primitives" }

[dev-dependencies]
sha2 = { workspace = true }
tempfile = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ sov-state = { path = "../sov-state" }
sov-zk-cycle-macros = { path = "../../utils/zk-cycle-macros", optional = true }
sov-zk-cycle-utils = { path = "../../utils/zk-cycle-utils", optional = true }

# Citrea Deps
citrea-primitives = { path = "../../../primitives" }

[features]
bench = ["sov-zk-cycle-macros", "risc0-zkvm", "risc0-zkvm-platform"]
default = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![doc = include_str!("../README.md")]

use borsh::BorshDeserialize;
use citrea_primitives::fork::ForkManager;
use itertools::Itertools;
use rs_merkle::algorithms::Sha256;
use rs_merkle::MerkleTree;
Expand All @@ -17,7 +16,7 @@ use sov_modules_api::{
};
use sov_rollup_interface::da::{DaData, SequencerCommitment};
use sov_rollup_interface::digest::Digest;
use sov_rollup_interface::fork::Fork;
use sov_rollup_interface::fork::{Fork, ForkManager};
use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation;
use sov_rollup_interface::spec::SpecId;
pub use sov_rollup_interface::stf::{BatchReceipt, TransactionReceipt};
Expand Down
35 changes: 18 additions & 17 deletions crates/sovereign-sdk/rollup-interface/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
[package]
name = "sov-rollup-interface"
description = "Defines interfaces for building rollups with the Sovereign SDK"
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
license = { workspace = true }
repository = { workspace = true }
description = "Defines interfaces for building rollups with the Sovereign SDK"

version = { workspace = true }
readme = "README.md"
resolver = "2"
exclude = [
"specs/assets/*",
"specs/assets/*",
]
readme = "README.md"
resolver = "2"

[dependencies]
arbitrary = { workspace = true, optional = true }
anyhow = { workspace = true }
arbitrary = { workspace = true, optional = true }
async-trait = { workspace = true }
borsh = { workspace = true }
bytes = { workspace = true, optional = true, default-features = true }
digest = { workspace = true }
futures = { workspace = true, optional = true }
hex = { workspace = true }
serde = { workspace = true }
sha2 = { workspace = true, optional = true }
thiserror = { workspace = true, optional = true }
futures = { workspace = true, optional = true }
# TODO: Remove tokio when https://github.com/Sovereign-Labs/sovereign-sdk/issues/1161 is resolved
tokio = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }

# Proptest should be a dev-dependency, but those can't be optional
proptest = { workspace = true, optional = true }
Expand All @@ -38,19 +39,19 @@ serde_json = { workspace = true }

[features]
default = ["std"]
native = ["std", "tokio", "futures"]
native = ["std", "tokio", "futures", "tracing"]
fuzzing = ["proptest", "proptest-derive", "sha2", "std"]
testing = ["native"]
arbitrary = ["dep:arbitrary"]
std = [
"anyhow/default",
"borsh/default",
"borsh/bytes",
"bytes",
"digest/default",
"hex/default",
"proptest?/default",
"serde/default",
"sha2?/default",
"thiserror"
"anyhow/default",
"borsh/default",
"borsh/bytes",
"bytes",
"digest/default",
"hex/default",
"proptest?/default",
"serde/default",
"sha2?/default",
"thiserror",
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use sov_rollup_interface::fork::Fork;
use alloc::boxed::Box;
use alloc::vec;
use alloc::vec::Vec;

use super::ForkMigration;
use super::{Fork, ForkMigration};

pub struct ForkManager {
forks: Vec<Fork>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use sov_rollup_interface::fork::Fork;
use super::Fork;

/// Defines the interface of a migration
pub trait ForkMigration {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#![allow(missing_docs)]

mod manager;
mod migration;
#[cfg(test)]
mod tests;

pub use manager::*;
pub use migration::*;

use crate::spec::SpecId;

/// Fork is a wrapper struct that contains spec id and it's activation height
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use anyhow::anyhow;
use sov_rollup_interface::fork::Fork;
use sov_rollup_interface::spec::SpecId;

use super::ForkManager;
use crate::fork::{fork_from_block_number, ForkMigration};
use crate::fork::{fork_from_block_number, Fork, ForkMigration};
use crate::spec::SpecId;

#[test]
fn test_fork_from_block_number() {
Expand Down

0 comments on commit 63ed217

Please sign in to comment.