Skip to content

Commit

Permalink
add community wallet flag to snapshot state
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Dec 5, 2024
1 parent e348a09 commit 4725efa
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/extract_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use libra_backwards_compatibility::version_five::{
use libra_storage::read_snapshot::{accounts_from_snapshot_backup, load_snapshot_manifest};
use libra_types::{
exports::AccountAddress,
move_resource::{libra_coin::LibraCoinStoreResource, wallet::SlowWalletResource},
move_resource::{
cumulative_deposits::CumulativeDepositResource, libra_coin::LibraCoinStoreResource,
wallet::SlowWalletResource,
},
};
use log::{error, info, warn};

Expand Down Expand Up @@ -112,6 +115,11 @@ pub async fn extract_current_snapshot(archive_path: &Path) -> Result<Vec<Warehou
s.slow_wallet_transferred = sw.transferred;
}

// Infer if it is a donor voice account
if let Some(_sw) = el.get_resource::<CumulativeDepositResource>()? {
s.donor_voice_acc = true;
}

warehouse_state.push(s);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/schema_account_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct WarehouseAccState {
pub balance: u64,
pub slow_wallet_locked: u64,
pub slow_wallet_transferred: u64,
pub donor_voice_acc: bool,
}

impl Default for WarehouseAccState {
Expand All @@ -30,6 +31,7 @@ impl Default for WarehouseAccState {
balance: Default::default(),
slow_wallet_locked: Default::default(),
slow_wallet_transferred: Default::default(),
donor_voice_acc: false,
}
}
}
Expand All @@ -43,6 +45,7 @@ impl WarehouseAccState {
balance: 0,
slow_wallet_locked: 0,
slow_wallet_transferred: 0,
donor_voice_acc: false,
}
}
pub fn set_time(&mut self, timestamp: u64, version: u64, epoch: u64) {
Expand All @@ -57,14 +60,15 @@ impl WarehouseAccState {
/// Note original data was in an RFC rfc3339 with Z for UTC, Cypher seems to prefer with offsets +00000
pub fn to_cypher_object_template(&self) -> String {
format!(
r#"{{address: "{}", balance: {}, version: {}, sequence_num: {}, slow_locked: {}, slow_transfer: {}, framework_version: "{}" }}"#,
r#"{{address: "{}", balance: {}, version: {}, sequence_num: {}, slow_locked: {}, slow_transfer: {}, framework_version: "{}", donor_voice: {} }}"#,
self.address.to_hex_literal(),
self.balance,
self.time.version,
self.sequence_num,
self.slow_wallet_locked,
self.slow_wallet_transferred,
self.time.framework_version,
self.donor_voice_acc,
)
}

Expand All @@ -87,7 +91,7 @@ impl WarehouseAccState {
UNWIND tx_data AS tx
MERGE (addr:Account {{address: tx.address}})
MERGE (snap:Snapshot {{address: tx.address, balance: tx.balance, framework_version: tx.framework_version, version: tx.version, sequence_num: tx.sequence_num, slow_locked: tx.slow_locked, slow_transfer: tx.slow_transfer }})
MERGE (snap:Snapshot {{address: tx.address, balance: tx.balance, framework_version: tx.framework_version, version: tx.version, sequence_num: tx.sequence_num, slow_locked: tx.slow_locked, slow_transfer: tx.slow_transfer, donor_voice: tx.donor_voice }})
MERGE (addr)-[rel:State {{version: tx.version}} ]->(snap)
RETURN
Expand Down
43 changes: 41 additions & 2 deletions tests/test_load_state.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
mod support;

use libra_forensic_db::{
extract_snapshot::extract_v5_snapshot,
extract_snapshot::{extract_current_snapshot, extract_v5_snapshot},
load_account_state::{impl_batch_snapshot_insert, snapshot_batch},
neo4j_init::{get_neo4j_localhost_pool, maybe_create_indexes},
schema_account_state::WarehouseAccState,
};
use support::{
fixtures::v5_state_manifest_fixtures_path, neo4j_testcontainer::start_neo4j_container,
fixtures::{v5_state_manifest_fixtures_path, v7_state_manifest_fixtures_path},
neo4j_testcontainer::start_neo4j_container,
};

#[tokio::test]
Expand Down Expand Up @@ -36,6 +37,44 @@ async fn test_snapshot_unit() -> anyhow::Result<()> {

#[tokio::test]
async fn test_snapshot_batch() -> anyhow::Result<()> {
libra_forensic_db::log_setup();
let manifest_file = v7_state_manifest_fixtures_path().join("state.manifest");
assert!(manifest_file.exists());
let vec_snap = extract_current_snapshot(&manifest_file).await?;

let c = start_neo4j_container();
let port = c.get_host_port_ipv4(7687);
let graph = get_neo4j_localhost_pool(port)
.await
.expect("could not get neo4j connection pool");
maybe_create_indexes(&graph)
.await
.expect("could start index");

let merged_snapshots = impl_batch_snapshot_insert(&graph, &vec_snap[..100]).await?;
dbg!(&merged_snapshots.created_tx);
// assert!(merged_snapshots.created_tx == 100);

// check DB to see what is persisted
let cypher_query = neo4rs::query(
"MATCH ()-[r:State]->()
RETURN count(r) AS count_state_edges",
);

// Execute the query
let mut result = graph.execute(cypher_query).await?;

// Fetch the first row only
let row = result.next().await?.unwrap();
let count: i64 = row.get("count_state_edges").unwrap();
dbg!(&count);
// assert!(count == 100i64);

Ok(())
}

#[tokio::test]
async fn test_v5_snapshot_batch() -> anyhow::Result<()> {
libra_forensic_db::log_setup();
let manifest_file = v5_state_manifest_fixtures_path().join("state.manifest");
assert!(manifest_file.exists());
Expand Down

0 comments on commit 4725efa

Please sign in to comment.