From 8aecd22b91daf698d0c158bab5ee7cbaa3be1fb0 Mon Sep 17 00:00:00 2001 From: librelois Date: Sun, 16 May 2021 23:17:05 +0200 Subject: [PATCH] =?UTF-8?q?feat(blocks=5Fchunks):=C2=A0increase=20chunk=20?= =?UTF-8?q?size?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- indexer/src/blocks_chunks.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/indexer/src/blocks_chunks.rs b/indexer/src/blocks_chunks.rs index 4703be6..320e39a 100644 --- a/indexer/src/blocks_chunks.rs +++ b/indexer/src/blocks_chunks.rs @@ -15,6 +15,8 @@ use crate::*; +const CHUNK_SIZE: u32 = 4_096; + pub(super) fn apply_block_blocks_chunk( block: &DubpBlockV10, gva_db: &mut GvaV1DbTxRw, @@ -25,7 +27,7 @@ pub(super) fn apply_block_blocks_chunk( GvaBlockDbV1(DubpBlock::V10(block.clone())), ); - if block_number % 1_000 == 999 { + if (block_number + 1) % CHUNK_SIZE == 0 { let current_chunk: Vec = gva_db .current_blocks_chunk .iter(.., |it| it.values().collect::, _>>())?; @@ -34,7 +36,7 @@ pub(super) fn apply_block_blocks_chunk( .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( gva_db: &mut GvaV1DbTxRw, ) -> 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( let current_chunk: Vec = 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