Skip to content

Commit

Permalink
Improve versioning and folder structure (mit-dci#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Davidson-Souza authored May 18, 2023
1 parent 88c4bf9 commit ba4f5c0
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
14 changes: 10 additions & 4 deletions src/blockchain/p2p_blockchain/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ impl Peer {
) => {
self.send_to_node(PeerMessages::NewBlock(block_hash)).await;
}
bitcoin::network::message_blockdata::Inventory::WTx(_) => todo!(),
bitcoin::network::message_blockdata::Inventory::WitnessTransaction(_) => {}
_ => {}
}
}
Expand Down Expand Up @@ -336,6 +334,11 @@ pub(super) mod peer_utils {
message::{self, NetworkMessage},
message_network,
};

use crate::version::{FLORESTA_VERSION, RUSTREEXO_VERSION, RUST_BITCOIN_VERSION};
/// Protocol version we speak
pub const PROTOCOL_VERSION: u32 = 70016;

pub(super) fn make_pong(nonce: u64) -> NetworkMessage {
NetworkMessage::Pong(nonce)
}
Expand Down Expand Up @@ -363,7 +366,10 @@ pub(super) mod peer_utils {
let nonce: u64 = 1;

// "User Agent (0x00 if string is 0 bytes long)"
let user_agent = String::from("/rust-bitcoin:0.29.3/Floresta:0.2.1");
let user_agent = format!(
"/rust-bitcoin:{}/rustreexo:{}/Floresta:{}/",
RUST_BITCOIN_VERSION, RUSTREEXO_VERSION, FLORESTA_VERSION
);

// "The last block received by the emitting node"
let start_height: i32 = 0;
Expand All @@ -378,7 +384,7 @@ pub(super) mod peer_utils {
user_agent,
start_height,
relay: false,
version: 70016,
version: PROTOCOL_VERSION,
})
}
}
Expand Down
31 changes: 25 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mod cli;
mod config_file;
mod electrum;
mod error;
mod version;
mod wallet_input;

use std::{path::PathBuf, sync::Arc};
Expand All @@ -52,7 +53,7 @@ use crate::blockchain::cli_blockchain::UtreexodBackend;

#[cfg(feature = "experimental-p2p")]
use crate::blockchain::p2p_blockchain::{mempool::Mempool, node::UtreexoNode};
use crate::wallet_input::InitialWalletSetup;
use crate::{version::DIR_NAME, wallet_input::InitialWalletSetup};

fn main() {
// Setup global logger
Expand Down Expand Up @@ -81,14 +82,23 @@ fn main() {
let shutdown = Arc::new(std::sync::atomic::AtomicBool::new(false));
signal_hook::flag::register(signal_hook::consts::SIGINT, Arc::clone(&shutdown))
.expect("Could no register for SIGTERM");

let data_dir = get_one_or_another(
data_dir,
dirs::home_dir().map(|x: PathBuf| {
x.to_str().unwrap_or_default().to_owned() + "/.utreexo_wallet/"
format!(
"{}/{}/",
x.to_str().unwrap_or_default().to_owned(),
DIR_NAME,
)
}),
"wallet".into(),
);
let data_dir = match params.network {
cli::Network::Bitcoin => data_dir,
cli::Network::Signet => data_dir + "/signet/",
cli::Network::Testnet => data_dir + "/testnet3/",
cli::Network::Regtest => data_dir + "/regtest/",
};

debug!("Loading wallet");
let mut wallet = load_wallet(&data_dir);
Expand Down Expand Up @@ -171,11 +181,20 @@ fn main() {
let data_dir = get_one_or_another(
data_dir,
dirs::home_dir().map(|x: PathBuf| {
x.to_str().unwrap_or_default().to_owned() + "/.utreexo_wallet/"
format!(
"{}/{}/",
x.to_str().unwrap_or_default().to_owned(),
DIR_NAME,
)
}),
"wallet".into(),
);

let data_dir = match params.network {
cli::Network::Bitcoin => data_dir,
cli::Network::Signet => data_dir + "/signet/",
cli::Network::Testnet => data_dir + "/testnet3/",
cli::Network::Regtest => data_dir + "/regtest/",
};
debug!("Loading wallet");
let mut wallet = load_wallet(&data_dir);
wallet.setup().expect("Could not initialize wallet");
Expand All @@ -199,7 +218,7 @@ fn main() {
get_net(&params.network),
assume_valid,
));
debug!("Done loading wallet");
debug!("Done loading database");

let chain_provider = UtreexoNode::new(
blockchain_state.clone(),
Expand Down
10 changes: 10 additions & 0 deletions src/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! This module contains some common strings for versioning
/// The default name of our data dir
pub const DIR_NAME: &str = ".floresta";
/// Version of rust-bitcoin we are using. If we bump it on Cargo.toml, should change here too
pub const RUST_BITCOIN_VERSION: &str = "0.29.3";
/// Version of rustreexo we use
pub const RUSTREEXO_VERSION: &str = "0.1.0";
/// Our own version
pub const FLORESTA_VERSION: &str = "0.3.0";

0 comments on commit ba4f5c0

Please sign in to comment.