Select Git revision
build-deb.md
-
* remove /ws from listen address * fix error when user already exist * change binary to duniter2 * add rpc-cors * add config documentation * add reference in service files * use embedded distance oracle * optimize ci * use docker cache * add systemd timer * add documentation * fix base_path default * add duniter user * add services * update docs * add deb package to ci * add deb docker building
* remove /ws from listen address * fix error when user already exist * change binary to duniter2 * add rpc-cors * add config documentation * add reference in service files * use embedded distance oracle * optimize ci * use docker cache * add systemd timer * add documentation * fix base_path default * add duniter user * add services * update docs * add deb package to ci * add deb docker building
blocks_chunks.rs 4.86 KiB
// Copyright (C) 2020 Éloïs SANCHEZ.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::*;
use flate2::read::ZlibDecoder;
use flate2::write::ZlibEncoder;
use flate2::Compression;
const CHUNK_SIZE: u32 = 4_096;
const CHUNK_FILE_PREFIX: &str = "_";
const CHUNK_FILE_EXT: &str = ".bin.gz";
pub fn apply_block_blocks_chunk<B: Backend>(
block: &DubpBlockV10,
gva_db: &GvaV1Db<B>,
profile_path: &Path,
) -> KvResult<()> {
let block_number = block.number().0;
let chunks_folder_path = profile_path.join("data/gva_v1_blocks_chunks");
gva_db.current_blocks_chunk_write().upsert(
U32BE(block_number),
GvaBlockDbV1(DubpBlock::V10(block.clone())),
)?;
if (block_number + 1) % CHUNK_SIZE == 0 {
let current_chunk: Vec<GvaBlockDbV1> = gva_db
.current_blocks_chunk()
.iter(.., |it| it.values().collect::<Result<Vec<_>, _>>())?;
let current_chunk_bin = bincode_db()
.serialize(¤t_chunk)
.map_err(|e| KvError::DeserError(e.into()))?;
let chunk_hash = Hash::compute_blake3(current_chunk_bin.as_ref());
let chunk_index = U32BE(block_number / CHUNK_SIZE);
gva_db
.blocks_chunk_hash_write()
.upsert(chunk_index, HashDb(chunk_hash))?;
write_and_compress_chunk_in_file(
current_chunk_bin.as_ref(),
chunk_index.0,
chunks_folder_path.as_path(),
)
.map_err(|e| KvError::Custom(e.into()))?;
gva_db.current_blocks_chunk_write().clear()?;
}
Ok(())
}
pub fn revert_block_blocks_chunk<B: Backend>(
block: &DubpBlockV10,
gva_db: &GvaV1Db<B>,
profile_path: &Path,
) -> KvResult<()> {
let block_number = block.number().0;
let chunks_folder_path = profile_path.join("data/gva_v1_blocks_chunks");
gva_db.write(|mut db| {