Skip to content

Commit

Permalink
refactor(storage): rework project structure; add file db for persiste…
Browse files Browse the repository at this point in the history
…nt state (WIP); fix StoredValue deserialization
  • Loading branch information
pashinov committed Feb 26, 2024
1 parent a5949c1 commit 1566cef
Show file tree
Hide file tree
Showing 34 changed files with 1,277 additions and 366 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions block-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ everscale-types = "0.1.0-rc.6"
hex = "0.4.3"
parking_lot = "0.12.1"
sha2 = "0.10.8"
smallvec = "1.13"
thiserror = "1.0.57"

# local deps
Expand Down
23 changes: 22 additions & 1 deletion block-util/src/archive/entry_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::str::FromStr;
use anyhow::Result;
use everscale_types::models::*;
use everscale_types::prelude::HashBytes;
use smallvec::SmallVec;

/// Package entry id.
#[derive(Debug, Hash, Eq, PartialEq)]
Expand Down Expand Up @@ -48,9 +49,29 @@ where
Self::ProofLink(_) => ENTRY_PROOF_LINK,
}
}

/// Constructs on-stack buffer with the serialized object
pub fn to_vec(&self) -> SmallVec<[u8; 4 + 8 + 4 + 32 + 1]> {
// TODO:
let mut result = SmallVec::with_capacity(4 + 8 + 4 + 32 + 1); // TODO:
let (block_id, ty) = match self {
Self::Block(id) => (id, 0),
Self::Proof(id) => (id, 1),
Self::ProofLink(id) => (id, 2),
};
let block_id = block_id.borrow();

result.extend_from_slice(&block_id.shard.workchain().to_be_bytes());
result.extend_from_slice(&block_id.shard.prefix().to_be_bytes());
result.extend_from_slice(&block_id.seqno.to_be_bytes());
result.extend_from_slice(block_id.root_hash.as_slice());
result.push(ty);

result
}
}

trait GetFileName {
pub trait GetFileName {
fn filename(&self) -> String;
}

Expand Down
4 changes: 2 additions & 2 deletions block-util/src/archive/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use bytes::Bytes;

pub use self::entry_id::ArchiveEntryId;
pub use self::entry_id::{ArchiveEntryId, GetFileName};
pub use self::reader::{ArchiveEntry, ArchiveReader, ArchiveReaderError, ArchiveVerifier};

mod entry_id;
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<T> std::ops::Deref for WithArchiveData<T> {
pub struct WithArchiveDataError;

/// Encodes archive package segment.
pub fn make_archive_segment(filename: &str, data: &[u8]) -> Vec<u8> {
pub fn make_archive_entry(filename: &str, data: &[u8]) -> Vec<u8> {
let mut vec = Vec::with_capacity(2 + 2 + 4 + filename.len() + data.len());
vec.extend_from_slice(&ARCHIVE_ENTRY_PREFIX);
vec.extend_from_slice(&(filename.len() as u16).to_le_bytes());
Expand Down
3 changes: 2 additions & 1 deletion storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ anyhow = "1.0.79"
bytes = "1.5.0"

tokio = { version = "1.36.0", features = ["full"] }
tracing = "0.1.40"
tracing = "0.1"
thiserror = "1.0.57"
hex = "0.4.3"
libc = "0.2.153"
Expand All @@ -37,6 +37,7 @@ fdlimit = "0.3.0"
humantime = "2.1.0"
sysinfo = "0.30.5"
triomphe = "0.1.11"
num-traits = "0.2.18"

[lints]
workspace = true
Loading

0 comments on commit 1566cef

Please sign in to comment.