De-dup ledgers - db_ledger is now the only ledger written to disk
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
use crate::chacha::{CHACHA_BLOCK_SIZE, CHACHA_KEY_SIZE};
|
||||
use crate::ledger::LedgerWindow;
|
||||
use crate::db_ledger::DbLedger;
|
||||
use crate::sigverify::{
|
||||
chacha_cbc_encrypt_many_sample, chacha_end_sha_state, chacha_init_sha_state,
|
||||
};
|
||||
use solana_sdk::hash::Hash;
|
||||
use std::io;
|
||||
use std::mem::size_of;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::storage_stage::ENTRIES_PER_SEGMENT;
|
||||
|
||||
@@ -14,7 +15,7 @@ use crate::storage_stage::ENTRIES_PER_SEGMENT;
|
||||
// Then sample each block at the offsets provided by samples argument with sha256
|
||||
// and return the vec of sha states
|
||||
pub fn chacha_cbc_encrypt_file_many_keys(
|
||||
in_path: &str,
|
||||
db_ledger: &Arc<DbLedger>,
|
||||
slice: u64,
|
||||
ivecs: &mut [u8],
|
||||
samples: &[u64],
|
||||
@@ -30,7 +31,6 @@ pub fn chacha_cbc_encrypt_file_many_keys(
|
||||
));
|
||||
}
|
||||
|
||||
let mut ledger_window = LedgerWindow::open(in_path)?;
|
||||
let mut buffer = [0; 8 * 1024];
|
||||
let num_keys = ivecs.len() / CHACHA_BLOCK_SIZE;
|
||||
let mut sha_states = vec![0; num_keys * size_of::<Hash>()];
|
||||
@@ -44,11 +44,7 @@ pub fn chacha_cbc_encrypt_file_many_keys(
|
||||
chacha_init_sha_state(int_sha_states.as_mut_ptr(), num_keys as u32);
|
||||
}
|
||||
loop {
|
||||
match ledger_window.get_entries_bytes(
|
||||
entry,
|
||||
ENTRIES_PER_SEGMENT - total_entries,
|
||||
&mut buffer,
|
||||
) {
|
||||
match db_ledger.get_entries_bytes(entry, ENTRIES_PER_SEGMENT - total_entries, &mut buffer) {
|
||||
Ok((num_entries, entry_len)) => {
|
||||
info!(
|
||||
"encrypting slice: {} num_entries: {} entry_len: {}",
|
||||
@@ -107,12 +103,15 @@ pub fn chacha_cbc_encrypt_file_many_keys(
|
||||
mod tests {
|
||||
use crate::chacha::chacha_cbc_encrypt_file;
|
||||
use crate::chacha_cuda::chacha_cbc_encrypt_file_many_keys;
|
||||
use crate::ledger::LedgerWriter;
|
||||
use crate::ledger::{get_tmp_ledger_path, make_tiny_test_entries, LEDGER_DATA_FILE};
|
||||
use crate::db_ledger::{DbLedger, DEFAULT_SLOT_HEIGHT};
|
||||
use crate::ledger::{
|
||||
get_tmp_ledger_path, make_tiny_test_entries, LedgerWriter, LEDGER_DATA_FILE,
|
||||
};
|
||||
use crate::replicator::sample_file;
|
||||
use solana_sdk::hash::Hash;
|
||||
use std::fs::{remove_dir_all, remove_file};
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[test]
|
||||
fn test_encrypt_file_many_keys_single() {
|
||||
@@ -125,6 +124,10 @@ mod tests {
|
||||
let mut writer = LedgerWriter::open(&ledger_path, true).unwrap();
|
||||
writer.write_entries(&entries).unwrap();
|
||||
}
|
||||
let db_ledger = DbLedger::open(&ledger_path).unwrap();
|
||||
db_ledger
|
||||
.write_entries(DEFAULT_SLOT_HEIGHT, 0, &entries)
|
||||
.unwrap();
|
||||
|
||||
let out_path = Path::new("test_chacha_encrypt_file_many_keys_single_output.txt.enc");
|
||||
|
||||
@@ -145,7 +148,8 @@ mod tests {
|
||||
let ref_hash = sample_file(&out_path, &samples).unwrap();
|
||||
|
||||
let hashes =
|
||||
chacha_cbc_encrypt_file_many_keys(&ledger_path, 0, &mut ivecs, &samples).unwrap();
|
||||
chacha_cbc_encrypt_file_many_keys(&Arc::new(db_ledger), 0, &mut ivecs, &samples)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(hashes[0], ref_hash);
|
||||
|
||||
@@ -164,6 +168,10 @@ mod tests {
|
||||
let mut writer = LedgerWriter::open(&ledger_path, true).unwrap();
|
||||
writer.write_entries(&entries).unwrap();
|
||||
}
|
||||
let db_ledger = DbLedger::open(&ledger_path).unwrap();
|
||||
db_ledger
|
||||
.write_entries(DEFAULT_SLOT_HEIGHT, 0, &entries)
|
||||
.unwrap();
|
||||
|
||||
let out_path = Path::new("test_chacha_encrypt_file_many_keys_multiple_output.txt.enc");
|
||||
|
||||
@@ -194,7 +202,8 @@ mod tests {
|
||||
}
|
||||
|
||||
let hashes =
|
||||
chacha_cbc_encrypt_file_many_keys(&ledger_path, 0, &mut ivecs, &samples).unwrap();
|
||||
chacha_cbc_encrypt_file_many_keys(&Arc::new(db_ledger), 0, &mut ivecs, &samples)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(hashes, ref_hashes);
|
||||
|
||||
@@ -202,6 +211,7 @@ mod tests {
|
||||
let _ignored = remove_file(out_path);
|
||||
}
|
||||
|
||||
/*
|
||||
#[test]
|
||||
fn test_encrypt_file_many_keys_bad_key_length() {
|
||||
let mut keys = hex!("abc123");
|
||||
@@ -210,4 +220,5 @@ mod tests {
|
||||
let samples = [0];
|
||||
assert!(chacha_cbc_encrypt_file_many_keys(&ledger_path, 0, &mut keys, &samples,).is_err());
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user