Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ec3486b
update proptest to fix 'impl non-local' warning
cowlicks Apr 6, 2025
a2cf32c
add CompactEncodable derives
cowlicks Apr 8, 2025
1771cef
use macros for encode size/bytes
cowlicks Apr 8, 2025
a4551a6
add CompactEncodable's to oplog/header
cowlicks Apr 9, 2025
c9c45d7
add entry OplogEntry CompactEncobable
cowlicks Apr 9, 2025
a966da5
encoded_bytes changed to encode
cowlicks Apr 14, 2025
a17a8e4
WIP Removing State/HypercoreState
cowlicks Apr 16, 2025
dffe4dd
rework crypto/hash with new cenc
cowlicks Apr 17, 2025
c4170f4
rework tree/merkel_tree with new cenc
cowlicks Apr 17, 2025
fbad506
use new compact encoding
cowlicks Apr 17, 2025
0889fd8
lint
cowlicks Apr 19, 2025
1464853
Fix bug in decoding partial kp
cowlicks Apr 19, 2025
93f9fab
BROKEN Remove HypercoreState from oplog/mod.rs
cowlicks Apr 19, 2025
0bbf329
fix bugs
cowlicks Apr 19, 2025
f5d09b3
fix bug in open
cowlicks Apr 19, 2025
1d5226b
fix bug in open
cowlicks Apr 21, 2025
93c0c06
dedupe macros
cowlicks Apr 21, 2025
c9c1ca5
fix decode bug
cowlicks Apr 21, 2025
f741fc1
export more funcs used in protocol
cowlicks Apr 30, 2025
819b943
fix bug encoding DataUpgrade
cowlicks Apr 30, 2025
3069b60
CompactEncoding Vec<u8> -> Box<[u8]>
cowlicks May 2, 2025
2788bb1
Don't re-export compact encoding
cowlicks May 2, 2025
804631a
use map_decode
cowlicks May 2, 2025
be60bca
remove decode! macro and use map_decode
cowlicks May 2, 2025
3b521e5
more map_decode
cowlicks May 2, 2025
ff89a4b
remove & add TODO
cowlicks May 2, 2025
29e041e
use map_decode and check flag correctly
cowlicks May 5, 2025
5577d59
wip use local compact-encoding
cowlicks May 5, 2025
5040979
use new release of compact-encoding
cowlicks May 5, 2025
e571f98
Make BitfieldUpdate pub(crate)
cowlicks May 5, 2025
ee5d7be
clippy fixes
cowlicks May 5, 2025
860eeb5
CI: clippy, check docs and fail on warnings
cowlicks May 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
env:
RUST_BACKTRACE: 1
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"
RUSTDOCFLAGS: "-Dwarnings"

jobs:
ci-pass:
Expand Down Expand Up @@ -145,4 +147,6 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Format check
run: |
cargo doc
cargo fmt -- --check
cargo clippy --all-targets
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ed25519-dalek = { version = "2", features = ["rand_core"] }
getrandom = { version = "0.2", features = ["js"] }
thiserror = "1"
tracing = "0.1"
compact-encoding = "1"
compact-encoding = "2"
flat-tree = "6"
merkle-tree-stream = "0.12"
pretty-hash = "0.4"
Expand All @@ -47,8 +47,8 @@ random-access-disk = { version = "3", default-features = false }

