Skip to content
Snippets Groups Projects
Commit baf49d59 authored by Éloïs's avatar Éloïs
Browse files

[ref] server: move old heads in db dunp_v1

parent a6392f11
No related branches found
No related tags found
No related merge requests found
...@@ -15,10 +15,4 @@ ...@@ -15,10 +15,4 @@
use crate::*; use crate::*;
db_schema!( db_schema!(CmV1, [["self_peer_old", SelfPeerOld, (), PeerCardDbV1],]);
CmV1,
[
["self_peer_old", SelfPeerOld, (), PeerCardDbV1],
["dunp_heads_old", DunpHeadsOld, DunpNodeIdV1Db, DunpHeadDbV1],
]
);
...@@ -17,5 +17,8 @@ use crate::*; ...@@ -17,5 +17,8 @@ use crate::*;
db_schema!( db_schema!(
DunpV1, DunpV1,
[["peers_old", PeersOld, PubKeyKeyV2, PeerCardDbV1],] [
["heads_old", HeadsOld, DunpNodeIdV1Db, DunpHeadDbV1],
["peers_old", PeersOld, PubKeyKeyV2, PeerCardDbV1],
]
); );
...@@ -23,8 +23,8 @@ impl DuniterServer { ...@@ -23,8 +23,8 @@ impl DuniterServer {
self.dbs_pool self.dbs_pool
.execute(move |dbs| { .execute(move |dbs| {
for (dunp_node_id, dunp_head) in heads { for (dunp_node_id, dunp_head) in heads {
dbs.cm_db dbs.dunp_db
.dunp_heads_old_write() .heads_old_write()
.upsert(dunp_node_id, dunp_head)? .upsert(dunp_node_id, dunp_head)?
} }
Ok::<(), KvError>(()) Ok::<(), KvError>(())
...@@ -83,13 +83,13 @@ mod tests { ...@@ -83,13 +83,13 @@ mod tests {
ed25519::{PublicKey, Signature}, ed25519::{PublicKey, Signature},
PublicKey as _, PublicKey as _,
}; };
use duniter_dbs::databases::dunp_v1::DunpV1DbReadable;
use duniter_dbs::PeerCardDbV1; use duniter_dbs::PeerCardDbV1;
use super::*; use super::*;
#[test] #[test]
fn test_receive_new_heads() -> anyhow::Result<()> { fn test_receive_new_heads() -> anyhow::Result<()> {
use duniter_dbs::databases::cm_v1::CmV1DbReadable as _;
let (server, dbs) = DuniterServer::test(DuniterConf::default())?; let (server, dbs) = DuniterServer::test(DuniterConf::default())?;
let head = ( let head = (
...@@ -107,10 +107,10 @@ mod tests { ...@@ -107,10 +107,10 @@ mod tests {
}, },
); );
assert_eq!(dbs.cm_db.dunp_heads_old().count()?, 0); assert_eq!(dbs.dunp_db.heads_old().count()?, 0);
server.receive_new_heads(vec![head.clone()])?; server.receive_new_heads(vec![head.clone()])?;
assert_eq!(dbs.cm_db.dunp_heads_old().count()?, 1); assert_eq!(dbs.dunp_db.heads_old().count()?, 1);
assert_eq!(dbs.cm_db.dunp_heads_old().get(&head.0)?, Some(head.1)); assert_eq!(dbs.dunp_db.heads_old().get(&head.0)?, Some(head.1));
Ok(()) Ok(())
} }
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
mod legacy; mod legacy;
pub use duniter_conf::{gva_conf::GvaConf, DuniterConf}; pub use duniter_conf::{gva_conf::GvaConf, DuniterConf};
use duniter_dbs::databases::dunp_v1::DunpV1DbWritable;
pub use duniter_dbs::{ pub use duniter_dbs::{
kv_typed::prelude::KvResult, smallvec, DunpHeadDbV1, DunpNodeIdV1Db, PeerCardDbV1, kv_typed::prelude::KvResult, smallvec, DunpHeadDbV1, DunpNodeIdV1Db, PeerCardDbV1,
}; };
...@@ -115,6 +116,7 @@ impl DuniterServer { ...@@ -115,6 +116,7 @@ impl DuniterServer {
log::info!("open duniter databases..."); log::info!("open duniter databases...");
let (bc_db, dbs) = duniter_dbs::open_dbs(profile_path_opt); let (bc_db, dbs) = duniter_dbs::open_dbs(profile_path_opt);
dbs.dunp_db.heads_old_write().clear()?; // Clear WS2Pv1 HEADs
log::info!("Databases successfully opened."); log::info!("Databases successfully opened.");
let current = duniter_dbs_read_ops::get_current_block_meta(&dbs.bc_db_ro) let current = duniter_dbs_read_ops::get_current_block_meta(&dbs.bc_db_ro)
.context("Fail to get current")?; .context("Fail to get current")?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment