feat(blocks_chunks): increase chunk size
This commit is contained in:
parent
f8c5e0a0af
commit
8aecd22b91
1 changed files with 7 additions and 5 deletions
|
@ -15,6 +15,8 @@
|
|||
|
||||
use crate::*;
|
||||
|
||||
const CHUNK_SIZE: u32 = 4_096;
|
||||
|
||||
pub(super) fn apply_block_blocks_chunk<B: Backend>(
|
||||
block: &DubpBlockV10,
|
||||
gva_db: &mut GvaV1DbTxRw<B::Col>,
|
||||
|
@ -25,7 +27,7 @@ pub(super) fn apply_block_blocks_chunk<B: Backend>(
|
|||
GvaBlockDbV1(DubpBlock::V10(block.clone())),
|
||||
);
|
||||
|
||||
if block_number % 1_000 == 999 {
|
||||
if (block_number + 1) % CHUNK_SIZE == 0 {
|
||||
let current_chunk: Vec<GvaBlockDbV1> = gva_db
|
||||
.current_blocks_chunk
|
||||
.iter(.., |it| it.values().collect::<Result<Vec<_>, _>>())?;
|
||||
|
@ -34,7 +36,7 @@ pub(super) fn apply_block_blocks_chunk<B: Backend>(
|
|||
.map_err(|e| KvError::DeserError(e.into()))?;
|
||||
let chunk_hash = Hash::compute_blake3(current_chunk_bin.as_ref());
|
||||
let compressed_chunk = lz4_flex::compress_prepend_size(current_chunk_bin.as_ref());
|
||||
let chunk_index = U32BE(block_number / 1_000);
|
||||
let chunk_index = U32BE(block_number / CHUNK_SIZE);
|
||||
gva_db
|
||||
.blocks_chunk_hash
|
||||
.upsert(chunk_index, HashDb(chunk_hash));
|
||||
|
@ -51,9 +53,9 @@ pub(super) fn revert_block_blocks_chunk<B: Backend>(
|
|||
gva_db: &mut GvaV1DbTxRw<B::Col>,
|
||||
) -> KvResult<()> {
|
||||
let block_number = block.number().0;
|
||||
if block_number % 1_000 == 999 {
|
||||
if (block_number + 1) % CHUNK_SIZE == 0 {
|
||||
// Uncompress las compressed chunk and replace it in current chunk
|
||||
let chunk_index = U32BE(block_number / 1_000);
|
||||
let chunk_index = U32BE(block_number / CHUNK_SIZE);
|
||||
if let Some(compressed_chunk) = gva_db.compressed_blocks_chunk.get(&chunk_index)? {
|
||||
gva_db.blocks_chunk_hash.remove(chunk_index);
|
||||
gva_db.compressed_blocks_chunk.remove(chunk_index);
|
||||
|
@ -62,7 +64,7 @@ pub(super) fn revert_block_blocks_chunk<B: Backend>(
|
|||
let current_chunk: Vec<GvaBlockDbV1> = bincode_db()
|
||||
.deserialize(current_chunk_bin.as_ref())
|
||||
.map_err(|e| KvError::DeserError(e.into()))?;
|
||||
let current_chunk_begin = block_number - 999;
|
||||
let current_chunk_begin = block_number - CHUNK_SIZE + 1;
|
||||
for (i, block) in current_chunk.into_iter().enumerate() {
|
||||
gva_db
|
||||
.current_blocks_chunk
|
||||
|
|
Loading…
Add table
Reference in a new issue