From e3f8f29d7c92419c4334a9be25522664a0d3f09b Mon Sep 17 00:00:00 2001
From: "[1000i100] Millicent Billette" <git@1000i100.fr>
Date: Mon, 7 Oct 2019 02:30:56 +0200
Subject: [PATCH] wip bc-db-writer roadmap

---
 .../blockchain/bc-db-writer/src/blocks.rs     |  2 +-
 .../bc-db-writer/src/current_frame.rs         | 37 +++++++++++++++++++
 .../blockchain/bc-db-writer/src/lib.rs        |  1 -
 .../blockchain/bc-db-writer/src/store_name.rs | 29 ---------------
 4 files changed, 38 insertions(+), 31 deletions(-)
 delete mode 100644 lib/modules/blockchain/bc-db-writer/src/store_name.rs

diff --git a/lib/modules/blockchain/bc-db-writer/src/blocks.rs b/lib/modules/blockchain/bc-db-writer/src/blocks.rs
index 7757e50c..187c62e4 100644
--- a/lib/modules/blockchain/bc-db-writer/src/blocks.rs
+++ b/lib/modules/blockchain/bc-db-writer/src/blocks.rs
@@ -50,7 +50,7 @@ pub fn insert_new_head_block(
     crate::current_meta_datas::update_current_meta_datas(db, w, &dal_block.block)?;
 
     // Update stores linked to MAIN_BLOCKS
-    crate::store_name::update_store_name(db, w, &dal_block.block)?;
+    crate::current_frame::update_current_frame(db, w, &dal_block.block)?;
 
     if let Some(fork_tree) = fork_tree {
         // Insert head block in fork tree
diff --git a/lib/modules/blockchain/bc-db-writer/src/current_frame.rs b/lib/modules/blockchain/bc-db-writer/src/current_frame.rs
index 60c59719..28b6a5bf 100644
--- a/lib/modules/blockchain/bc-db-writer/src/current_frame.rs
+++ b/lib/modules/blockchain/bc-db-writer/src/current_frame.rs
@@ -24,6 +24,43 @@ use durs_bc_db_reader::constants::*;
 use durs_bc_db_reader::current_meta_datas::get_current_blockstamp_;
 use durs_bc_db_reader::current_meta_datas::CurrentMetaDataKey;
 use durs_bc_db_reader::{DbValue,DbReader};
+use dubp_block_doc::BlockDocument;
+
+// TODO: revert_current_frame
+pub(crate) fn update_current_frame(
+    _db: &Db,
+    _w: &mut DbWriter,
+    _new_current_block: &BlockDocument,
+) -> Result<(), DbError> {
+    unimplemented!();
+    //Ok(())
+    // 1. dans CURRENT_FRAME_MEMBERS
+    //   pour le WotId du nouveau bloc
+    //     last_block = CurrentBlockNumber
+    //     block_count++ OR 1 si nouvelle clef
+    //   pour les WotId des 0 à 2 blocs sortant (à récupérer via une queue)
+    //    block_count-- Si 0 supprimer la clef
+    // 2. créer SortedFrameMemberTable : Vec<(bloc_count : u32, WotId)>
+    //      en extraire la valeur médiane MedianFrameMember 
+    // 3. dans CURRENT_META_DATAS
+    //    CurrentFrameMembersSize += diff clef WotId ajoutée/supprimée
+    //    MedianFrameMember = MedianFrameMember 
+    //    CurrentFrameFIFO
+
+}
+// fn update_current_frame_fifo
+//   fn push_in_current_frame_fifo
+//   update_current_frame_members <- add WotId
+//   fn pop_in_current_frame_fifo
+//   0-2 update_current_frame_members <- rm WotId
+// (fn update_current_frame_members)
+//   fn write_current_frame_fifo_in_store
+
+// fn update_median_forged_blocks_in_current_frame
+//   fn get_current_frame durs-bc-db-reader (mais comment on l'initialise au lancement ?)
+//   chercher rust compute median (en ligne) si pas d'algo sans tri : fn sort_current_frame_members_by_forged_blocks (en itérant/transformant la structure précédente)
+//   fn compute_median_forged_blocks_in_current_frame (à partir du tableau trié)
+// fn update_current_frame_meta_data (sauf fifo)
 
 
 /// Compute the personal difficulty of a member.
diff --git a/lib/modules/blockchain/bc-db-writer/src/lib.rs b/lib/modules/blockchain/bc-db-writer/src/lib.rs
index 413de1c4..361acabc 100644
--- a/lib/modules/blockchain/bc-db-writer/src/lib.rs
+++ b/lib/modules/blockchain/bc-db-writer/src/lib.rs
@@ -34,7 +34,6 @@ pub mod blocks;
 pub mod current_frame;
 pub mod current_meta_datas;
 pub mod indexes;
-pub mod store_name;
 pub mod writers;
 
 pub use durs_dbs_tools::kv_db::{
diff --git a/lib/modules/blockchain/bc-db-writer/src/store_name.rs b/lib/modules/blockchain/bc-db-writer/src/store_name.rs
deleted file mode 100644
index dee6273e..00000000
--- a/lib/modules/blockchain/bc-db-writer/src/store_name.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-//  Copyright (C) 2017-2019  The AXIOM TEAM Association.
-//
-// 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/>.
-
-//! "store name" storage: define write requests.
-
-use crate::{Db, DbWriter};
-use dubp_block_doc::BlockDocument;
-use durs_dbs_tools::DbError;
-
-pub(crate) fn update_store_name(
-    _db: &Db,
-    _w: &mut DbWriter,
-    _new_current_block: &BlockDocument,
-) -> Result<(), DbError> {
-    //unimplemented!()
-    Ok(())
-}
-- 
GitLab