mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Make db-models no-std (#14459)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de> Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com> Co-authored-by: alpharush <0xalpharush@protonmail.com> Co-authored-by: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Co-authored-by: Alexey Shekhirin <5773434+shekhirin@users.noreply.github.com> Co-authored-by: Dan Cline <6798349+Rjected@users.noreply.github.com> Co-authored-by: Federico Gimenez <fgimenez@users.noreply.github.com> Co-authored-by: Roman Krasiuk <rokrassyuk@gmail.com> Co-authored-by: Ryan Schneider <ryanleeschneider@gmail.com> Co-authored-by: Bilog WEB3 <155262265+Bilogweb3@users.noreply.github.com> Co-authored-by: Vitalyr <158586577+Vitaliyr888@users.noreply.github.com> Co-authored-by: Yohann Kazoula <yoh.kzl@gmail.com> Co-authored-by: Shourya Chaudhry <149008800+18aaddy@users.noreply.github.com> Co-authored-by: Poulav Bhowmick <bpoulav@gmail.com> Co-authored-by: urb <urbadeil@gmail.com> Co-authored-by: Emilia Hane <elsaemiliaevahane@gmail.com>
This commit is contained in:
@ -14,7 +14,7 @@ workspace = true
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-codecs.workspace = true
|
||||
reth-db-models.workspace = true
|
||||
reth-db-models = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives = { workspace = true, features = ["reth-codec"] }
|
||||
reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] }
|
||||
reth-stages-types = { workspace = true, features = ["serde", "reth-codec"] }
|
||||
|
||||
@ -13,28 +13,30 @@ workspace = true
|
||||
|
||||
[dependencies]
|
||||
# reth
|
||||
reth-codecs.workspace = true
|
||||
reth-primitives-traits = { workspace = true, features = ["serde", "reth-codec"] }
|
||||
reth-codecs = { workspace = true, optional = true }
|
||||
reth-primitives-traits = { workspace = true, features = ["serde"] }
|
||||
|
||||
# ethereum
|
||||
alloy-primitives.workspace = true
|
||||
alloy-eips.workspace = true
|
||||
|
||||
# codecs
|
||||
modular-bitfield.workspace = true
|
||||
modular-bitfield = { workspace = true, optional = true }
|
||||
serde = { workspace = true, default-features = false }
|
||||
|
||||
# misc
|
||||
bytes.workspace = true
|
||||
bytes = { workspace = true, optional = true }
|
||||
|
||||
# arbitrary utils
|
||||
arbitrary = { workspace = true, features = ["derive"], optional = true }
|
||||
proptest = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
# reth
|
||||
reth-primitives-traits = { workspace = true, features = ["arbitrary"] }
|
||||
reth-codecs.workspace = true
|
||||
|
||||
bytes.workspace = true
|
||||
modular-bitfield.workspace = true
|
||||
arbitrary = { workspace = true, features = ["derive"] }
|
||||
|
||||
proptest.workspace = true
|
||||
@ -42,16 +44,30 @@ proptest-arbitrary-interop.workspace = true
|
||||
test-fuzz.workspace = true
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = [
|
||||
"alloy-eips/std",
|
||||
"alloy-primitives/std",
|
||||
"reth-primitives-traits/std",
|
||||
"bytes?/std",
|
||||
"serde/std",
|
||||
]
|
||||
test-utils = [
|
||||
"reth-primitives-traits/test-utils",
|
||||
"arbitrary",
|
||||
"reth-codecs/test-utils",
|
||||
"reth-codecs?/test-utils",
|
||||
]
|
||||
arbitrary = [
|
||||
"std",
|
||||
"reth-primitives-traits/arbitrary",
|
||||
"dep:arbitrary",
|
||||
"dep:proptest",
|
||||
"alloy-primitives/arbitrary",
|
||||
"alloy-eips/arbitrary",
|
||||
"reth-codecs/arbitrary",
|
||||
"reth-codecs?/arbitrary",
|
||||
]
|
||||
reth-codec = [
|
||||
"dep:reth-codecs",
|
||||
"dep:modular-bitfield",
|
||||
"dep:bytes",
|
||||
"reth-primitives-traits/reth-codec",
|
||||
]
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use serde::Serialize;
|
||||
|
||||
use alloy_primitives::{bytes::Buf, Address};
|
||||
use alloy_primitives::Address;
|
||||
use reth_primitives_traits::Account;
|
||||
|
||||
/// Account as it is saved in the database.
|
||||
@ -9,7 +8,7 @@ use reth_primitives_traits::Account;
|
||||
/// [`Address`] is the subkey.
|
||||
#[derive(Debug, Default, Clone, Eq, PartialEq, Serialize)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary, serde::Deserialize))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
pub struct AccountBeforeTx {
|
||||
/// Address for the account. Acts as `DupSort::SubKey`.
|
||||
pub address: Address,
|
||||
@ -20,7 +19,8 @@ pub struct AccountBeforeTx {
|
||||
// NOTE: Removing reth_codec and manually encode subkey
|
||||
// and compress second part of the value. If we have compression
|
||||
// over whole value (Even SubKey) that would mess up fetching of values with seek_by_key_subkey
|
||||
impl Compact for AccountBeforeTx {
|
||||
#[cfg(feature = "reth-codec")]
|
||||
impl reth_codecs::Compact for AccountBeforeTx {
|
||||
fn to_compact<B>(&self, buf: &mut B) -> usize
|
||||
where
|
||||
B: bytes::BufMut + AsMut<[u8]>,
|
||||
@ -36,6 +36,7 @@ impl Compact for AccountBeforeTx {
|
||||
}
|
||||
|
||||
fn from_compact(mut buf: &[u8], len: usize) -> (Self, &[u8]) {
|
||||
use bytes::Buf;
|
||||
let address = Address::from_slice(&buf[..20]);
|
||||
buf.advance(20);
|
||||
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
use alloy_eips::eip4895::Withdrawals;
|
||||
use alloy_primitives::TxNumber;
|
||||
use bytes::Buf;
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use core::ops::Range;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ops::Range;
|
||||
|
||||
/// Total number of transactions.
|
||||
pub type NumTransactions = u64;
|
||||
@ -12,9 +10,10 @@ pub type NumTransactions = u64;
|
||||
///
|
||||
/// It has the pointer to the transaction Number of the first
|
||||
/// transaction in the block and the total number of transactions.
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone, Copy, Serialize, Deserialize, Compact)]
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
pub struct StoredBlockBodyIndices {
|
||||
/// The number of the first transaction in this block
|
||||
///
|
||||
@ -68,9 +67,10 @@ impl StoredBlockBodyIndices {
|
||||
}
|
||||
|
||||
/// The storage representation of block withdrawals.
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize, Compact)]
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), derive(reth_codecs::Compact))]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
pub struct StoredBlockWithdrawals {
|
||||
/// The block withdrawals.
|
||||
pub withdrawals: Withdrawals,
|
||||
@ -80,13 +80,14 @@ pub struct StoredBlockWithdrawals {
|
||||
/// represents a pre-merge block.
|
||||
#[derive(Debug, Default, Eq, PartialEq, Clone, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
pub struct StaticFileBlockWithdrawals {
|
||||
/// The block withdrawals. A `None` value represents a pre-merge block.
|
||||
pub withdrawals: Option<Withdrawals>,
|
||||
}
|
||||
|
||||
impl Compact for StaticFileBlockWithdrawals {
|
||||
#[cfg(feature = "reth-codec")]
|
||||
impl reth_codecs::Compact for StaticFileBlockWithdrawals {
|
||||
fn to_compact<B>(&self, buf: &mut B) -> usize
|
||||
where
|
||||
B: bytes::BufMut + AsMut<[u8]>,
|
||||
@ -98,6 +99,7 @@ impl Compact for StaticFileBlockWithdrawals {
|
||||
1
|
||||
}
|
||||
fn from_compact(mut buf: &[u8], _: usize) -> (Self, &[u8]) {
|
||||
use bytes::Buf;
|
||||
if buf.get_u8() == 1 {
|
||||
let (w, buf) = Withdrawals::from_compact(buf, buf.len());
|
||||
(Self { withdrawals: Some(w) }, buf)
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
//! Client version model.
|
||||
|
||||
use reth_codecs::{add_arbitrary_tests, Compact};
|
||||
use alloc::string::String;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Client version that accessed the database.
|
||||
#[derive(Clone, Eq, PartialEq, Debug, Default, Serialize, Deserialize)]
|
||||
#[cfg_attr(any(test, feature = "arbitrary"), derive(arbitrary::Arbitrary))]
|
||||
#[add_arbitrary_tests(compact)]
|
||||
#[cfg_attr(any(test, feature = "reth-codec"), reth_codecs::add_arbitrary_tests(compact))]
|
||||
pub struct ClientVersion {
|
||||
/// Client version
|
||||
pub version: String,
|
||||
@ -23,7 +23,8 @@ impl ClientVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl Compact for ClientVersion {
|
||||
#[cfg(feature = "reth-codec")]
|
||||
impl reth_codecs::Compact for ClientVersion {
|
||||
fn to_compact<B>(&self, buf: &mut B) -> usize
|
||||
where
|
||||
B: bytes::BufMut + AsMut<[u8]>,
|
||||
|
||||
@ -1,4 +1,15 @@
|
||||
//! Models used in storage module
|
||||
//! Models used in storage module.
|
||||
|
||||
#![doc(
|
||||
html_logo_url = "https://raw.githubusercontent.com/paradigmxyz/reth/main/assets/reth-docs.png",
|
||||
html_favicon_url = "https://avatars0.githubusercontent.com/u/97369466?s=256",
|
||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||
)]
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
/// Accounts
|
||||
pub mod accounts;
|
||||
|
||||
Reference in New Issue
Block a user