Skip to content

Commit 65ca0bf

Browse files
authored
Merge pull request #147 from cowlicks/use-hypercore-schema
Use `hypercore_schema` crate
2 parents 65738ce + fc4a63b commit 65ca0bf

30 files changed

Lines changed: 245 additions & 999 deletions

.clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
avoid-breaking-exported-api = false

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Added
1313

14+
* Added some new clippy lints to enforce.
15+
16+
### Changed
17+
18+
* `get_random_access` was renamed to `get_random_access_mut`.
19+
* Bumped to 2024 edition.
20+
* Structs that were shared with `hypercore-protocol` have been moved into a separate crate: `hypercore_schema`.
21+
* Dependencies update
22+
* Some function signatures were changed that were pass-by-value or pass-by-ref that didn't need to be.
23+
24+
### Removed
25+
26+
27+
28+
## [0.15.0] - 2025-12-25
29+
30+
### Added
31+
1432
* More impl's of `CompactEncoding`.
1533

1634
### Changed
@@ -480,5 +498,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
480498
```
481499

482500
<!-- next-url -->
483-
[Unreleased]: https://github.com/datrs/hypercore/compare/v0.14.0...HEAD
501+
[Unreleased]: https://github.com/datrs/hypercore/compare/v0.15.0...HEAD
502+
[0.15.0]: https://github.com/datrs/hypercore/compare/v0.14.0...v0.15.0
484503
[0.14.0]: https://github.com/datrs/hypercore/compare/v0.14.0...v0.13.0

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hypercore"
3-
version = "0.14.0"
3+
version = "0.15.0"
44
license = "MIT OR Apache-2.0"
55
description = "Secure, distributed, append-only log"
66
documentation = "https://docs.rs/hypercore"
@@ -18,7 +18,7 @@ categories = [
1818
"data-structures",
1919
"encoding",
2020
]
21-
edition = "2021"
21+
edition = "2024"
2222

2323
[dependencies]
2424
blake2 = "0.10"
@@ -42,6 +42,9 @@ moka = { version = "0.12", optional = true, features = ["sync"] }
4242
async-broadcast = { version = "0.7.1", optional = true }
4343
async-lock = {version = "3.4.0", optional = true }
4444

45+
[dependencies.hypercore_schema]
46+
version = "0.2.0"
47+
4548
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4649
random-access-disk = { version = "3", default-features = false }
4750

@@ -61,7 +64,7 @@ test-log = { version = "0.2.11", default-features = false, features = ["trace"]
6164
tracing-subscriber = { version = "0.3.16", features = ["env-filter", "fmt"] }
6265

6366
[features]
64-
default = ["tokio", "sparse", "replication"]
67+
default = ["tokio", "sparse", "replication", "cache"]
6568
replication = ["dep:async-broadcast"]
6669
shared-core = ["replication", "dep:async-lock"]
6770
sparse = ["random-access-disk/sparse"]

benches/disk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::{Duration, Instant};
22

33
#[cfg(feature = "async-std")]
44
use criterion::async_executor::AsyncStdExecutor;
5-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
66
use hypercore::{Hypercore, HypercoreBuilder, HypercoreError, Storage};
77
use tempfile::Builder as TempfileBuilder;
88

benches/memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::time::{Duration, Instant};
22

33
#[cfg(feature = "async-std")]
44
use criterion::async_executor::AsyncStdExecutor;
5-
use criterion::{black_box, criterion_group, criterion_main, Criterion};
5+
use criterion::{Criterion, black_box, criterion_group, criterion_main};
66
use hypercore::{Hypercore, HypercoreBuilder, HypercoreError, Storage};
77
use random_access_memory::RandomAccessMemory;
88

examples/replication.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#[cfg(feature = "async-std")]
22
use async_std::main as async_main;
3-
use hypercore::{
4-
Hypercore, HypercoreBuilder, HypercoreError, PartialKeypair, RequestBlock, RequestUpgrade,
5-
Storage,
6-
};
3+
use hypercore::{Hypercore, HypercoreBuilder, HypercoreError, PartialKeypair, Storage};
4+
use hypercore_schema::{RequestBlock, RequestUpgrade};
75
use tempfile::Builder;
86
#[cfg(feature = "tokio")]
97
use tokio::main as async_main;
@@ -99,10 +97,12 @@ async fn replicate_index(
9997
.expect("Creating proof error")
10098
.expect("Could not get proof");
10199
// Then the proof is verified and applied to the replicated party.
102-
assert!(replicated_hypercore
103-
.verify_and_apply_proof(&proof)
104-
.await
105-
.expect("Verifying and applying proof failed"));
100+
assert!(
101+
replicated_hypercore
102+
.verify_and_apply_proof(&proof)
103+
.await
104+
.expect("Verifying and applying proof failed")
105+
);
106106
}
107107

108108
fn format_res(res: Result<Option<Vec<u8>>, HypercoreError>) -> String {

src/bitfield/dynamic.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use super::fixed::{FixedBitfield, FIXED_BITFIELD_BITS_LENGTH, FIXED_BITFIELD_LENGTH};
1+
use super::fixed::{FIXED_BITFIELD_BITS_LENGTH, FIXED_BITFIELD_LENGTH, FixedBitfield};
22
use crate::{
3-
common::{BitfieldUpdate, StoreInfo, StoreInfoInstruction, StoreInfoType},
43
Store,
4+
common::{BitfieldUpdate, StoreInfo, StoreInfoInstruction, StoreInfoType},
55
};
66
use futures::future::Either;
77
use std::{cell::RefCell, convert::TryInto};
@@ -176,22 +176,22 @@ impl DynamicBitfield {
176176
// not pages that don't exist, as they can't possibly contain the value.
177177

178178
// To keep the common case fast, first try the same page as the position
179-
if let Some(p) = self.pages.get(first_page) {
180-
if let Some(index) = p.borrow().index_of(value, first_index as u32) {
181-
return Some(first_page * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
182-
};
183-
}
179+
if let Some(p) = self.pages.get(first_page)
180+
&& let Some(index) = p.borrow().index_of(value, first_index as u32)
181+
{
182+
return Some(first_page * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
183+
};
184184

185185
// It wasn't found on the first page, now get the keys that are bigger
186186
// than the given index and sort them.
187187
let mut keys: Vec<&u64> = self.pages.keys().filter(|key| **key > first_page).collect();
188188
keys.sort();
189189
for key in keys {
190-
if let Some(p) = self.pages.get(*key) {
191-
if let Some(index) = p.borrow().index_of(value, 0) {
192-
return Some(key * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
193-
};
194-
}
190+
if let Some(p) = self.pages.get(*key)
191+
&& let Some(index) = p.borrow().index_of(value, 0)
192+
{
193+
return Some(key * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
194+
};
195195
}
196196
} else {
197197
// Searching for the false value is easier as it is automatically hit on
@@ -223,11 +223,11 @@ impl DynamicBitfield {
223223
// not pages that don't exist, as they can't possibly contain the value.
224224

225225
// To keep the common case fast, first try the same page as the position
226-
if let Some(p) = self.pages.get(last_page) {
227-
if let Some(index) = p.borrow().last_index_of(value, last_index as u32) {
228-
return Some(last_page * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
229-
};
230-
}
226+
if let Some(p) = self.pages.get(last_page)
227+
&& let Some(index) = p.borrow().last_index_of(value, last_index as u32)
228+
{
229+
return Some(last_page * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
230+
};
231231

232232
// It wasn't found on the last page, now get the keys that are smaller
233233
// than the given index and sort them.
@@ -236,14 +236,13 @@ impl DynamicBitfield {
236236
keys.reverse();
237237

238238
for key in keys {
239-
if let Some(p) = self.pages.get(*key) {
240-
if let Some(index) = p
239+
if let Some(p) = self.pages.get(*key)
240+
&& let Some(index) = p
241241
.borrow()
242242
.last_index_of(value, FIXED_BITFIELD_BITS_LENGTH as u32 - 1)
243-
{
244-
return Some(key * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
245-
};
246-
}
243+
{
244+
return Some(key * DYNAMIC_BITFIELD_PAGE_SIZE as u64 + index as u64);
245+
};
247246
}
248247
} else {
249248
// Searching for the false value is easier as it is automatically hit on

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tracing::instrument;
55

66
#[cfg(feature = "cache")]
77
use crate::common::cache::CacheOptions;
8-
use crate::{core::HypercoreOptions, Hypercore, HypercoreError, PartialKeypair, Storage};
8+
use crate::{Hypercore, HypercoreError, PartialKeypair, Storage, core::HypercoreOptions};
99

1010
/// Build CacheOptions.
1111
#[cfg(feature = "cache")]

src/common/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use moka::sync::Cache;
22
use std::time::Duration;
33

4-
use crate::Node;
4+
use hypercore_schema::Node;
55

66
// Default to 1 year of cache
77
const DEFAULT_CACHE_TTL_SEC: u64 = 31556952;

src/common/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@ mod peer;
66
mod store;
77

88
pub use self::error::HypercoreError;
9-
pub use self::node::Node;
109
pub(crate) use self::node::NodeByteRange;
1110
pub(crate) use self::peer::ValuelessProof;
12-
pub use self::peer::{
13-
DataBlock, DataHash, DataSeek, DataUpgrade, Proof, RequestBlock, RequestSeek, RequestUpgrade,
14-
};
1511
pub use self::store::Store;
1612
pub(crate) use self::store::{StoreInfo, StoreInfoInstruction, StoreInfoType};
1713

0 commit comments

Comments
 (0)