Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 34 additions & 11 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"ledger",
"ledger/helpers",
"ledger/helpers/unsafe",
"metadata",
"node",
"pallets/midnight",
Expand Down Expand Up @@ -126,7 +127,8 @@ midnight-serialize = { version = "=1.2.0", package = "midnight-serialize" }
# Midnight local dependencies
midnight-node-ledger = { path = "ledger", default-features = false }
midnight-node-metadata = { path = "metadata", default-features = false }
midnight-node-ledger-helpers = { path = "ledger/helpers", default-features = false, features = ["test-utils"] }
midnight-node-ledger-helpers = { path = "ledger/helpers", default-features = false }
midnight-ledger-unsafe-helpers = { path = "ledger/helpers/unsafe", default-features = false }
midnight-node-res = { path = "res", default-features = false }
midnight-node-toolkit = { path = "util/toolkit", default-features = true }
pallet-midnight = { path = "pallets/midnight", default-features = false }
Expand Down
9 changes: 9 additions & 0 deletions changes/toolkit/changed/split-midnight-ledger-helpers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#toolkit

# Split midnight-ledger-helpers crate

Splits 'can-panic' feature code to a separate crate to avoid confusion
about what code can be used by consenus and what code is for toolkit
and tests.

PR: https://github.com/midnightntwrk/midnight-node/pull/2106
6 changes: 1 addition & 5 deletions ledger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ scale-info.workspace = true

[dev-dependencies]
midnight-node-res = { workspace = true, features = ["test", "chain-spec"] }
# The crate's own `#[cfg(test)]` modules (api::ledger, api::transaction, and the
# state-translation tests) use `extract_tx_with_context`, gated behind the
# helpers `can-panic` feature. Enable it for test builds so the tests compile
# when the crate is tested standalone.
midnight-node-ledger-helpers = { workspace = true, features = ["can-panic", "test-utils"] }
midnight-ledger-unsafe-helpers = { workspace = true }

[features]
default = [
Expand Down
16 changes: 1 addition & 15 deletions ledger/helpers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ cargo_metadata = "0.15"

[dependencies]
hex.workspace = true
sha2.workspace = true

base-crypto = { workspace = true }
coin-structure = { workspace = true }
Expand All @@ -32,40 +31,27 @@ zswap-ledger-9 = { workspace = true }
coin-structure-ledger-9 = { workspace = true }
transient-crypto-ledger-9 = { workspace = true }

# v8->v9 state translation table, used by the toolkit fork boundary (`fork::fork_8_to_9`).
v8-to-v9-state-translation = { workspace = true }

rand = { version = "0.8.4", features = ["small_rng", "getrandom"] }
rayon.workspace = true
log.workspace = true
lazy_static.workspace = true
itertools = { workspace = true, features = ["use_alloc"] }
thiserror.workspace = true
tokio.workspace = true
async-trait.workspace = true
futures.workspace = true
bip32.workspace = true
derive-where.workspace = true
serde = { workspace = true, features = ["derive"] }
# Derive the u8 <-> variant and name <-> variant mappings from the enum declaration
# itself, so `LedgerVersion`'s wire discriminants can't drift from a hand-written table.
num_enum = "0.7"
strum.workspace = true
bech32 = "0.11.0"
bip39 = "2.2.2"
subxt.workspace = true
subxt-signer.workspace = true
serde_json.workspace = true
serde_bytes = "0.11"
zeroize = { workspace = true }

[dev-dependencies]
# Pins the cache wire format of `LedgerVersion` (see raw_block_data.rs tests).
postcard = { version = "1.1", features = ["alloc"] }
serde_json.workspace = true

[features]
default = []
can-panic = []
erase-proof = []
test-utils = []
fixed-point-custom-serde = ["mn-ledger-8/fixed-point-custom-serde", "mn-ledger-9/fixed-point-custom-serde"]
21 changes: 0 additions & 21 deletions ledger/helpers/src/fork/mod.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
pub mod raw_block_data;

#[cfg(feature = "can-panic")]
use crate::fork::raw_block_data::LedgerVersion;

#[cfg(feature = "can-panic")]
pub mod fork_8_to_9;
#[cfg(feature = "can-panic")]
pub mod fork_aware_context;

#[cfg(feature = "can-panic")]
pub fn network_id_and_ledger_version_from_tx_bytes(
tx_bytes: &[u8],
) -> Result<(String, LedgerVersion), std::io::Error> {
let res9 = crate::ledger_9::network_id_from_transaction_bytes(tx_bytes);
if let Ok(ref network_id) = res9 {
return Ok((network_id.to_string(), LedgerVersion::Ledger9));
}

let network_id = crate::ledger_8::network_id_from_transaction_bytes(tx_bytes)?;
Ok((network_id.to_string(), LedgerVersion::Ledger8))
}
33 changes: 0 additions & 33 deletions ledger/helpers/src/fork/raw_block_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,39 +277,6 @@ impl SerializedTxBatches {
}
}

#[cfg(feature = "can-panic")]
impl TryFrom<&SerializedTxBatches> for Vec<RawBlockData> {
type Error = String;

fn try_from(value: &SerializedTxBatches) -> Result<Self, Self::Error> {
let mut blocks = Vec::new();
let mut ledger_version = LedgerVersion::default();

for batch in &value.batches {
let context = SerializedTxBatches::get_context(batch)?;
let transactions: Vec<_> = batch.iter().map(|t| t.tx.clone()).collect();

if let Some((_, v)) = transactions
.iter()
.filter_map(|tx| {
crate::fork::network_id_and_ledger_version_from_tx_bytes(tx.as_bytes()).ok()
})
.next()
{
ledger_version = v;
}

blocks.push(RawBlockData::new_from_timestamp(
context.tblock.to_secs(),
ledger_version,
transactions,
));
}

Ok(blocks)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
25 changes: 0 additions & 25 deletions ledger/helpers/src/ledger_8/block_context.rs

This file was deleted.

Loading
Loading