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 0000000000000000000000000000000000000000..dfa4c3390930c036a49435bfb581aff8a4fe63d5 --- /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 f8d98098964ea52de01d5e0581be4c11eaba4568..2023358773713b96e32375f4fa685c3b3c720d00 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()