Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconstruct msmps from disk and archive #30

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub async fn initialize(cli_args: cli_args::Args) -> Result<()> {
WalletSecret::read_from_file_or_create(&data_dir.wallet_directory_path())?;
info!("Now getting wallet state. This may take a while if the database needs pruning.");
let wallet_state =
WalletState::new_from_wallet_secret(Some(&data_dir), wallet_secret, &cli_args).await;
WalletState::new_from_wallet_secret(&data_dir, wallet_secret, &cli_args).await;
info!("Got wallet state.");

// Connect to or create databases for block index, peers, mutator set, block sync
Expand Down Expand Up @@ -136,6 +136,9 @@ pub async fn initialize(cli_args: cli_args::Args) -> Result<()> {
own_handshake_data.tip_header.height
);

// Check if we need to restore the wallet database, and if so, do it.
state.restore_monitored_utxos_from_recovery_data().await?;

// Connect to peers, and provide each peer thread with a thread-safe copy of the state
let mut thread_join_handles = vec![];
for peer_address in state.cli.peers.clone() {
Expand Down
5 changes: 3 additions & 2 deletions src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ impl MainLoopHandler {
.archival_state
.as_ref()
.unwrap()
.update_mutator_set(&mut db_lock, &mut ams_lock, &new_block)?;
.update_mutator_set(&mut db_lock, &mut ams_lock, &new_block)
.expect("Updating mutator set must succeed");

// Notify wallet to expect the coinbase UTXO, as we mined this block
self.global_state
Expand Down Expand Up @@ -1165,7 +1166,7 @@ impl MainLoopHandler {
if we_have_blocks {
return self
.global_state
.resync_membership_proofs_to_tip(current_tip_digest)
.resync_membership_proofs_from_stored_blocks(current_tip_digest)
.await;
}

Expand Down
10 changes: 8 additions & 2 deletions src/models/blockchain/block/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use itertools::Itertools;
use num_bigint::BigUint;
use num_traits::{abs, Zero};

use serde::{Deserialize, Serialize};
use std::cmp::max;

use tracing::{debug, warn};
use twenty_first::shared_math::tip5::DIGEST_LENGTH;
use twenty_first::util_types::algebraic_hasher::AlgebraicHasher;
Expand Down Expand Up @@ -451,7 +453,10 @@ impl Block {
mod block_tests {
use crate::{
config_models::network::Network,
models::{blockchain::transaction::PubScript, state::UtxoReceiverData},
models::{
blockchain::transaction::PubScript, state::wallet::WalletSecret,
state::UtxoReceiverData,
},
tests::shared::{get_mock_global_state, make_mock_block},
};

Expand All @@ -466,7 +471,8 @@ mod block_tests {
async fn merge_transaction_test() {
// We need the global state to construct a transaction. This global state
// has a wallet which receives a premine-UTXO.
let global_state = get_mock_global_state(Network::Alpha, 2, None).await;
let network = Network::Alpha;
let global_state = get_mock_global_state(network, 2, None).await;
let spending_key = global_state
.wallet_state
.wallet_secret
Expand Down
258 changes: 172 additions & 86 deletions src/models/state/archival_state.rs

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions src/models/state/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ mod tests {
#[tokio::test]
pub async fn insert_then_get_then_remove_then_get() {
let mempool = Mempool::new(ByteSize::gb(1));
let wallet_state = get_mock_wallet_state(None).await;
let network = Network::Alpha;
let wallet_state = get_mock_wallet_state(None, network).await;
let transaction =
make_mock_transaction_with_wallet(vec![], vec![], Amount::zero(), &wallet_state, None);
let transaction_digest = &Hash::hash(&transaction);
Expand All @@ -542,9 +543,9 @@ mod tests {
}

// Create a mempool with n transactions.
async fn setup(transactions_count: u32) -> Mempool {
async fn setup(transactions_count: u32, network: Network) -> Mempool {
let mempool = Mempool::new(ByteSize::gb(1));
let wallet_state = get_mock_wallet_state(None).await;
let wallet_state = get_mock_wallet_state(None, network).await;
for i in 0..transactions_count {
let t = make_mock_transaction_with_wallet(
vec![],
Expand All @@ -562,7 +563,7 @@ mod tests {
#[tokio::test]
async fn get_densest_transactions() {
// Verify that transactions are returned ordered by fee density, with highest fee density first
let mempool = setup(10).await;
let mempool = setup(10, Network::RegTest).await;

let max_fee_density: FeeDensity = FeeDensity::new(BigInt::from(999), BigInt::from(1));
let mut prev_fee_density = max_fee_density;
Expand All @@ -578,7 +579,7 @@ mod tests {
#[tokio::test]
async fn get_sorted_iter() {
// Verify that the function `get_sorted_iter` returns transactions sorted by fee density
let mempool = setup(10).await;
let mempool = setup(10, Network::Alpha).await;

let max_fee_density: FeeDensity = FeeDensity::new(BigInt::from(999), BigInt::from(1));
let mut prev_fee_density = max_fee_density;
Expand All @@ -592,7 +593,7 @@ mod tests {
#[traced_test]
#[tokio::test]
async fn prune_stale_transactions() {
let wallet_state = get_mock_wallet_state(None).await;
let wallet_state = get_mock_wallet_state(None, Network::Alpha).await;
let mempool = Mempool::new(ByteSize::gb(1));
assert!(
mempool.is_empty(),
Expand Down Expand Up @@ -886,7 +887,7 @@ mod tests {
async fn get_mempool_size() {
// Verify that the `get_size` method on mempool returns sane results
let tx_count_small = 10;
let mempool_small = setup(10).await;
let mempool_small = setup(10, Network::Alpha).await;
let size_gs_small = mempool_small.get_size();
let size_serialized_small =
bincode::serialize(&mempool_small.internal.read().unwrap().tx_dictionary)
Expand All @@ -903,7 +904,7 @@ mod tests {
);

let tx_count_big = 100;
let mempool_big = setup(tx_count_big).await;
let mempool_big = setup(tx_count_big, Network::Alpha).await;
let size_gs_big = mempool_big.get_size();
let size_serialized_big =
bincode::serialize(&mempool_big.internal.read().unwrap().tx_dictionary)
Expand Down
Loading
Loading