Skip to content

Commit 65ac14a

Browse files
authored
Historical hash (#4683)
## Motivation Add support for historical hashing ## Proposal * Introduce a new combinator based on `ClonableView` I ended up with a solution that is entirely separate from `HashableView`. ## Test Plan CI ## Release Plan This won't be trivial to release in testnet but maybe still doable.
1 parent 816ae0c commit 65ac14a

File tree

13 files changed

+631
-22
lines changed

13 files changed

+631
-22
lines changed

linera-views/src/batch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use crate::{
3737
/// * Deletion of a specific key.
3838
/// * Deletion of all keys matching a specific prefix.
3939
/// * Insertion or replacement of a key with a value.
40-
#[derive(Clone, Debug, Eq, PartialEq, WitType, WitLoad, WitStore)]
40+
#[derive(Clone, Debug, Eq, PartialEq, WitType, WitLoad, WitStore, Serialize)]
4141
pub enum WriteOperation {
4242
/// Delete the given key.
4343
Delete {
@@ -59,7 +59,7 @@ pub enum WriteOperation {
5959
}
6060

6161
/// A batch of write operations.
62-
#[derive(Clone, Debug, Default, Eq, PartialEq)]
62+
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
6363
pub struct Batch {
6464
/// The write operations.
6565
pub operations: Vec<WriteOperation>,

linera-views/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ pub use generic_array;
124124
#[doc(hidden)]
125125
pub use sha3;
126126
pub use views::{
127-
bucket_queue_view, collection_view, hashable_wrapper, key_value_store_view, log_view, map_view,
128-
queue_view, reentrant_collection_view, register_view, set_view,
127+
bucket_queue_view, collection_view, hashable_wrapper, historical_hash_wrapper,
128+
key_value_store_view, log_view, map_view, queue_view, reentrant_collection_view, register_view,
129+
set_view,
129130
};

linera-views/src/views/bucket_queue_view.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
common::{from_bytes_option, from_bytes_option_or_default, HasherOutput},
1313
context::Context,
1414
hashable_wrapper::WrappedHashableContainerView,
15+
historical_hash_wrapper::HistoricallyHashableView,
1516
store::ReadableKeyValueStore as _,
1617
views::{ClonableView, HashableView, Hasher, View, ViewError, MIN_VIEW_TAG},
1718
};
@@ -711,6 +712,10 @@ where
711712
pub type HashedBucketQueueView<C, T, const N: usize> =
712713
WrappedHashableContainerView<C, BucketQueueView<C, T, N>, HasherOutput>;
713714

715+
/// Wrapper around `BucketQueueView` to compute hashes based on the history of changes.
716+
pub type HistoricallyHashedBucketQueueView<C, T, const N: usize> =
717+
HistoricallyHashableView<C, BucketQueueView<C, T, N>>;
718+
714719
#[cfg(with_graphql)]
715720
mod graphql {
716721
use std::borrow::Cow;

linera-views/src/views/collection_view.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::{
1919
common::{CustomSerialize, HasherOutput, SliceExt as _, Update},
2020
context::{BaseKey, Context},
2121
hashable_wrapper::WrappedHashableContainerView,
22+
historical_hash_wrapper::HistoricallyHashableView,
2223
store::ReadableKeyValueStore as _,
2324
views::{ClonableView, HashableView, Hasher, View, ViewError, MIN_VIEW_TAG},
2425
};
@@ -1784,14 +1785,26 @@ where
17841785
pub type HashedByteCollectionView<C, W> =
17851786
WrappedHashableContainerView<C, ByteCollectionView<C, W>, HasherOutput>;
17861787

1788+
/// Wrapper around `ByteCollectionView` to compute hashes based on the history of changes.
1789+
pub type HistoricallyHashedByteCollectionView<C, W> =
1790+
HistoricallyHashableView<C, ByteCollectionView<C, W>>;
1791+
17871792
/// Type wrapping `CollectionView` while memoizing the hash.
17881793
pub type HashedCollectionView<C, I, W> =
17891794
WrappedHashableContainerView<C, CollectionView<C, I, W>, HasherOutput>;
17901795

1796+
/// Wrapper around `CollectionView` to compute hashes based on the history of changes.
1797+
pub type HistoricallyHashedCollectionView<C, I, W> =
1798+
HistoricallyHashableView<C, CollectionView<C, I, W>>;
1799+
17911800
/// Type wrapping `CustomCollectionView` while memoizing the hash.
17921801
pub type HashedCustomCollectionView<C, I, W> =
17931802
WrappedHashableContainerView<C, CustomCollectionView<C, I, W>, HasherOutput>;
17941803

1804+
/// Wrapper around `CustomCollectionView` to compute hashes based on the history of changes.
1805+
pub type HistoricallyHashedCustomCollectionView<C, I, W> =
1806+
HistoricallyHashableView<C, CustomCollectionView<C, I, W>>;
1807+
17951808
#[cfg(with_graphql)]
17961809
mod graphql {
17971810
use std::borrow::Cow;

linera-views/src/views/hashable_wrapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
views::{ClonableView, HashableView, Hasher, ReplaceContext, View, ViewError, MIN_VIEW_TAG},
1717
};
1818

19-
/// A hash for `ContainerView` and storing of the hash for memoization purposes
19+
/// Wrapping a view to memoize its hash.
2020
#[derive(Debug)]
2121
pub struct WrappedHashableContainerView<C, W, O> {
2222
_phantom: PhantomData<C>,
@@ -25,7 +25,7 @@ pub struct WrappedHashableContainerView<C, W, O> {
2525
inner: W,
2626
}
2727

28-
/// Key tags to create the sub-keys of a `MapView` on top of the base key.
28+
/// Key tags to create the sub-keys of a `WrappedHashableContainerView` on top of the base key.
2929
#[repr(u8)]
3030
enum KeyTag {
3131
/// Prefix for the indices of the view.

0 commit comments

Comments
 (0)