From 606cca622797b1ad609c24a18654b2e9121b414e Mon Sep 17 00:00:00 2001 From: librelois <c@elo.tf> Date: Sat, 20 Mar 2021 19:11:33 +0100 Subject: [PATCH] [fix]: fill current meta db on start --- rust-libs/duniter-server/src/fill_cm_db.rs | 31 ++++++++++++++++++++++ rust-libs/duniter-server/src/lib.rs | 4 +++ 2 files changed, 35 insertions(+) create mode 100644 rust-libs/duniter-server/src/fill_cm_db.rs diff --git a/rust-libs/duniter-server/src/fill_cm_db.rs b/rust-libs/duniter-server/src/fill_cm_db.rs new file mode 100644 index 000000000..dfa4c3390 --- /dev/null +++ b/rust-libs/duniter-server/src/fill_cm_db.rs @@ -0,0 +1,31 @@ +// 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 duniter_dbs::databases::bc_v2::BcV2DbReadable; + +pub(super) fn fill_current_meta_db(shared_dbs: &SharedDbs<FileBackend>) -> anyhow::Result<()> { + if let Some(current_block_meta) = shared_dbs + .bc_db_ro + .blocks_meta() + .iter_rev(.., |it| it.values().next_res())? + { + shared_dbs + .cm_db + .current_block_meta_write() + .upsert((), current_block_meta)?; + } + Ok(()) +} diff --git a/rust-libs/duniter-server/src/lib.rs b/rust-libs/duniter-server/src/lib.rs index f8d980989..202335877 100644 --- a/rust-libs/duniter-server/src/lib.rs +++ b/rust-libs/duniter-server/src/lib.rs @@ -22,6 +22,7 @@ unused_import_braces )] +mod fill_cm_db; mod legacy; pub use duniter_conf::{gva_conf::GvaConf, DuniterConf, DuniterMode}; @@ -119,6 +120,9 @@ impl DuniterServer { let threadpool = fast_threadpool::ThreadPool::start(ThreadPoolConfig::default(), shared_dbs.clone()); + // Fill CmV1Db + fill_cm_db::fill_current_meta_db(&shared_dbs)?; + if conf.gva.is_some() { log::info!("start duniter modules..."); let runtime = tokio::runtime::Builder::new_multi_thread() -- GitLab