Skip to content

Commit a95ee7f

Browse files
authored
linera_views::Context: extract KeyValueStore functions (#3861)
## Motivation The `Context` trait currently duplicates the `ReadableKeyValue` and `WritableKeyValue` traits. ## Proposal Instead, provide direct access to the store so there's no need to pass through these calls. This shrinks the `Context` trait and its implementers quite considerably in preparation for #1948. While we're at it, factor `BaseKey` out into a separate type for the same reason. Additionally, I noticed we've maintained the `Local`/`Send` split for our traits, a distinction that we chose to abandon in the codebase in favour of conditional compilation, so I merged those. This led to some knock-on effects: - we get to remove `async-trait` in a lot of places, replacing its trait transformation functionality with `trait-variant` where necessary — this simplifies the implementation of the traits, since implementers don't need to re-iterate the `Send`ness of the trait - since we can now no longer implement things for `*Store` without implementing them for `Local*Store`, we need to be more careful about the propagation of `Send`/`Sync` traits. Notably this required making GraphQL support conditional, which could even be extended to a feature flag in the future (just by modifying `Cargo.toml` and `build.rs`, since I made use of the `with_*` alias pattern). In addition it seems that `cargo machete` detected some unused dependencies in our workspace and decided to remove them. ## 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 12424da commit a95ee7f

File tree

89 files changed

+634
-1779
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+634
-1779
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ revm-primitives = "15.2.0"
150150
rocksdb = "0.21.0"
151151
ruzstd = "0.7.1"
152152
scylla = "0.15.1"
153-
secp256k1 = { version = "0.30.0", default-features = false, features = [
154-
"alloc",
155-
"rand",
156-
"serde",
157-
] }
158153
semver = "1.0.22"
159154
serde = { version = "1.0.197", features = ["derive"] }
160155
serde-name = "0.2.1"
@@ -204,7 +199,6 @@ url = "2.4"
204199
wasm-bindgen = "0.2.92"
205200
wasm-bindgen-futures = "0.4.42"
206201
wasm-bindgen-test = "0.3.42"
207-
wasm-encoder = "0.24.1"
208202
wasm-instrument = { package = "linera-wasm-instrument", version = "0.4.0-linera.1" }
209203
wasm_thread = "0.3.0"
210204
wasmer = { package = "linera-wasmer", version = "4.4.0-linera.7", default-features = false }
@@ -213,7 +207,6 @@ wasmer-compiler-singlepass = { package = "linera-wasmer-compiler-singlepass", ve
213207
"unwind",
214208
"avx",
215209
] }
216-
wasmparser = "0.101.1"
217210
wasmtime = { version = "25.0.0", default-features = false, features = [
218211
"cranelift",
219212
"runtime",
@@ -280,9 +273,6 @@ max_combination_size = 1
280273
[profile.dev.package.linera-wasmer]
281274
opt-level = 3
282275

283-
[profile.dev.package.wasmparser]
284-
opt-level = 3
285-
286276
[profile.dev.package.wasmtime]
287277
opt-level = 3
288278

examples/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-chain/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
fn main() {
55
cfg_aliases::cfg_aliases! {
6+
web: { all(target_arch = "wasm32", feature = "web") },
67
with_testing: { any(test, feature = "test") },
78
with_metrics: { all(not(target_arch = "wasm32"), feature = "metrics") },
9+
with_graphql: { not(web) },
810
};
911
}

linera-chain/src/chain.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
sync::Arc,
99
};
1010

11-
use async_graphql::SimpleObject;
1211
use futures::stream::{self, StreamExt, TryStreamExt};
1312
use linera_base::{
1413
crypto::{CryptoHash, ValidatorPublicKey},
@@ -33,6 +32,7 @@ use linera_views::{
3332
reentrant_collection_view::ReentrantCollectionView,
3433
register_view::RegisterView,
3534
set_view::SetView,
35+
store::ReadableKeyValueStore as _,
3636
views::{ClonableView, CryptoHashView, RootView, View},
3737
};
3838
use serde::{Deserialize, Serialize};
@@ -182,7 +182,8 @@ static NUM_OUTBOXES: LazyLock<HistogramVec> = LazyLock::new(|| {
182182
const EMPTY_BLOCK_SIZE: usize = 94;
183183

184184
/// An origin, cursor and timestamp of a unskippable bundle in our inbox.
185-
#[derive(Debug, Clone, Serialize, Deserialize, async_graphql::SimpleObject)]
185+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
186+
#[derive(Debug, Clone, Serialize, Deserialize)]
186187
pub struct TimestampedBundleInInbox {
187188
/// The origin and cursor of the bundle.
188189
pub entry: BundleInInbox,
@@ -191,9 +192,8 @@ pub struct TimestampedBundleInInbox {
191192
}
192193

193194
/// An origin and cursor of a unskippable bundle that is no longer in our inbox.
194-
#[derive(
195-
Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, async_graphql::SimpleObject,
196-
)]
195+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
196+
#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
197197
pub struct BundleInInbox {
198198
/// The origin from which we received the bundle.
199199
pub origin: ChainId,
@@ -215,8 +215,12 @@ impl BundleInInbox {
215215
const TIMESTAMPBUNDLE_BUCKET_SIZE: usize = 100;
216216

217217
/// A view accessing the state of a chain.
218-
#[derive(Debug, RootView, ClonableView, SimpleObject)]
219-
#[graphql(cache_control(no_cache))]
218+
#[cfg_attr(
219+
with_graphql,
220+
derive(async_graphql::SimpleObject),
221+
graphql(cache_control(no_cache))
222+
)]
223+
#[derive(Debug, RootView, ClonableView)]
220224
pub struct ChainStateView<C>
221225
where
222226
C: Clone + Context + Send + Sync + 'static,
@@ -262,7 +266,8 @@ where
262266
}
263267

264268
/// Block-chaining state.
265-
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize, SimpleObject)]
269+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
270+
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize)]
266271
pub struct ChainTipState {
267272
/// Hash of the latest certified block in this chain, if any.
268273
pub block_hash: Option<CryptoHash>,
@@ -468,7 +473,7 @@ where
468473
pub async fn validate_incoming_bundles(&self) -> Result<(), ChainError> {
469474
let chain_id = self.chain_id();
470475
let pairs = self.inboxes.try_load_all_entries().await?;
471-
let max_stream_queries = self.context().max_stream_queries();
476+
let max_stream_queries = self.context().store().max_stream_queries();
472477
let stream = stream::iter(pairs)
473478
.map(|(origin, inbox)| async move {
474479
if let Some(bundle) = inbox.removed_bundles.front().await? {

linera-chain/src/inbox.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ static REMOVED_BUNDLES: LazyLock<HistogramVec> = LazyLock::new(|| {
6565
/// * The cursors of added bundles (resp. removed bundles) must be increasing over time.
6666
/// * Reconciliation of added and removed bundles is allowed to skip some added bundles.
6767
/// However, the opposite is not true: every removed bundle must be eventually added.
68-
#[derive(Debug, ClonableView, View, async_graphql::SimpleObject)]
68+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
69+
#[derive(Debug, ClonableView, View)]
6970
pub struct InboxStateView<C>
7071
where
7172
C: Clone + Context + Send + Sync,

linera-chain/src/manager.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
7171
use std::collections::BTreeMap;
7272

73-
use async_graphql::{ComplexObject, SimpleObject};
7473
use custom_debug_derive::Debug;
7574
use futures::future::Either;
7675
use linera_base::{
@@ -138,8 +137,8 @@ impl LockingBlock {
138137
}
139138

140139
/// The state of the certification process for a chain's next block.
141-
#[derive(Debug, View, ClonableView, SimpleObject)]
142-
#[graphql(complex)]
140+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject), graphql(complex))]
141+
#[derive(Debug, View, ClonableView)]
143142
pub struct ChainManager<C>
144143
where
145144
C: Clone + Context + Send + Sync + 'static,
@@ -149,37 +148,37 @@ where
149148
/// The seed for the pseudo-random number generator that determines the round leaders.
150149
pub seed: RegisterView<C, u64>,
151150
/// The probability distribution for choosing a round leader.
152-
#[graphql(skip)] // Derived from ownership.
151+
#[cfg_attr(with_graphql, graphql(skip))] // Derived from ownership.
153152
pub distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>,
154153
/// The probability distribution for choosing a fallback round leader.
155-
#[graphql(skip)] // Derived from validator weights.
154+
#[cfg_attr(with_graphql, graphql(skip))] // Derived from validator weights.
156155
pub fallback_distribution: RegisterView<C, Option<WeightedAliasIndex<u64>>>,
157156
/// Highest-round authenticated block that we have received and checked. If there are multiple
158157
/// proposals in the same round, this contains only the first one.
159-
#[graphql(skip)]
158+
#[cfg_attr(with_graphql, graphql(skip))]
160159
pub proposed: RegisterView<C, Option<BlockProposal>>,
161160
/// These are blobs published or read by the proposed block.
162161
pub proposed_blobs: MapView<C, BlobId, Blob>,
163162
/// Latest validated proposal that a validator may have voted to confirm. This is either the
164163
/// latest `ValidatedBlock` we have seen, or the proposal from the `Fast` round.
165-
#[graphql(skip)]
164+
#[cfg_attr(with_graphql, graphql(skip))]
166165
pub locking_block: RegisterView<C, Option<LockingBlock>>,
167166
/// These are blobs published or read by the locking block.
168167
pub locking_blobs: MapView<C, BlobId, Blob>,
169168
/// Latest leader timeout certificate we have received.
170-
#[graphql(skip)]
169+
#[cfg_attr(with_graphql, graphql(skip))]
171170
pub timeout: RegisterView<C, Option<TimeoutCertificate>>,
172171
/// Latest vote we cast to confirm a block.
173-
#[graphql(skip)]
172+
#[cfg_attr(with_graphql, graphql(skip))]
174173
pub confirmed_vote: RegisterView<C, Option<Vote<ConfirmedBlock>>>,
175174
/// Latest vote we cast to validate a block.
176-
#[graphql(skip)]
175+
#[cfg_attr(with_graphql, graphql(skip))]
177176
pub validated_vote: RegisterView<C, Option<Vote<ValidatedBlock>>>,
178177
/// Latest timeout vote we cast.
179-
#[graphql(skip)]
178+
#[cfg_attr(with_graphql, graphql(skip))]
180179
pub timeout_vote: RegisterView<C, Option<Vote<Timeout>>>,
181180
/// Fallback vote we cast.
182-
#[graphql(skip)]
181+
#[cfg_attr(with_graphql, graphql(skip))]
183182
pub fallback_vote: RegisterView<C, Option<Vote<Timeout>>>,
184183
/// The time after which we are ready to sign a timeout certificate for the current round.
185184
pub round_timeout: RegisterView<C, Option<Timestamp>>,
@@ -189,13 +188,14 @@ where
189188
/// Having a leader timeout certificate in any given round causes the next one to become
190189
/// current. Seeing a validated block certificate or a valid proposal in any round causes that
191190
/// round to become current, unless a higher one already is.
192-
#[graphql(skip)]
191+
#[cfg_attr(with_graphql, graphql(skip))]
193192
pub current_round: RegisterView<C, Round>,
194193
/// The owners that take over in fallback mode.
195194
pub fallback_owners: RegisterView<C, BTreeMap<AccountOwner, u64>>,
196195
}
197196

198-
#[ComplexObject]
197+
#[cfg(with_graphql)]
198+
#[async_graphql::ComplexObject]
199199
impl<C> ChainManager<C>
200200
where
201201
C: Context + Clone + Send + Sync + 'static,

linera-chain/src/outbox.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ const BLOCK_HEIGHT_BUCKET_SIZE: usize = 1000;
4747
/// we just send the certified blocks over and let the receivers figure out what were the
4848
/// messages for them.
4949
/// * When marking block heights as received, messages at lower heights are also marked (i.e. dequeued).
50-
#[derive(Debug, ClonableView, View, async_graphql::SimpleObject)]
50+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
51+
#[derive(Debug, ClonableView, View)]
5152
pub struct OutboxStateView<C>
5253
where
5354
C: Context + Send + Sync + 'static,

linera-chain/src/pending_blobs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
use std::collections::BTreeMap;
55

6-
use async_graphql::SimpleObject;
76
use linera_base::{
87
data_types::{Blob, Round},
98
ensure,
@@ -19,7 +18,8 @@ use linera_views::{
1918
use crate::ChainError;
2019

2120
/// The pending blobs belonging to a block that can't be processed without them.
22-
#[derive(Debug, View, ClonableView, SimpleObject)]
21+
#[cfg_attr(with_graphql, derive(async_graphql::SimpleObject))]
22+
#[derive(Debug, View, ClonableView)]
2323
pub struct PendingBlobsView<C>
2424
where
2525
C: Clone + Context + Send + Sync + 'static,

linera-execution/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn main() {
77

88
with_fs: { all(not(target_arch = "wasm32"), feature = "fs") },
99
with_metrics: { all(not(target_arch = "wasm32"), feature = "metrics") },
10+
with_graphql: { not(web) },
1011
with_testing: { any(test, feature = "test") },
1112
with_tokio_multi_thread: { not(target_arch = "wasm32") },
1213
with_wasmer: { feature = "wasmer" },

0 commit comments

Comments
 (0)