[dev-dependencies]
anyhow = "1.0.70"
proptest = "1.1.0"
proptest-derive = "0.2.0"
proptest = "1.6.0"
proptest-derive = "0.5.1"
data-encoding = "2.2.0"
remove_dir_all = "0.7.0"
tempfile = "3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use self::store::Store;
pub(crate) use self::store::{StoreInfo, StoreInfoInstruction, StoreInfoType};

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BitfieldUpdate {
pub(crate) struct BitfieldUpdate {
pub(crate) drop: bool,
pub(crate) start: u64,
pub(crate) length: u64,
Expand Down
2 changes: 2 additions & 0 deletions src/common/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub struct Node {
/// This node's index in the Merkle tree
pub(crate) index: u64,
/// Hash of the data in this node
// TODO make this [u8; 32] like:
// https://github.com/holepunchto/hypercore/blob/d21ebdeca1b27eb4c2232f8af17d5ae939ee97f2/lib/messages.js#L246
pub(crate) hash: Vec<u8>,
/// Number of bytes in this [`Node::data`]
pub(crate) length: u64,
Expand Down
54 changes: 24 additions & 30 deletions src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use blake2::{
Blake2b, Blake2bMac, Digest,
};
use byteorder::{BigEndian, WriteBytesExt};
use compact_encoding::State;
use compact_encoding::{as_array, to_encoded_bytes, EncodingError, FixedWidthEncoding};
use ed25519_dalek::VerifyingKey;
use merkle_tree_stream::Node as NodeTrait;
use std::convert::AsRef;
Expand Down Expand Up @@ -124,10 +124,9 @@ impl Hash {

/// Hash data
pub(crate) fn data(data: &[u8]) -> Self {
let (mut state, mut size) = State::new_with_size(8);
state
.encode_u64(data.len() as u64, &mut size)
.expect("Encoding u64 should not fail");
let size =
(|| Ok::<_, EncodingError>(to_encoded_bytes!((data.len() as u64).as_fixed_width())))()
.expect("Encoding u64 should not fail");

let mut hasher = Blake2b256::new();
hasher.update(LEAF_TYPE);
Expand All @@ -147,10 +146,10 @@ impl Hash {
(right, left)
};

let (mut state, mut size) = State::new_with_size(8);
state
.encode_u64(node1.length + node2.length, &mut size)
.expect("Encoding u64 should not fail");
let len = node1.length + node2.length;
let size: Box<[u8]> =
(|| Ok::<_, EncodingError>(to_encoded_bytes!(len.as_fixed_width())))()
.expect("Encoding u64 should not fail");

let mut hasher = Blake2b256::new();
hasher.update(PARENT_TYPE);
Expand All @@ -170,13 +169,13 @@ impl Hash {

for node in roots {
let node = node.as_ref();
let (mut state, mut buffer) = State::new_with_size(16);
state
.encode_u64(node.index(), &mut buffer)
.expect("Encoding u64 should not fail");
state
.encode_u64(node.len(), &mut buffer)
.expect("Encoding u64 should not fail");
let buffer = (|| {
Ok::<_, EncodingError>(to_encoded_bytes!(
node.index().as_fixed_width(),
node.len().as_fixed_width()
))
})()
.expect("Encoding u64 should not fail");

hasher.update(node.hash());
hasher.update(&buffer[..8]);
Expand Down Expand Up @@ -212,20 +211,15 @@ impl DerefMut for Hash {
/// Create a signable buffer for tree. This is treeSignable in Javascript.
/// See https://github.com/hypercore-protocol/hypercore/blob/70b271643c4e4b1e5ecae5bb579966dfe6361ff3/lib/caps.js#L17
pub(crate) fn signable_tree(hash: &[u8], length: u64, fork: u64) -> Box<[u8]> {
let (mut state, mut buffer) = State::new_with_size(80);
state
.encode_fixed_32(&TREE, &mut buffer)
.expect("Should be able ");
state
.encode_fixed_32(hash, &mut buffer)
.expect("Encoding fixed 32 bytes should not fail");
state
.encode_u64(length, &mut buffer)
.expect("Encoding u64 should not fail");
state
.encode_u64(fork, &mut buffer)
.expect("Encoding u64 should not fail");
buffer
(|| {
Ok::<_, EncodingError>(to_encoded_bytes!(
&TREE,
as_array::<32>(hash)?,
length.as_fixed_width(),
fork.as_fixed_width()
))
})()
.expect("Encoding should not fail")
}

#[cfg(test)]
Expand Down
Loading
Loading