Skip to content

Commit aee5dec

Browse files
authored
linera-persistent: move out of linera-client (#4002)
## Motivation We'd like to push `persistent` further down the stack (in preparation for [removing it](#3974)) so let's extract it into its own crate for now. ## Proposal Extract it into a separate crate. ## Test Plan CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent ebcf07c commit aee5dec

File tree

28 files changed

+126
-66
lines changed

28 files changed

+126
-66
lines changed

Cargo.lock

Lines changed: 25 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"linera-indexer/graphql-client",
1414
"linera-indexer/lib",
1515
"linera-indexer/plugins",
16+
"linera-persistent",
1617
"linera-rpc",
1718
"linera-sdk",
1819
"linera-sdk-derive",
@@ -205,11 +206,6 @@ revm-state = { version = "4.0.0", default-features = false, features = [
205206
rocksdb = "0.21.0"
206207
ruzstd = "0.7.1"
207208
scylla = "1.1.0"
208-
secp256k1 = { version = "0.30.0", default-features = false, features = [
209-
"alloc",
210-
"rand",
211-
"serde",
212-
] }
213209
semver = "1.0.22"
214210
serde = { version = "1.0.197", features = ["derive"] }
215211
serde-command-opts = "0.1.1"

docker/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ COPY linera-service-graphql-client linera-service-graphql-client
5757
COPY linera-storage linera-storage
5858
COPY linera-storage-service linera-storage-service
5959
COPY linera-summary linera-summary
60+
COPY linera-persistent linera-persistent
6061
COPY linera-version linera-version
6162
COPY linera-views linera-views
6263
COPY linera-views-derive linera-views-derive

linera-client/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ wasmer = [
2828
"linera-storage/wasmer",
2929
]
3030
wasmtime = ["linera-execution/wasmtime", "linera-storage/wasmtime"]
31-
fs = ["fs-err", "fs4", "linera-execution/fs"]
31+
fs = ["fs-err", "fs4", "linera-execution/fs", "linera-persistent/fs"]
3232
metrics = [
3333
"linera-base/metrics",
3434
"linera-chain/metrics",
@@ -41,29 +41,29 @@ web = [
4141
"dep:web-sys",
4242
"dep:wasm-bindgen-futures",
4343
"linera-base/web",
44-
"linera-storage/web",
44+
"linera-execution/web",
4545
"linera-chain/web",
4646
"linera-client/web",
4747
"linera-core/web",
48-
"linera-views/web",
49-
"linera-execution/web",
48+
"linera-persistent/indexed-db",
5049
"linera-rpc/web",
50+
"linera-storage/web",
51+
"linera-views/web",
5152
]
5253
indexed-db = ["web", "indexed_db_futures", "serde-wasm-bindgen", "gloo-utils"]
5354
web-default = ["web", "wasmer", "indexed-db"]
5455

5556
[dependencies]
5657
anyhow = { workspace = true, optional = true }
5758
bcs.workspace = true
58-
cfg-if.workspace = true
5959
clap.workspace = true
6060
crossbeam-channel = { workspace = true, optional = true }
61-
derive_more = { workspace = true, features = ["deref", "deref_mut"] }
6261
futures.workspace = true
6362
linera-base.workspace = true
6463
linera-chain.workspace = true
6564
linera-core.workspace = true
6665
linera-execution.workspace = true
66+
linera-persistent = { version = "0.15.0", path = "../linera-persistent" }
6767
linera-rpc.workspace = true
6868
linera-sdk = { workspace = true, optional = true }
6969
linera-storage.workspace = true
@@ -73,7 +73,6 @@ num-format = { workspace = true, optional = true }
7373
prometheus-parse = { workspace = true, optional = true }
7474
reqwest = { workspace = true, optional = true }
7575
serde.workspace = true
76-
serde_json.workspace = true
7776
thiserror.workspace = true
7877
thiserror-context.workspace = true
7978
tokio.workspace = true

linera-client/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
fn main() {
55
cfg_aliases::cfg_aliases! {
66
web: { all(target_arch = "wasm32", feature = "web") },
7-
with_persist: { any(feature = "fs", with_indexed_db) },
8-
with_indexed_db: { all(web, feature = "indexed-db") },
97
with_testing: { any(test, feature = "test") },
108
with_metrics: { all(not(target_arch = "wasm32"), feature = "metrics") },
119
};

linera-client/src/client_context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use linera_core::{
2121
node::{CrossChainMessageDelivery, ValidatorNode},
2222
Environment, JoinSetExt as _,
2323
};
24+
use linera_persistent::{Persist, PersistExt as _};
2425
use linera_rpc::node_provider::{NodeOptions, NodeProvider};
2526
use linera_version::VersionInfo;
2627
use thiserror_context::Context;
@@ -57,9 +58,7 @@ use {
5758
use crate::{
5859
chain_listener::{self, ClientContext as _, ClientContextExt as _},
5960
client_options::{ChainOwnershipConfig, ClientContextOptions},
60-
error,
61-
persistent::{Persist, PersistExt as _},
62-
util,
61+
error, util,
6362
wallet::{UserChain, Wallet},
6463
Error,
6564
};

linera-client/src/client_options.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ use linera_base::{
1212
use linera_core::{client::BlanketMessagePolicy, DEFAULT_GRACE_PERIOD};
1313
use linera_execution::ResourceControlPolicy;
1414

15-
#[cfg(any(with_indexed_db, not(with_persist)))]
16-
use crate::wallet::Wallet;
17-
use crate::{persistent, util};
15+
use crate::util;
1816

1917
#[derive(Debug, thiserror::Error)]
2018
pub enum Error {
2119
#[error("I/O error: {0}")]
2220
IoError(#[from] std::io::Error),
23-
#[error("no wallet found")]
24-
NonexistentWallet,
2521
#[error("there are {public_keys} public keys but {weights} weights")]
2622
MisalignedWeights { public_keys: usize, weights: usize },
2723
#[error("persistence error: {0}")]
@@ -31,10 +27,10 @@ pub enum Error {
3127
}
3228

3329
#[cfg(feature = "fs")]
34-
util::impl_from_dynamic!(Error:Persistence, persistent::file::Error);
30+
util::impl_from_dynamic!(Error:Persistence, linera_persistent::file::Error);
3531

36-
#[cfg(with_indexed_db)]
37-
util::impl_from_dynamic!(Error:Persistence, persistent::indexed_db::Error);
32+
#[cfg(web)]
33+
util::impl_from_dynamic!(Error:Persistence, linera_persistent::indexed_db::Error);
3834

3935
util::impl_from_infallible!(Error);
4036

@@ -116,24 +112,6 @@ pub struct ClientContextOptions {
116112
pub blob_download_timeout: Duration,
117113
}
118114

119-
#[cfg(with_indexed_db)]
120-
impl ClientContextOptions {
121-
pub async fn wallet(&self) -> Result<persistent::IndexedDb<Wallet>, Error> {
122-
persistent::IndexedDb::read("linera-wallet")
123-
.await?
124-
.ok_or(Error::NonexistentWallet)
125-
}
126-
}
127-
128-
#[cfg(not(with_persist))]
129-
impl ClientContextOptions {
130-
pub async fn wallet(&self) -> Result<persistent::Memory<Wallet>, Error> {
131-
#![allow(unreachable_code)]
132-
let _wallet = unimplemented!("No persistence backend selected for wallet; please use one of the `fs` or `indexed-db` features");
133-
Ok(persistent::Memory::new(_wallet))
134-
}
135-
}
136-
137115
#[derive(Debug, Clone, clap::Args)]
138116
pub struct ChainOwnershipConfig {
139117
/// The new super owners.

linera-client/src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use linera_execution::{
1717
committee::{Committee, ValidatorState},
1818
ResourceControlPolicy,
1919
};
20+
use linera_persistent as persistent;
2021
use linera_rpc::config::{
2122
ExporterServiceConfig, ValidatorInternalNetworkConfig, ValidatorPublicNetworkConfig,
2223
};
@@ -37,10 +38,10 @@ pub enum Error {
3738
NoAdminChain,
3839
}
3940

40-
use crate::{persistent, util};
41+
use crate::util;
4142

4243
util::impl_from_dynamic!(Error:Persistence, persistent::memory::Error);
43-
#[cfg(with_indexed_db)]
44+
#[cfg(web)]
4445
util::impl_from_dynamic!(Error:Persistence, persistent::indexed_db::Error);
4546
#[cfg(feature = "fs")]
4647
util::impl_from_dynamic!(Error:Persistence, persistent::file::Error);

linera-client/src/error.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use linera_base::{
55
crypto::ValidatorPublicKey, data_types::NetworkDescription, identifiers::ChainId,
66
};
77
use linera_core::node::NodeError;
8+
use linera_persistent as persistent;
89
use linera_version::VersionInfo;
910
use thiserror_context::Context;
1011

1112
#[cfg(feature = "benchmark")]
1213
use crate::benchmark::BenchmarkError;
13-
use crate::{persistent, util};
14+
use crate::util;
1415

1516
#[derive(Debug, thiserror::Error)]
1617
#[non_exhaustive]
@@ -77,5 +78,5 @@ thiserror_context::impl_context!(Error(Inner));
7778
util::impl_from_dynamic!(Inner:Persistence, persistent::memory::Error);
7879
#[cfg(feature = "fs")]
7980
util::impl_from_dynamic!(Inner:Persistence, persistent::file::Error);
80-
#[cfg(with_indexed_db)]
81+
#[cfg(web)]
8182
util::impl_from_dynamic!(Inner:Persistence, persistent::indexed_db::Error);

linera-client/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub mod client_context;
1212
pub mod client_options;
1313
pub mod config;
1414
mod error;
15-
pub mod persistent;
1615
pub mod util;
1716
pub mod wallet;
1817

0 commit comments

Comments
 (0)