mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-25 23:23:11 +00:00
Merge branch 'main' into Pravdyvy/indexer-db-batching
This commit is contained in:
@@ -4,6 +4,9 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
common.workspace = true
|
||||
nssa.workspace = true
|
||||
|
||||
@@ -17,21 +17,24 @@ pub enum DbError {
|
||||
}
|
||||
|
||||
impl DbError {
|
||||
pub fn rocksdb_cast_message(rerr: rocksdb::Error, message: Option<String>) -> Self {
|
||||
#[must_use]
|
||||
pub const fn rocksdb_cast_message(rerr: rocksdb::Error, message: Option<String>) -> Self {
|
||||
Self::RocksDbError {
|
||||
error: rerr,
|
||||
additional_info: message,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn borsh_cast_message(berr: borsh::io::Error, message: Option<String>) -> Self {
|
||||
#[must_use]
|
||||
pub const fn borsh_cast_message(berr: borsh::io::Error, message: Option<String>) -> Self {
|
||||
Self::SerializationError {
|
||||
error: berr,
|
||||
additional_info: message,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn db_interaction_error(message: String) -> Self {
|
||||
#[must_use]
|
||||
pub const fn db_interaction_error(message: String) -> Self {
|
||||
Self::DbInteractionError {
|
||||
additional_info: message,
|
||||
}
|
||||
|
||||
+89
-93
@@ -1,9 +1,9 @@
|
||||
use std::{collections::HashMap, ops::Div, path::Path, sync::Arc};
|
||||
use std::{path::Path, sync::Arc};
|
||||
|
||||
use common::{block::Block, transaction::NSSATransaction};
|
||||
use common::block::Block;
|
||||
use nssa::V02State;
|
||||
use rocksdb::{
|
||||
BoundColumnFamily, ColumnFamilyDescriptor, DBWithThreadMode, MultiThreaded, Options, WriteBatch,
|
||||
BoundColumnFamily, ColumnFamilyDescriptor, DBWithThreadMode, MultiThreaded, Options,
|
||||
};
|
||||
|
||||
use crate::error::DbError;
|
||||
@@ -13,52 +13,55 @@ pub mod read_once;
|
||||
pub mod write_batch;
|
||||
pub mod write_once;
|
||||
|
||||
/// Maximal size of stored blocks in base
|
||||
/// Maximal size of stored blocks in base.
|
||||
///
|
||||
/// Used to control db size
|
||||
/// Used to control db size.
|
||||
///
|
||||
/// Currently effectively unbounded.
|
||||
pub const BUFF_SIZE_ROCKSDB: usize = usize::MAX;
|
||||
|
||||
/// Size of stored blocks cache in memory
|
||||
/// Size of stored blocks cache in memory.
|
||||
///
|
||||
/// Keeping small to not run out of memory
|
||||
/// Keeping small to not run out of memory.
|
||||
pub const CACHE_SIZE: usize = 1000;
|
||||
|
||||
/// Key base for storing metainformation about id of first block in db
|
||||
/// Key base for storing metainformation about id of first block in db.
|
||||
pub const DB_META_FIRST_BLOCK_IN_DB_KEY: &str = "first_block_in_db";
|
||||
/// Key base for storing metainformation about id of last current block in db
|
||||
/// Key base for storing metainformation about id of last current block in db.
|
||||
pub const DB_META_LAST_BLOCK_IN_DB_KEY: &str = "last_block_in_db";
|
||||
/// Key base for storing metainformation about id of last observed L1 lib header in db
|
||||
/// Key base for storing metainformation about id of last observed L1 lib header in db.
|
||||
pub const DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY: &str =
|
||||
"last_observed_l1_lib_header_in_db";
|
||||
/// Key base for storing metainformation which describe if first block has been set
|
||||
/// Key base for storing metainformation which describe if first block has been set.
|
||||
pub const DB_META_FIRST_BLOCK_SET_KEY: &str = "first_block_set";
|
||||
/// Key base for storing metainformation about the last breakpoint
|
||||
/// Key base for storing metainformation about the last breakpoint.
|
||||
pub const DB_META_LAST_BREAKPOINT_ID: &str = "last_breakpoint_id";
|
||||
|
||||
/// Interval between state breakpoints
|
||||
pub const BREAKPOINT_INTERVAL: u64 = 100;
|
||||
/// Interval between state breakpoints.
|
||||
pub const BREAKPOINT_INTERVAL: u8 = 100;
|
||||
|
||||
/// Name of block column family
|
||||
/// Name of block column family.
|
||||
pub const CF_BLOCK_NAME: &str = "cf_block";
|
||||
/// Name of meta column family
|
||||
/// Name of meta column family.
|
||||
pub const CF_META_NAME: &str = "cf_meta";
|
||||
/// Name of breakpoint column family
|
||||
/// Name of breakpoint column family.
|
||||
pub const CF_BREAKPOINT_NAME: &str = "cf_breakpoint";
|
||||
/// Name of hash to id map column family
|
||||
/// Name of hash to id map column family.
|
||||
pub const CF_HASH_TO_ID: &str = "cf_hash_to_id";
|
||||
/// Name of tx hash to id map column family
|
||||
/// Name of tx hash to id map column family.
|
||||
pub const CF_TX_TO_ID: &str = "cf_tx_to_id";
|
||||
/// Name of account meta column family
|
||||
/// Name of account meta column family.
|
||||
pub const CF_ACC_META: &str = "cf_acc_meta";
|
||||
/// Name of account id to tx hash map column family
|
||||
/// Name of account id to tx hash map column family.
|
||||
pub const CF_ACC_TO_TX: &str = "cf_acc_to_tx";
|
||||
|
||||
pub type DbResult<T> = Result<T, DbError>;
|
||||
|
||||
fn closest_breakpoint_id(block_id: u64) -> u64 {
|
||||
block_id.saturating_sub(1).div(BREAKPOINT_INTERVAL)
|
||||
block_id
|
||||
.saturating_sub(1)
|
||||
.checked_div(u64::from(BREAKPOINT_INTERVAL))
|
||||
.expect("Breakpoint interval is not zero")
|
||||
}
|
||||
|
||||
pub struct RocksDBIO {
|
||||
@@ -66,7 +69,11 @@ pub struct RocksDBIO {
|
||||
}
|
||||
|
||||
impl RocksDBIO {
|
||||
pub fn open_or_create(path: &Path, start_data: Option<(Block, V02State)>) -> DbResult<Self> {
|
||||
pub fn open_or_create(
|
||||
path: &Path,
|
||||
genesis_block: &Block,
|
||||
initial_state: &V02State,
|
||||
) -> DbResult<Self> {
|
||||
let mut cf_opts = Options::default();
|
||||
cf_opts.set_max_write_buffer_number(16);
|
||||
// ToDo: Add more column families for different data
|
||||
@@ -85,49 +92,31 @@ impl RocksDBIO {
|
||||
&db_opts,
|
||||
path,
|
||||
vec![cfb, cfmeta, cfbreakpoint, cfhti, cftti, cfameta, cfatt],
|
||||
);
|
||||
)
|
||||
.map_err(|err| DbError::RocksDbError {
|
||||
error: err,
|
||||
additional_info: Some("Failed to open or create DB".to_owned()),
|
||||
})?;
|
||||
|
||||
let dbio = Self {
|
||||
// There is no point in handling this from runner code
|
||||
db: db.expect("We should have permissions to open DB"),
|
||||
};
|
||||
let dbio = Self { db };
|
||||
|
||||
let is_start_set = dbio.get_meta_is_first_block_set()?;
|
||||
|
||||
if is_start_set {
|
||||
Ok(dbio)
|
||||
} else if let Some((block, initial_state)) = start_data {
|
||||
let block_id = block.header.block_id;
|
||||
if !is_start_set {
|
||||
let block_id = genesis_block.header.block_id;
|
||||
dbio.put_meta_last_block_in_db(block_id)?;
|
||||
dbio.put_meta_first_block_in_db_batch(block)?;
|
||||
dbio.put_meta_first_block_in_db_batch(genesis_block)?;
|
||||
dbio.put_meta_is_first_block_set()?;
|
||||
|
||||
// First breakpoint setup
|
||||
dbio.put_breakpoint(0, initial_state)?;
|
||||
dbio.put_meta_last_breakpoint_id(0)?;
|
||||
|
||||
Ok(dbio)
|
||||
} else {
|
||||
// Here we are trying to start a DB without a block, one should not do it.
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
Ok(dbio)
|
||||
}
|
||||
|
||||
pub fn destroy(path: &Path) -> DbResult<()> {
|
||||
let mut cf_opts = Options::default();
|
||||
cf_opts.set_max_write_buffer_number(16);
|
||||
// ToDo: Add more column families for different data
|
||||
let _cfb = ColumnFamilyDescriptor::new(CF_BLOCK_NAME, cf_opts.clone());
|
||||
let _cfmeta = ColumnFamilyDescriptor::new(CF_META_NAME, cf_opts.clone());
|
||||
let _cfsnapshot = ColumnFamilyDescriptor::new(CF_BREAKPOINT_NAME, cf_opts.clone());
|
||||
let _cfhti = ColumnFamilyDescriptor::new(CF_HASH_TO_ID, cf_opts.clone());
|
||||
let _cftti = ColumnFamilyDescriptor::new(CF_TX_TO_ID, cf_opts.clone());
|
||||
let _cfameta = ColumnFamilyDescriptor::new(CF_ACC_META, cf_opts.clone());
|
||||
let _cfatt = ColumnFamilyDescriptor::new(CF_ACC_TO_TX, cf_opts.clone());
|
||||
|
||||
let mut db_opts = Options::default();
|
||||
db_opts.create_missing_column_families(true);
|
||||
db_opts.create_if_missing(true);
|
||||
let db_opts = Options::default();
|
||||
DBWithThreadMode::<MultiThreaded>::destroy(&db_opts, path)
|
||||
.map_err(|rerr| DbError::rocksdb_cast_message(rerr, None))
|
||||
}
|
||||
@@ -188,7 +177,9 @@ impl RocksDBIO {
|
||||
// ToDo: update it to handle any genesis id
|
||||
// right now works correctly only if genesis_id < BREAKPOINT_INTERVAL
|
||||
let start = if br_id != 0 {
|
||||
BREAKPOINT_INTERVAL * br_id
|
||||
u64::from(BREAKPOINT_INTERVAL)
|
||||
.checked_mul(br_id)
|
||||
.expect("Reached maximum breakpoint id")
|
||||
} else {
|
||||
self.get_meta_first_block_in_db()?
|
||||
};
|
||||
@@ -214,7 +205,7 @@ impl RocksDBIO {
|
||||
Ok(breakpoint)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block on this id not found".to_string(),
|
||||
"Block on this id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -224,8 +215,10 @@ impl RocksDBIO {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::shadow_unrelated)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use common::transaction::NSSATransaction;
|
||||
use nssa::AccountId;
|
||||
use tempfile::tempdir;
|
||||
|
||||
@@ -277,17 +270,17 @@ mod tests {
|
||||
}
|
||||
|
||||
common::test_utils::create_transaction_native_token_transfer(
|
||||
from, nonce, to, amount, sign_key,
|
||||
from, nonce, to, amount, &sign_key,
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_start_db() {
|
||||
fn start_db() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let first_id = dbio.get_meta_first_block_in_db().unwrap();
|
||||
@@ -315,18 +308,18 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_one_block_insertion() {
|
||||
fn one_block_insertion() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
let prev_hash = genesis_block().header.hash;
|
||||
let transfer_tx = transfer(1, 0, true);
|
||||
let block = common::test_utils::produce_dummy_block(2, Some(prev_hash), vec![transfer_tx]);
|
||||
|
||||
dbio.put_block(block, [1; 32]).unwrap();
|
||||
dbio.put_block(&block, [1; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let first_id = dbio.get_meta_first_block_in_db().unwrap();
|
||||
@@ -359,22 +352,25 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_new_breakpoint() {
|
||||
fn new_breakpoint() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
for i in 1..(BREAKPOINT_INTERVAL + 1) {
|
||||
for i in 1..=BREAKPOINT_INTERVAL {
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
|
||||
let prev_hash = last_block.header.hash;
|
||||
let transfer_tx = transfer(1, (i - 1) as u128, true);
|
||||
let block =
|
||||
common::test_utils::produce_dummy_block(i + 1, Some(prev_hash), vec![transfer_tx]);
|
||||
dbio.put_block(block, [i as u8; 32]).unwrap();
|
||||
let transfer_tx = transfer(1, (i - 1).into(), true);
|
||||
let block = common::test_utils::produce_dummy_block(
|
||||
(i + 1).into(),
|
||||
Some(prev_hash),
|
||||
vec![transfer_tx],
|
||||
);
|
||||
dbio.put_block(&block, [i; 32]).unwrap();
|
||||
}
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
@@ -414,12 +410,12 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_simple_maps() {
|
||||
fn simple_maps() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -430,7 +426,7 @@ mod tests {
|
||||
|
||||
let control_hash1 = block.header.hash;
|
||||
|
||||
dbio.put_block(block, [1; 32]).unwrap();
|
||||
dbio.put_block(&block, [1; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -441,7 +437,7 @@ mod tests {
|
||||
|
||||
let control_hash2 = block.header.hash;
|
||||
|
||||
dbio.put_block(block, [2; 32]).unwrap();
|
||||
dbio.put_block(&block, [2; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -452,7 +448,7 @@ mod tests {
|
||||
let control_tx_hash1 = transfer_tx.hash();
|
||||
|
||||
let block = common::test_utils::produce_dummy_block(4, Some(prev_hash), vec![transfer_tx]);
|
||||
dbio.put_block(block, [3; 32]).unwrap();
|
||||
dbio.put_block(&block, [3; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -463,7 +459,7 @@ mod tests {
|
||||
let control_tx_hash2 = transfer_tx.hash();
|
||||
|
||||
let block = common::test_utils::produce_dummy_block(5, Some(prev_hash), vec![transfer_tx]);
|
||||
dbio.put_block(block, [4; 32]).unwrap();
|
||||
dbio.put_block(&block, [4; 32]).unwrap();
|
||||
|
||||
let control_block_id1 = dbio.get_block_id_by_hash(control_hash1.0).unwrap();
|
||||
let control_block_id2 = dbio.get_block_id_by_hash(control_hash2.0).unwrap();
|
||||
@@ -477,14 +473,14 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_block_batch() {
|
||||
fn block_batch() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let mut block_res = vec![];
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -494,7 +490,7 @@ mod tests {
|
||||
let block = common::test_utils::produce_dummy_block(2, Some(prev_hash), vec![transfer_tx]);
|
||||
|
||||
block_res.push(block.clone());
|
||||
dbio.put_block(block, [1; 32]).unwrap();
|
||||
dbio.put_block(&block, [1; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -504,7 +500,7 @@ mod tests {
|
||||
let block = common::test_utils::produce_dummy_block(3, Some(prev_hash), vec![transfer_tx]);
|
||||
|
||||
block_res.push(block.clone());
|
||||
dbio.put_block(block, [2; 32]).unwrap();
|
||||
dbio.put_block(&block, [2; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -514,7 +510,7 @@ mod tests {
|
||||
|
||||
let block = common::test_utils::produce_dummy_block(4, Some(prev_hash), vec![transfer_tx]);
|
||||
block_res.push(block.clone());
|
||||
dbio.put_block(block, [3; 32]).unwrap();
|
||||
dbio.put_block(&block, [3; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -524,7 +520,7 @@ mod tests {
|
||||
|
||||
let block = common::test_utils::produce_dummy_block(5, Some(prev_hash), vec![transfer_tx]);
|
||||
block_res.push(block.clone());
|
||||
dbio.put_block(block, [4; 32]).unwrap();
|
||||
dbio.put_block(&block, [4; 32]).unwrap();
|
||||
|
||||
let block_hashes_mem: Vec<[u8; 32]> =
|
||||
block_res.into_iter().map(|bl| bl.header.hash.0).collect();
|
||||
@@ -563,12 +559,12 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_account_map() {
|
||||
fn account_map() {
|
||||
let temp_dir = tempdir().unwrap();
|
||||
let temdir_path = temp_dir.path();
|
||||
|
||||
let dbio = RocksDBIO::open_or_create(temdir_path, Some((genesis_block(), initial_state())))
|
||||
.unwrap();
|
||||
let dbio =
|
||||
RocksDBIO::open_or_create(temdir_path, &genesis_block(), &initial_state()).unwrap();
|
||||
|
||||
let mut tx_hash_res = vec![];
|
||||
|
||||
@@ -587,7 +583,7 @@ mod tests {
|
||||
vec![transfer_tx1, transfer_tx2],
|
||||
);
|
||||
|
||||
dbio.put_block(block, [1; 32]).unwrap();
|
||||
dbio.put_block(&block, [1; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -604,7 +600,7 @@ mod tests {
|
||||
vec![transfer_tx1, transfer_tx2],
|
||||
);
|
||||
|
||||
dbio.put_block(block, [2; 32]).unwrap();
|
||||
dbio.put_block(&block, [2; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -621,7 +617,7 @@ mod tests {
|
||||
vec![transfer_tx1, transfer_tx2],
|
||||
);
|
||||
|
||||
dbio.put_block(block, [3; 32]).unwrap();
|
||||
dbio.put_block(&block, [3; 32]).unwrap();
|
||||
|
||||
let last_id = dbio.get_meta_last_block_in_db().unwrap();
|
||||
let last_block = dbio.get_block(last_id).unwrap();
|
||||
@@ -632,7 +628,7 @@ mod tests {
|
||||
|
||||
let block = common::test_utils::produce_dummy_block(5, Some(prev_hash), vec![transfer_tx]);
|
||||
|
||||
dbio.put_block(block, [4; 32]).unwrap();
|
||||
dbio.put_block(&block, [4; 32]).unwrap();
|
||||
|
||||
let acc1_tx = dbio.get_acc_transactions(*acc1().value(), 0, 7).unwrap();
|
||||
let acc1_tx_hashes: Vec<[u8; 32]> = acc1_tx.into_iter().map(|tx| tx.hash().0).collect();
|
||||
@@ -643,6 +639,6 @@ mod tests {
|
||||
let acc1_tx_limited_hashes: Vec<[u8; 32]> =
|
||||
acc1_tx_limited.into_iter().map(|tx| tx.hash().0).collect();
|
||||
|
||||
assert_eq!(acc1_tx_limited_hashes.as_slice(), &tx_hash_res[1..5])
|
||||
assert_eq!(acc1_tx_limited_hashes.as_slice(), &tx_hash_res[1..5]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use common::transaction::NSSATransaction;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl RocksDBIO {
|
||||
@@ -39,7 +41,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
));
|
||||
@@ -56,7 +58,7 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<Block>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block data".to_string()),
|
||||
Some("Failed to deserialize block data".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
@@ -86,10 +88,7 @@ impl RocksDBIO {
|
||||
keys.push((
|
||||
&cf_tti,
|
||||
borsh::to_vec(tx_hash).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize tx_hash".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize tx_hash".to_owned()))
|
||||
})?,
|
||||
));
|
||||
}
|
||||
@@ -105,7 +104,7 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block id".to_string()),
|
||||
Some("Failed to deserialize block id".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
@@ -134,13 +133,10 @@ impl RocksDBIO {
|
||||
let mut keys = vec![];
|
||||
for tx_id in offset..(offset + limit) {
|
||||
let mut prefix = borsh::to_vec(&acc_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(
|
||||
berr,
|
||||
Some("Failed to serialize account id".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize account id".to_owned()))
|
||||
})?;
|
||||
let suffix = borsh::to_vec(&tx_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_string()))
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_owned()))
|
||||
})?;
|
||||
|
||||
prefix.extend_from_slice(&suffix);
|
||||
@@ -157,7 +153,7 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<[u8; 32]>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize tx_hash".to_string()),
|
||||
Some("Failed to deserialize tx_hash".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
|
||||
@@ -12,7 +12,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -22,12 +22,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize first block".to_string()),
|
||||
Some("Failed to deserialize first block".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"First block not found".to_string(),
|
||||
"First block not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -51,12 +51,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize last block".to_string()),
|
||||
Some("Failed to deserialize last block".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Last block not found".to_string(),
|
||||
"Last block not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ impl RocksDBIO {
|
||||
err,
|
||||
Some(
|
||||
"Failed to serialize DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY"
|
||||
.to_string(),
|
||||
.to_owned(),
|
||||
),
|
||||
)
|
||||
},
|
||||
@@ -85,7 +85,7 @@ impl RocksDBIO {
|
||||
borsh::from_slice::<[u8; 32]>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize last l1 lib header".to_string()),
|
||||
Some("Failed to deserialize last l1 lib header".to_owned()),
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -101,7 +101,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_SET_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -119,7 +119,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BREAKPOINT_ID).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -129,12 +129,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize last breakpoint id".to_string()),
|
||||
Some("Failed to deserialize last breakpoint id".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Last breakpoint id not found".to_string(),
|
||||
"Last breakpoint id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -160,12 +160,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<Block>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block data".to_string()),
|
||||
Some("Failed to deserialize block data".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block on this id not found".to_string(),
|
||||
"Block on this id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&br_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize breakpoint id".to_string()),
|
||||
Some("Failed to serialize breakpoint id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -191,12 +191,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<V02State>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize breakpoint data".to_string()),
|
||||
Some("Failed to deserialize breakpoint data".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Breakpoint on this id not found".to_string(),
|
||||
"Breakpoint on this id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&hash).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block hash".to_string()),
|
||||
Some("Failed to serialize block hash".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -220,14 +220,11 @@ impl RocksDBIO {
|
||||
|
||||
if let Some(data) = res {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block id".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(serr, Some("Failed to deserialize block id".to_owned()))
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block on this hash not found".to_string(),
|
||||
"Block on this hash not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -241,7 +238,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&tx_hash).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize transaction hash".to_string()),
|
||||
Some("Failed to serialize transaction hash".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -249,14 +246,11 @@ impl RocksDBIO {
|
||||
|
||||
if let Some(data) = res {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block id".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(serr, Some("Failed to deserialize block id".to_owned()))
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block for this tx hash not found".to_string(),
|
||||
"Block for this tx hash not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -266,12 +260,12 @@ impl RocksDBIO {
|
||||
pub(crate) fn get_acc_meta_num_tx(&self, acc_id: [u8; 32]) -> DbResult<Option<u64>> {
|
||||
let cf_ameta = self.account_meta_column();
|
||||
let res = self.db.get_cf(&cf_ameta, acc_id).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to read from acc meta cf".to_string()))
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to read from acc meta cf".to_owned()))
|
||||
})?;
|
||||
|
||||
res.map(|data| {
|
||||
borsh::from_slice::<u64>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(serr, Some("Failed to deserialize num tx".to_string()))
|
||||
DbError::borsh_cast_message(serr, Some("Failed to deserialize num tx".to_owned()))
|
||||
})
|
||||
})
|
||||
.transpose()
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use rocksdb::WriteBatch;
|
||||
|
||||
use super::*;
|
||||
|
||||
impl RocksDBIO {
|
||||
@@ -14,12 +18,12 @@ impl RocksDBIO {
|
||||
write_batch.put_cf(
|
||||
&cf_ameta,
|
||||
borsh::to_vec(&acc_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize account id".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize account id".to_owned()))
|
||||
})?,
|
||||
borsh::to_vec(&num_tx).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize acc metadata".to_string()),
|
||||
Some("Failed to serialize acc metadata".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -42,13 +46,10 @@ impl RocksDBIO {
|
||||
let put_id = acc_num_tx + tx_id as u64;
|
||||
|
||||
let mut prefix = borsh::to_vec(&acc_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(
|
||||
berr,
|
||||
Some("Failed to serialize account id".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize account id".to_owned()))
|
||||
})?;
|
||||
let suffix = borsh::to_vec(&put_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_string()))
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_owned()))
|
||||
})?;
|
||||
|
||||
prefix.extend_from_slice(&suffix);
|
||||
@@ -59,7 +60,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(tx_hash).map_err(|berr| {
|
||||
DbError::borsh_cast_message(
|
||||
berr,
|
||||
Some("Failed to serialize tx hash".to_string()),
|
||||
Some("Failed to serialize tx hash".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -72,7 +73,7 @@ impl RocksDBIO {
|
||||
)?;
|
||||
|
||||
self.db.write(write_batch).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to write batch".to_string()))
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to write batch".to_owned()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -89,13 +90,10 @@ impl RocksDBIO {
|
||||
let put_id = acc_num_tx + tx_id as u64;
|
||||
|
||||
let mut prefix = borsh::to_vec(&acc_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(
|
||||
berr,
|
||||
Some("Failed to serialize account id".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize account id".to_owned()))
|
||||
})?;
|
||||
let suffix = borsh::to_vec(&put_id).map_err(|berr| {
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_string()))
|
||||
DbError::borsh_cast_message(berr, Some("Failed to serialize tx id".to_owned()))
|
||||
})?;
|
||||
|
||||
prefix.extend_from_slice(&suffix);
|
||||
@@ -106,7 +104,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(tx_hash).map_err(|berr| {
|
||||
DbError::borsh_cast_message(
|
||||
berr,
|
||||
Some("Failed to serialize tx hash".to_string()),
|
||||
Some("Failed to serialize tx hash".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -119,7 +117,7 @@ impl RocksDBIO {
|
||||
|
||||
// Meta
|
||||
|
||||
pub fn put_meta_first_block_in_db_batch(&self, block: Block) -> DbResult<()> {
|
||||
pub fn put_meta_first_block_in_db_batch(&self, block: &Block) -> DbResult<()> {
|
||||
let cf_meta = self.meta_column();
|
||||
self.db
|
||||
.put_cf(
|
||||
@@ -127,13 +125,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize first block id".to_string()),
|
||||
Some("Failed to serialize first block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -154,13 +152,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -180,14 +178,14 @@ impl RocksDBIO {
|
||||
err,
|
||||
Some(
|
||||
"Failed to serialize DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY"
|
||||
.to_string(),
|
||||
.to_owned(),
|
||||
),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&l1_lib_header).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last l1 block header".to_string()),
|
||||
Some("Failed to serialize last l1 block header".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -205,13 +203,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BREAKPOINT_ID).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&br_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -225,7 +223,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_SET_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
[1u8; 1],
|
||||
@@ -235,7 +233,7 @@ impl RocksDBIO {
|
||||
|
||||
// Block
|
||||
|
||||
pub fn put_block(&self, block: Block, l1_lib_header: [u8; 32]) -> DbResult<()> {
|
||||
pub fn put_block(&self, block: &Block, l1_lib_header: [u8; 32]) -> DbResult<()> {
|
||||
let cf_block = self.block_column();
|
||||
let cf_hti = self.hash_to_id_column();
|
||||
let cf_tti: Arc<BoundColumnFamily<'_>> = self.tx_hash_to_id_column();
|
||||
@@ -245,10 +243,10 @@ impl RocksDBIO {
|
||||
write_batch.put_cf(
|
||||
&cf_block,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_owned()))
|
||||
})?,
|
||||
borsh::to_vec(&block).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block data".to_string()))
|
||||
borsh::to_vec(block).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block data".to_owned()))
|
||||
})?,
|
||||
);
|
||||
|
||||
@@ -260,30 +258,27 @@ impl RocksDBIO {
|
||||
write_batch.put_cf(
|
||||
&cf_hti,
|
||||
borsh::to_vec(&block.header.hash).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block hash".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block hash".to_owned()))
|
||||
})?,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_owned()))
|
||||
})?,
|
||||
);
|
||||
|
||||
let mut acc_to_tx_map: HashMap<[u8; 32], Vec<[u8; 32]>> = HashMap::new();
|
||||
|
||||
for tx in block.body.transactions {
|
||||
for tx in &block.body.transactions {
|
||||
let tx_hash = tx.hash();
|
||||
|
||||
write_batch.put_cf(
|
||||
&cf_tti,
|
||||
borsh::to_vec(&tx_hash).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize tx hash".to_string()),
|
||||
)
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize tx hash".to_owned()))
|
||||
})?,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -302,15 +297,23 @@ impl RocksDBIO {
|
||||
}
|
||||
}
|
||||
|
||||
#[expect(
|
||||
clippy::iter_over_hash_type,
|
||||
reason = "RocksDB will keep ordering persistent"
|
||||
)]
|
||||
for (acc_id, tx_hashes) in acc_to_tx_map {
|
||||
self.put_account_transactions_dependant(acc_id, tx_hashes, &mut write_batch)?;
|
||||
}
|
||||
|
||||
self.db.write(write_batch).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to write batch".to_string()))
|
||||
DbError::rocksdb_cast_message(rerr, Some("Failed to write batch".to_owned()))
|
||||
})?;
|
||||
|
||||
if block.header.block_id.is_multiple_of(BREAKPOINT_INTERVAL) {
|
||||
if block
|
||||
.header
|
||||
.block_id
|
||||
.is_multiple_of(BREAKPOINT_INTERVAL.into())
|
||||
{
|
||||
self.put_next_breakpoint()?;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -39,7 +39,7 @@ impl RocksDBIO {
|
||||
err,
|
||||
Some(
|
||||
"Failed to serialize DB_META_LAST_OBSERVED_L1_LIB_HEADER_ID_IN_DB_KEY"
|
||||
.to_string(),
|
||||
.to_owned(),
|
||||
),
|
||||
)
|
||||
},
|
||||
@@ -47,7 +47,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&l1_lib_header).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last l1 block header".to_string()),
|
||||
Some("Failed to serialize last l1 block header".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -63,13 +63,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BREAKPOINT_ID).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BREAKPOINT_ID".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&br_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -85,7 +85,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_SET_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
[1u8; 1],
|
||||
@@ -96,7 +96,7 @@ impl RocksDBIO {
|
||||
|
||||
// State
|
||||
|
||||
pub fn put_breakpoint(&self, br_id: u64, breakpoint: V02State) -> DbResult<()> {
|
||||
pub fn put_breakpoint(&self, br_id: u64, breakpoint: &V02State) -> DbResult<()> {
|
||||
let cf_br = self.breakpoint_column();
|
||||
|
||||
self.db
|
||||
@@ -105,13 +105,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&br_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize breakpoint id".to_string()),
|
||||
Some("Failed to serialize breakpoint id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&breakpoint).map_err(|err| {
|
||||
borsh::to_vec(breakpoint).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize breakpoint data".to_string()),
|
||||
Some("Failed to serialize breakpoint data".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -121,16 +121,18 @@ impl RocksDBIO {
|
||||
pub fn put_next_breakpoint(&self) -> DbResult<()> {
|
||||
let last_block = self.get_meta_last_block_in_db()?;
|
||||
let next_breakpoint_id = self.get_meta_last_breakpoint_id()? + 1;
|
||||
let block_to_break_id = next_breakpoint_id * BREAKPOINT_INTERVAL;
|
||||
let block_to_break_id = next_breakpoint_id
|
||||
.checked_mul(u64::from(BREAKPOINT_INTERVAL))
|
||||
.expect("Reached maximum breakpoint id");
|
||||
|
||||
if block_to_break_id <= last_block {
|
||||
let next_breakpoint = self.calculate_state_for_id(block_to_break_id)?;
|
||||
|
||||
self.put_breakpoint(next_breakpoint_id, next_breakpoint)?;
|
||||
self.put_breakpoint(next_breakpoint_id, &next_breakpoint)?;
|
||||
self.put_meta_last_breakpoint_id(next_breakpoint_id)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Breakpoint not yet achieved".to_string(),
|
||||
"Breakpoint not yet achieved".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
+70
-74
@@ -8,37 +8,37 @@ use rocksdb::{
|
||||
|
||||
use crate::error::DbError;
|
||||
|
||||
/// Maximal size of stored blocks in base
|
||||
/// Maximal size of stored blocks in base.
|
||||
///
|
||||
/// Used to control db size
|
||||
/// Used to control db size.
|
||||
///
|
||||
/// Currently effectively unbounded.
|
||||
pub const BUFF_SIZE_ROCKSDB: usize = usize::MAX;
|
||||
|
||||
/// Size of stored blocks cache in memory
|
||||
/// Size of stored blocks cache in memory.
|
||||
///
|
||||
/// Keeping small to not run out of memory
|
||||
/// Keeping small to not run out of memory.
|
||||
pub const CACHE_SIZE: usize = 1000;
|
||||
|
||||
/// Key base for storing metainformation about id of first block in db
|
||||
/// Key base for storing metainformation about id of first block in db.
|
||||
pub const DB_META_FIRST_BLOCK_IN_DB_KEY: &str = "first_block_in_db";
|
||||
/// Key base for storing metainformation about id of last current block in db
|
||||
/// Key base for storing metainformation about id of last current block in db.
|
||||
pub const DB_META_LAST_BLOCK_IN_DB_KEY: &str = "last_block_in_db";
|
||||
/// Key base for storing metainformation which describe if first block has been set
|
||||
/// Key base for storing metainformation which describe if first block has been set.
|
||||
pub const DB_META_FIRST_BLOCK_SET_KEY: &str = "first_block_set";
|
||||
/// Key base for storing metainformation about the last finalized block on Bedrock
|
||||
/// Key base for storing metainformation about the last finalized block on Bedrock.
|
||||
pub const DB_META_LAST_FINALIZED_BLOCK_ID: &str = "last_finalized_block_id";
|
||||
/// Key base for storing metainformation about the latest block meta
|
||||
/// Key base for storing metainformation about the latest block meta.
|
||||
pub const DB_META_LATEST_BLOCK_META_KEY: &str = "latest_block_meta";
|
||||
|
||||
/// Key base for storing the NSSA state
|
||||
/// Key base for storing the NSSA state.
|
||||
pub const DB_NSSA_STATE_KEY: &str = "nssa_state";
|
||||
|
||||
/// Name of block column family
|
||||
/// Name of block column family.
|
||||
pub const CF_BLOCK_NAME: &str = "cf_block";
|
||||
/// Name of meta column family
|
||||
/// Name of meta column family.
|
||||
pub const CF_META_NAME: &str = "cf_meta";
|
||||
/// Name of state column family
|
||||
/// Name of state column family.
|
||||
pub const CF_NSSA_STATE_NAME: &str = "cf_nssa_state";
|
||||
|
||||
pub type DbResult<T> = Result<T, DbError>;
|
||||
@@ -50,7 +50,8 @@ pub struct RocksDBIO {
|
||||
impl RocksDBIO {
|
||||
pub fn open_or_create(
|
||||
path: &Path,
|
||||
start_block: Option<(&Block, MantleMsgId)>,
|
||||
genesis_block: &Block,
|
||||
genesis_msg_id: MantleMsgId,
|
||||
) -> DbResult<Self> {
|
||||
let mut cf_opts = Options::default();
|
||||
cf_opts.set_max_write_buffer_number(16);
|
||||
@@ -66,34 +67,29 @@ impl RocksDBIO {
|
||||
&db_opts,
|
||||
path,
|
||||
vec![cfb, cfmeta, cfstate],
|
||||
);
|
||||
)
|
||||
.map_err(|err| DbError::RocksDbError {
|
||||
error: err,
|
||||
additional_info: Some("Failed to open or create DB".to_owned()),
|
||||
})?;
|
||||
|
||||
let dbio = Self {
|
||||
// There is no point in handling this from runner code
|
||||
db: db.unwrap(),
|
||||
};
|
||||
let dbio = Self { db };
|
||||
|
||||
let is_start_set = dbio.get_meta_is_first_block_set()?;
|
||||
|
||||
if is_start_set {
|
||||
Ok(dbio)
|
||||
} else if let Some((block, msg_id)) = start_block {
|
||||
let block_id = block.header.block_id;
|
||||
dbio.put_meta_first_block_in_db(block, msg_id)?;
|
||||
if !is_start_set {
|
||||
let block_id = genesis_block.header.block_id;
|
||||
dbio.put_meta_first_block_in_db(genesis_block, genesis_msg_id)?;
|
||||
dbio.put_meta_is_first_block_set()?;
|
||||
dbio.put_meta_last_block_in_db(block_id)?;
|
||||
dbio.put_meta_last_finalized_block_id(None)?;
|
||||
dbio.put_meta_latest_block_meta(&BlockMeta {
|
||||
id: block.header.block_id,
|
||||
hash: block.header.hash,
|
||||
msg_id,
|
||||
id: genesis_block.header.block_id,
|
||||
hash: genesis_block.header.hash,
|
||||
msg_id: genesis_msg_id,
|
||||
})?;
|
||||
|
||||
Ok(dbio)
|
||||
} else {
|
||||
// Here we are trying to start a DB without a block, one should not do it.
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
Ok(dbio)
|
||||
}
|
||||
|
||||
pub fn destroy(path: &Path) -> DbResult<()> {
|
||||
@@ -132,7 +128,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -142,12 +138,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize first block".to_string()),
|
||||
Some("Failed to deserialize first block".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"First block not found".to_string(),
|
||||
"First block not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -161,7 +157,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -171,12 +167,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<u64>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize last block".to_string()),
|
||||
Some("Failed to deserialize last block".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Last block not found".to_string(),
|
||||
"Last block not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -190,7 +186,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_SET_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -206,11 +202,11 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_NSSA_STATE_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_NSSA_STATE_KEY".to_string()),
|
||||
Some("Failed to serialize DB_NSSA_STATE_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(state).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize NSSA state".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize NSSA state".to_owned()))
|
||||
})?,
|
||||
);
|
||||
|
||||
@@ -225,13 +221,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize first block id".to_string()),
|
||||
Some("Failed to serialize first block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -242,7 +238,7 @@ impl RocksDBIO {
|
||||
self.db.write(batch).map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(
|
||||
rerr,
|
||||
Some("Failed to write first block in db".to_string()),
|
||||
Some("Failed to write first block in db".to_owned()),
|
||||
)
|
||||
})?;
|
||||
|
||||
@@ -257,13 +253,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -282,13 +278,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_BLOCK_IN_DB_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_BLOCK_IN_DB_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -303,13 +299,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LAST_FINALIZED_BLOCK_ID).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LAST_FINALIZED_BLOCK_ID".to_string()),
|
||||
Some("Failed to serialize DB_META_LAST_FINALIZED_BLOCK_ID".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize last block id".to_string()),
|
||||
Some("Failed to serialize last block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -325,10 +321,10 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_FIRST_BLOCK_SET_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_FIRST_BLOCK_SET_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
[1u8; 1],
|
||||
[1_u8; 1],
|
||||
)
|
||||
.map_err(|rerr| DbError::rocksdb_cast_message(rerr, None))?;
|
||||
Ok(())
|
||||
@@ -342,13 +338,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LATEST_BLOCK_META_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_meta).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize latest block meta".to_string()),
|
||||
Some("Failed to serialize latest block meta".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -367,13 +363,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LATEST_BLOCK_META_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block_meta).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize latest block meta".to_string()),
|
||||
Some("Failed to serialize latest block meta".to_owned()),
|
||||
)
|
||||
})?,
|
||||
);
|
||||
@@ -389,7 +385,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_META_LATEST_BLOCK_META_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_string()),
|
||||
Some("Failed to serialize DB_META_LATEST_BLOCK_META_KEY".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -399,12 +395,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<BlockMeta>(&data).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize latest block meta".to_string()),
|
||||
Some("Failed to deserialize latest block meta".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Latest block meta not found".to_string(),
|
||||
"Latest block meta not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -437,10 +433,10 @@ impl RocksDBIO {
|
||||
batch.put_cf(
|
||||
&cf_block,
|
||||
borsh::to_vec(&block.header.block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_owned()))
|
||||
})?,
|
||||
borsh::to_vec(block).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block data".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block data".to_owned()))
|
||||
})?,
|
||||
);
|
||||
Ok(())
|
||||
@@ -455,7 +451,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -465,12 +461,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<Block>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block data".to_string()),
|
||||
Some("Failed to deserialize block data".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block on this id not found".to_string(),
|
||||
"Block on this id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -484,7 +480,7 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&DB_NSSA_STATE_KEY).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -494,12 +490,12 @@ impl RocksDBIO {
|
||||
Ok(borsh::from_slice::<V02State>(&data).map_err(|serr| {
|
||||
DbError::borsh_cast_message(
|
||||
serr,
|
||||
Some("Failed to deserialize block data".to_string()),
|
||||
Some("Failed to deserialize block data".to_owned()),
|
||||
)
|
||||
})?)
|
||||
} else {
|
||||
Err(DbError::db_interaction_error(
|
||||
"Block on this id not found".to_string(),
|
||||
"Block on this id not found".to_owned(),
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -507,7 +503,7 @@ impl RocksDBIO {
|
||||
pub fn delete_block(&self, block_id: u64) -> DbResult<()> {
|
||||
let cf_block = self.block_column();
|
||||
let key = borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_string()))
|
||||
DbError::borsh_cast_message(err, Some("Failed to serialize block id".to_owned()))
|
||||
})?;
|
||||
|
||||
if self
|
||||
@@ -517,7 +513,7 @@ impl RocksDBIO {
|
||||
.is_none()
|
||||
{
|
||||
return Err(DbError::db_interaction_error(
|
||||
"Block on this id not found".to_string(),
|
||||
"Block on this id not found".to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -539,13 +535,13 @@ impl RocksDBIO {
|
||||
borsh::to_vec(&block_id).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block id".to_string()),
|
||||
Some("Failed to serialize block id".to_owned()),
|
||||
)
|
||||
})?,
|
||||
borsh::to_vec(&block).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to serialize block data".to_string()),
|
||||
Some("Failed to serialize block data".to_owned()),
|
||||
)
|
||||
})?,
|
||||
)
|
||||
@@ -567,14 +563,14 @@ impl RocksDBIO {
|
||||
let (_key, value) = res.map_err(|rerr| {
|
||||
DbError::rocksdb_cast_message(
|
||||
rerr,
|
||||
Some("Failed to get key value pair".to_string()),
|
||||
Some("Failed to get key value pair".to_owned()),
|
||||
)
|
||||
})?;
|
||||
|
||||
borsh::from_slice::<Block>(&value).map_err(|err| {
|
||||
DbError::borsh_cast_message(
|
||||
err,
|
||||
Some("Failed to deserialize block data".to_string()),
|
||||
Some("Failed to deserialize block data".to_owned()),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user