mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2025-04-04 15:35:18 +00:00
Compare commits
1 Commits
7cb190d792
...
cbde8af58e
Author | SHA1 | Date | |
---|---|---|---|
![]() |
cbde8af58e |
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -224,7 +224,6 @@ dependencies = [
|
|||||||
"eth2_ssz_derive",
|
"eth2_ssz_derive",
|
||||||
"ethereum-types 0.14.1",
|
"ethereum-types 0.14.1",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"metrics",
|
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"serde",
|
"serde",
|
||||||
"tiny-keccak",
|
"tiny-keccak",
|
||||||
|
@ -12,6 +12,4 @@ eth2_ssz_derive = "0.3.0"
|
|||||||
serde = { version = "1.0.137", features = ["derive"] }
|
serde = { version = "1.0.137", features = ["derive"] }
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
tracing = "0.1.36"
|
tracing = "0.1.36"
|
||||||
once_cell = "1.19.0"
|
once_cell = "1.19.0"
|
||||||
|
|
||||||
metrics = { workspace = true }
|
|
@ -1,5 +1,4 @@
|
|||||||
mod merkle_tree;
|
mod merkle_tree;
|
||||||
mod metrics;
|
|
||||||
mod proof;
|
mod proof;
|
||||||
mod sha3;
|
mod sha3;
|
||||||
|
|
||||||
@ -8,7 +7,6 @@ use std::cmp::Ordering;
|
|||||||
use std::collections::{BTreeMap, HashMap};
|
use std::collections::{BTreeMap, HashMap};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::time::Instant;
|
|
||||||
use tracing::{trace, warn};
|
use tracing::{trace, warn};
|
||||||
|
|
||||||
pub use crate::merkle_tree::{
|
pub use crate::merkle_tree::{
|
||||||
@ -140,18 +138,15 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn append(&mut self, new_leaf: E) {
|
pub fn append(&mut self, new_leaf: E) {
|
||||||
let start_time = Instant::now();
|
|
||||||
if new_leaf == E::null() {
|
if new_leaf == E::null() {
|
||||||
// appending null is not allowed.
|
// appending null is not allowed.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.layers[0].push(new_leaf);
|
self.layers[0].push(new_leaf);
|
||||||
self.recompute_after_append_leaves(self.leaves() - 1);
|
self.recompute_after_append_leaves(self.leaves() - 1);
|
||||||
metrics::APPEND.update_since(start_time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_list(&mut self, mut leaf_list: Vec<E>) {
|
pub fn append_list(&mut self, mut leaf_list: Vec<E>) {
|
||||||
let start_time = Instant::now();
|
|
||||||
if leaf_list.contains(&E::null()) {
|
if leaf_list.contains(&E::null()) {
|
||||||
// appending null is not allowed.
|
// appending null is not allowed.
|
||||||
return;
|
return;
|
||||||
@ -159,8 +154,6 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
let start_index = self.leaves();
|
let start_index = self.leaves();
|
||||||
self.layers[0].append(&mut leaf_list);
|
self.layers[0].append(&mut leaf_list);
|
||||||
self.recompute_after_append_leaves(start_index);
|
self.recompute_after_append_leaves(start_index);
|
||||||
|
|
||||||
metrics::APPEND_LIST.update_since(start_time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Append a leaf list by providing their intermediate node hash.
|
/// Append a leaf list by providing their intermediate node hash.
|
||||||
@ -169,7 +162,6 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
/// Other nodes in the subtree will be set to `null` nodes.
|
/// Other nodes in the subtree will be set to `null` nodes.
|
||||||
/// TODO: Optimize to avoid storing the `null` nodes?
|
/// TODO: Optimize to avoid storing the `null` nodes?
|
||||||
pub fn append_subtree(&mut self, subtree_depth: usize, subtree_root: E) -> Result<()> {
|
pub fn append_subtree(&mut self, subtree_depth: usize, subtree_root: E) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
|
||||||
if subtree_root == E::null() {
|
if subtree_root == E::null() {
|
||||||
// appending null is not allowed.
|
// appending null is not allowed.
|
||||||
bail!("subtree_root is null");
|
bail!("subtree_root is null");
|
||||||
@ -177,13 +169,10 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
let start_index = self.leaves();
|
let start_index = self.leaves();
|
||||||
self.append_subtree_inner(subtree_depth, subtree_root)?;
|
self.append_subtree_inner(subtree_depth, subtree_root)?;
|
||||||
self.recompute_after_append_subtree(start_index, subtree_depth - 1);
|
self.recompute_after_append_subtree(start_index, subtree_depth - 1);
|
||||||
|
|
||||||
metrics::APPEND_SUBTREE.update_since(start_time);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_subtree_list(&mut self, subtree_list: Vec<(usize, E)>) -> Result<()> {
|
pub fn append_subtree_list(&mut self, subtree_list: Vec<(usize, E)>) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
|
||||||
if subtree_list.iter().any(|(_, root)| root == &E::null()) {
|
if subtree_list.iter().any(|(_, root)| root == &E::null()) {
|
||||||
// appending null is not allowed.
|
// appending null is not allowed.
|
||||||
bail!("subtree_list contains null");
|
bail!("subtree_list contains null");
|
||||||
@ -193,14 +182,12 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
self.append_subtree_inner(subtree_depth, subtree_root)?;
|
self.append_subtree_inner(subtree_depth, subtree_root)?;
|
||||||
self.recompute_after_append_subtree(start_index, subtree_depth - 1);
|
self.recompute_after_append_subtree(start_index, subtree_depth - 1);
|
||||||
}
|
}
|
||||||
metrics::APPEND_SUBTREE_LIST.update_since(start_time);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Change the value of the last leaf and return the new merkle root.
|
/// Change the value of the last leaf and return the new merkle root.
|
||||||
/// This is needed if our merkle-tree in memory only keeps intermediate nodes instead of real leaves.
|
/// This is needed if our merkle-tree in memory only keeps intermediate nodes instead of real leaves.
|
||||||
pub fn update_last(&mut self, updated_leaf: E) {
|
pub fn update_last(&mut self, updated_leaf: E) {
|
||||||
let start_time = Instant::now();
|
|
||||||
if updated_leaf == E::null() {
|
if updated_leaf == E::null() {
|
||||||
// updating to null is not allowed.
|
// updating to null is not allowed.
|
||||||
return;
|
return;
|
||||||
@ -212,7 +199,6 @@ impl<E: HashElement, A: Algorithm<E>> AppendMerkleTree<E, A> {
|
|||||||
*self.layers[0].last_mut().unwrap() = updated_leaf;
|
*self.layers[0].last_mut().unwrap() = updated_leaf;
|
||||||
}
|
}
|
||||||
self.recompute_after_append_leaves(self.leaves() - 1);
|
self.recompute_after_append_leaves(self.leaves() - 1);
|
||||||
metrics::UPDATE_LAST.update_since(start_time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fill an unknown `null` leaf with its real value.
|
/// Fill an unknown `null` leaf with its real value.
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use metrics::{register_timer, Timer};
|
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
|
||||||
pub static ref APPEND: Arc<dyn Timer> = register_timer("append_merkle_append");
|
|
||||||
pub static ref APPEND_LIST: Arc<dyn Timer> = register_timer("append_merkle_append_list");
|
|
||||||
pub static ref APPEND_SUBTREE: Arc<dyn Timer> = register_timer("append_merkle_append_subtree");
|
|
||||||
pub static ref APPEND_SUBTREE_LIST: Arc<dyn Timer> = register_timer("append_merkle_append_subtree_list");
|
|
||||||
pub static ref UPDATE_LAST: Arc<dyn Timer> = register_timer("append_merkle_update_last");
|
|
||||||
}
|
|
@ -1,14 +1,13 @@
|
|||||||
|
use super::load_chunk::EntryBatch;
|
||||||
|
use super::seal_task_manager::SealTaskManager;
|
||||||
|
use super::{MineLoadChunk, SealAnswer, SealTask};
|
||||||
use crate::config::ShardConfig;
|
use crate::config::ShardConfig;
|
||||||
use crate::error::Error;
|
use crate::error::Error;
|
||||||
use crate::log_store::load_chunk::EntryBatch;
|
|
||||||
use crate::log_store::log_manager::{
|
use crate::log_store::log_manager::{
|
||||||
bytes_to_entries, data_to_merkle_leaves, COL_ENTRY_BATCH, COL_ENTRY_BATCH_ROOT,
|
bytes_to_entries, data_to_merkle_leaves, COL_ENTRY_BATCH, COL_ENTRY_BATCH_ROOT,
|
||||||
COL_FLOW_MPT_NODES, ENTRY_SIZE, PORA_CHUNK_SIZE,
|
COL_FLOW_MPT_NODES, ENTRY_SIZE, PORA_CHUNK_SIZE,
|
||||||
};
|
};
|
||||||
use crate::log_store::seal_task_manager::SealTaskManager;
|
use crate::log_store::{FlowRead, FlowSeal, FlowWrite};
|
||||||
use crate::log_store::{
|
|
||||||
metrics, FlowRead, FlowSeal, FlowWrite, MineLoadChunk, SealAnswer, SealTask,
|
|
||||||
};
|
|
||||||
use crate::{try_option, ZgsKeyValueDB};
|
use crate::{try_option, ZgsKeyValueDB};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use append_merkle::{MerkleTreeInitialData, MerkleTreeRead};
|
use append_merkle::{MerkleTreeInitialData, MerkleTreeRead};
|
||||||
@ -21,7 +20,6 @@ use std::cmp::Ordering;
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
|
||||||
use std::{cmp, mem};
|
use std::{cmp, mem};
|
||||||
use tracing::{debug, error, trace};
|
use tracing::{debug, error, trace};
|
||||||
use zgs_spec::{BYTES_PER_SECTOR, SEALS_PER_LOAD, SECTORS_PER_LOAD, SECTORS_PER_SEAL};
|
use zgs_spec::{BYTES_PER_SECTOR, SEALS_PER_LOAD, SECTORS_PER_LOAD, SECTORS_PER_SEAL};
|
||||||
@ -42,11 +40,7 @@ impl FlowStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_batch_root_list(&self, root_map: BTreeMap<usize, (DataRoot, usize)>) -> Result<()> {
|
pub fn put_batch_root_list(&self, root_map: BTreeMap<usize, (DataRoot, usize)>) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
self.db.put_batch_root_list(root_map)
|
||||||
let res = self.db.put_batch_root_list(root_map);
|
|
||||||
|
|
||||||
metrics::PUT_BATCH_ROOT_LIST.update_since(start_time);
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_subtree_list_for_batch(
|
pub fn insert_subtree_list_for_batch(
|
||||||
@ -54,7 +48,6 @@ impl FlowStore {
|
|||||||
batch_index: usize,
|
batch_index: usize,
|
||||||
subtree_list: Vec<(usize, usize, DataRoot)>,
|
subtree_list: Vec<(usize, usize, DataRoot)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
|
||||||
let mut batch = self
|
let mut batch = self
|
||||||
.db
|
.db
|
||||||
.get_entry_batch(batch_index as u64)?
|
.get_entry_batch(batch_index as u64)?
|
||||||
@ -62,8 +55,6 @@ impl FlowStore {
|
|||||||
batch.set_subtree_list(subtree_list);
|
batch.set_subtree_list(subtree_list);
|
||||||
self.db.put_entry_raw(vec![(batch_index as u64, batch)])?;
|
self.db.put_entry_raw(vec![(batch_index as u64, batch)])?;
|
||||||
|
|
||||||
metrics::INSERT_SUBTREE_LIST.update_since(start_time);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,10 +73,7 @@ impl FlowStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn put_mpt_node_list(&self, node_list: Vec<(usize, usize, DataRoot)>) -> Result<()> {
|
pub fn put_mpt_node_list(&self, node_list: Vec<(usize, usize, DataRoot)>) -> Result<()> {
|
||||||
let start_time = Instant::now();
|
self.db.put_mpt_node_list(node_list)
|
||||||
let res = self.db.put_mpt_node_list(node_list);
|
|
||||||
metrics::PUT_MPT_NODE.update_since(start_time);
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_batch_list(&self, batch_list: &[u64]) -> Result<()> {
|
pub fn delete_batch_list(&self, batch_list: &[u64]) -> Result<()> {
|
||||||
@ -234,7 +222,6 @@ impl FlowWrite for FlowStore {
|
|||||||
/// Return the roots of completed chunks. The order is guaranteed to be increasing
|
/// Return the roots of completed chunks. The order is guaranteed to be increasing
|
||||||
/// by chunk index.
|
/// by chunk index.
|
||||||
fn append_entries(&self, data: ChunkArray) -> Result<Vec<(u64, DataRoot)>> {
|
fn append_entries(&self, data: ChunkArray) -> Result<Vec<(u64, DataRoot)>> {
|
||||||
let start_time = Instant::now();
|
|
||||||
let mut to_seal_set = self.seal_manager.to_seal_set.write();
|
let mut to_seal_set = self.seal_manager.to_seal_set.write();
|
||||||
trace!("append_entries: {} {}", data.start_index, data.data.len());
|
trace!("append_entries: {} {}", data.start_index, data.data.len());
|
||||||
if data.data.len() % BYTES_PER_SECTOR != 0 {
|
if data.data.len() % BYTES_PER_SECTOR != 0 {
|
||||||
@ -277,8 +264,6 @@ impl FlowWrite for FlowStore {
|
|||||||
|
|
||||||
batch_list.push((chunk_index, batch));
|
batch_list.push((chunk_index, batch));
|
||||||
}
|
}
|
||||||
|
|
||||||
metrics::APPEND_ENTRIES.update_since(start_time);
|
|
||||||
self.db.put_entry_batch_list(batch_list)
|
self.db.put_entry_batch_list(batch_list)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +373,6 @@ impl FlowDBStore {
|
|||||||
&self,
|
&self,
|
||||||
batch_list: Vec<(u64, EntryBatch)>,
|
batch_list: Vec<(u64, EntryBatch)>,
|
||||||
) -> Result<Vec<(u64, DataRoot)>> {
|
) -> Result<Vec<(u64, DataRoot)>> {
|
||||||
let start_time = Instant::now();
|
|
||||||
let mut completed_batches = Vec::new();
|
let mut completed_batches = Vec::new();
|
||||||
let mut tx = self.kvdb.transaction();
|
let mut tx = self.kvdb.transaction();
|
||||||
for (batch_index, batch) in batch_list {
|
for (batch_index, batch) in batch_list {
|
||||||
@ -409,7 +393,6 @@ impl FlowDBStore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.kvdb.write(tx)?;
|
self.kvdb.write(tx)?;
|
||||||
metrics::PUT_ENTRY_BATCH_LIST.update_since(start_time);
|
|
||||||
Ok(completed_batches)
|
Ok(completed_batches)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -936,7 +936,6 @@ impl LogManager {
|
|||||||
#[instrument(skip(self, merkle))]
|
#[instrument(skip(self, merkle))]
|
||||||
fn pad_tx(&self, tx_start_index: u64, merkle: &mut MerkleManager) -> Result<()> {
|
fn pad_tx(&self, tx_start_index: u64, merkle: &mut MerkleManager) -> Result<()> {
|
||||||
// Check if we need to pad the flow.
|
// Check if we need to pad the flow.
|
||||||
let start_time = Instant::now();
|
|
||||||
let mut tx_start_flow_index =
|
let mut tx_start_flow_index =
|
||||||
merkle.last_chunk_start_index() + merkle.last_chunk_merkle.leaves() as u64;
|
merkle.last_chunk_start_index() + merkle.last_chunk_merkle.leaves() as u64;
|
||||||
let pad_size = tx_start_index - tx_start_flow_index;
|
let pad_size = tx_start_index - tx_start_flow_index;
|
||||||
@ -1026,8 +1025,6 @@ impl LogManager {
|
|||||||
merkle.pora_chunks_merkle.leaves(),
|
merkle.pora_chunks_merkle.leaves(),
|
||||||
merkle.last_chunk_merkle.leaves()
|
merkle.last_chunk_merkle.leaves()
|
||||||
);
|
);
|
||||||
|
|
||||||
metrics::PAD_TX.update_since(start_time);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1280,7 +1277,6 @@ pub fn sub_merkle_tree(leaf_data: &[u8]) -> Result<FileMerkleTree> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn data_to_merkle_leaves(leaf_data: &[u8]) -> Result<Vec<H256>> {
|
pub fn data_to_merkle_leaves(leaf_data: &[u8]) -> Result<Vec<H256>> {
|
||||||
let start_time = Instant::now();
|
|
||||||
if leaf_data.len() % ENTRY_SIZE != 0 {
|
if leaf_data.len() % ENTRY_SIZE != 0 {
|
||||||
bail!("merkle_tree: mismatched data size");
|
bail!("merkle_tree: mismatched data size");
|
||||||
}
|
}
|
||||||
@ -1296,8 +1292,6 @@ pub fn data_to_merkle_leaves(leaf_data: &[u8]) -> Result<Vec<H256>> {
|
|||||||
.map(Sha3Algorithm::leaf)
|
.map(Sha3Algorithm::leaf)
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
|
|
||||||
metrics::DATA_TO_MERKLE_LEAVES.update_since(start_time);
|
|
||||||
Ok(r)
|
Ok(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,29 +5,10 @@ use metrics::{register_timer, Timer};
|
|||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
pub static ref TX_STORE_PUT: Arc<dyn Timer> = register_timer("log_store_tx_store_put_tx");
|
pub static ref TX_STORE_PUT: Arc<dyn Timer> = register_timer("log_store_tx_store_put_tx");
|
||||||
|
|
||||||
pub static ref CHECK_TX_COMPLETED: Arc<dyn Timer> =
|
|
||||||
register_timer("log_store_log_manager_check_tx_completed");
|
|
||||||
|
|
||||||
pub static ref APPEND_SUBTREE_LIST: Arc<dyn Timer> =
|
pub static ref APPEND_SUBTREE_LIST: Arc<dyn Timer> =
|
||||||
register_timer("log_store_log_manager_append_subtree_list");
|
register_timer("log_store_log_manager_append_subtree_list");
|
||||||
|
|
||||||
pub static ref DATA_TO_MERKLE_LEAVES: Arc<dyn Timer> =
|
|
||||||
register_timer("log_store_log_manager_data_to_merkle_leaves");
|
|
||||||
|
|
||||||
pub static ref COPY_TX_AND_FINALIZE: Arc<dyn Timer> =
|
pub static ref COPY_TX_AND_FINALIZE: Arc<dyn Timer> =
|
||||||
register_timer("log_store_log_manager_copy_tx_and_finalize");
|
register_timer("log_store_log_manager_copy_tx_and_finalize");
|
||||||
|
|
||||||
pub static ref PAD_TX: Arc<dyn Timer> = register_timer("log_store_log_manager_pad_tx");
|
|
||||||
|
|
||||||
pub static ref PUT_BATCH_ROOT_LIST: Arc<dyn Timer> = register_timer("log_store_flow_store_put_batch_root_list");
|
|
||||||
|
|
||||||
pub static ref INSERT_SUBTREE_LIST: Arc<dyn Timer> =
|
|
||||||
register_timer("log_store_flow_store_insert_subtree_list");
|
|
||||||
|
|
||||||
pub static ref PUT_MPT_NODE: Arc<dyn Timer> = register_timer("log_store_flow_store_put_mpt_node");
|
|
||||||
|
|
||||||
pub static ref PUT_ENTRY_BATCH_LIST: Arc<dyn Timer> =
|
|
||||||
register_timer("log_store_flow_store_put_entry_batch_list");
|
|
||||||
|
|
||||||
pub static ref APPEND_ENTRIES: Arc<dyn Timer> = register_timer("log_store_flow_store_append_entries");
|
|
||||||
}
|
}
|
||||||
|
@ -180,12 +180,8 @@ impl TransactionStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_tx_completed(&self, tx_seq: u64) -> Result<bool> {
|
pub fn check_tx_completed(&self, tx_seq: u64) -> Result<bool> {
|
||||||
let start_time = Instant::now();
|
Ok(self.kvdb.get(COL_TX_COMPLETED, &tx_seq.to_be_bytes())?
|
||||||
let res = self.kvdb.get(COL_TX_COMPLETED, &tx_seq.to_be_bytes())?
|
== Some(vec![TX_STATUS_FINALIZED]))
|
||||||
== Some(vec![TX_STATUS_FINALIZED]);
|
|
||||||
|
|
||||||
metrics::CHECK_TX_COMPLETED.update_since(start_time);
|
|
||||||
Ok(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_tx_pruned(&self, tx_seq: u64) -> Result<bool> {
|
pub fn check_tx_pruned(&self, tx_seq: u64) -> Result<bool> {
|
||||||
|
Loading…
Reference in New Issue
Block a user