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

big cleanup #102

Merged
merged 2 commits into from
May 15, 2022
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
72 changes: 0 additions & 72 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ opt-level = 3
overflow-checks = true
debug = 0
lto = 'thin'
codegen-units = 1
strip="debuginfo"
codegen-units = 1

# [patch.crates-io]
# novasmt={path="../novasmt"}
Expand Down Expand Up @@ -71,22 +70,26 @@ version = "1.18.2"
features = ["full"]
optional = true

[dependencies.async-compat]
version="0.2.1"
optional=true


[dependencies]
anyhow = "1.0.57"
base64 = "0.13.0"
# base64 = "0.13.0"
arc-swap = "1.5.0"
async-compat = "0.2.1"

boringdb = "0.4"
# boringdb = {path="../boringdb"}
# blkdb = { path = "../../libs/blkdb" }
dashmap = "4.0.2"
default-net = "0.6.0"
default-net = {version="0.6.0", optional=true}
env_logger = "0.9.0"
ethnum = "1.1.1"
fastrand = "1.7.0"
futures-util = "0.3.21"
hex = "0.4.3"
hostname = "0.3.1"
imbl = "1.0.1"
log = "0.4.17"
lru = "0.7.5"
Expand All @@ -103,22 +106,21 @@ serde_json = "1.0.81"
defmac = "0.2.1"
smol = "1.2.5"
smolscale = "0.3.23"
smol_str = "0.1.23"
smol-timeout = "0.6.0"
stdcode = "0.1.7"
structopt = "0.3.26"
tap = "1.0.1"
tracing = "0.1.34"
# tracing = "0.1.34"
themelio-stf = "0.10.1"
tmelcrypt = "0.2.4"
themelio-bootstrap = "0.6"
tracing-subscriber = "0.3.11"
# tracing-subscriber = "0.3.11"
themelio-structs = "0.2.2"
dhat = "0.3.0"

# [target.'cfg(unix)'.dependencies]
# mimalloc = "0.1.28"

[features]
metrics = ["prometheus", "gethostname", "public-ip", "reqwest", "rweb", "systemstat", "tokio"]
metrics = ["prometheus", "gethostname", "public-ip", "reqwest", "rweb", "systemstat", "tokio", "async-compat", "default-net"]
dhat-heap = []
17 changes: 6 additions & 11 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[cfg(feature = "metrics")]
use crate::prometheus::{AWS_INSTANCE_ID, AWS_REGION};


use crate::storage::NodeStorage;

Expand Down Expand Up @@ -89,8 +88,7 @@ impl Args {
#[cfg(feature = "metrics")]
{
*crate::prometheus::NETWORK
.write()
.expect("Could not get a write lock on NETWORK") = "testnet";
.write() = "testnet";
}

Ok(GenesisConfig::std_testnet())
Expand Down Expand Up @@ -184,14 +182,11 @@ impl Args {
crate::prometheus::HOSTNAME.as_str(),
crate::public_ip_address::PUBLIC_IP_ADDRESS.as_str(),
crate::prometheus::NETWORK
.read(),
crate::AWS_REGION
.read(),
crate::AWS_INSTANCE_ID
.read()
.expect("Could not get a read lock on NETWORK."),
AWS_REGION
.read()
.expect("Could not get a read lock on AWS_REGION"),
AWS_INSTANCE_ID
.read()
.expect("Could not get a read lock on AWS_INSTANCE_ID")
);

Ok(storage)
Expand Down
61 changes: 22 additions & 39 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::storage::NodeStorage;
use args::Args;
use once_cell::sync::Lazy;
use structopt::StructOpt;
use tracing::instrument;

#[cfg(feature = "metrics")]
pub static RUNTIME: Lazy<Runtime> =
Expand All @@ -30,12 +29,23 @@ pub static RUNTIME: Lazy<Runtime> =
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;

#[instrument]
fn main() -> anyhow::Result<()> {
if std::env::var("RUST_LOG").is_err() {
std::env::set_var("RUST_LOG", "themelio_node=debug,warn");
}
env_logger::Builder::from_env("RUST_LOG").init();
let mut builder = env_logger::Builder::from_env("RUST_LOG");
#[cfg(feature = "metrics")]
{
use std::io::Write;
builder.format(|f, r| {
writeln!(f, "hostname={} public_ip={} network={} region={} instance_id={} level={} message={:?}", crate::prometheus::HOSTNAME.as_str(), crate::public_ip_address::PUBLIC_IP_ADDRESS.as_str(), crate::prometheus::NETWORK.read(),
AWS_REGION.read(),
AWS_INSTANCE_ID.read(),
r.level(),
r.args())
});
}
builder.init();
let opts = Args::from_args();

smolscale::block_on(main_async(opts))
Expand All @@ -44,46 +54,19 @@ fn main() -> anyhow::Result<()> {
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Runs the main function for a node.
#[instrument(skip(opt))]
pub async fn main_async(opt: Args) -> anyhow::Result<()> {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();

#[cfg(not(feature = "metrics"))]
log::info!("themelio-core v{} initializing...", VERSION);

#[cfg(feature = "metrics")]
log::info!(
"hostname={} public_ip={} network={} region={} instance_id={} themelio-core v{} initializing...",
crate::prometheus::HOSTNAME.as_str(),
crate::public_ip_address::PUBLIC_IP_ADDRESS.as_str(),
crate::prometheus::NETWORK.read().expect("Could not get a read lock on NETWORK."),
AWS_REGION.read().expect("Could not get a read lock on AWS_REGION"),
AWS_INSTANCE_ID.read().expect("Could not get a read lock on AWS_INSTANCE_ID"),
VERSION
);
let genesis = opt.genesis_config().await?;
let netid = genesis.network;
let storage: NodeStorage = opt.storage().await?;
let bootstrap = opt.bootstrap().await?;
#[cfg(not(feature = "metrics"))]

log::info!("bootstrapping with {:?}", bootstrap);
#[cfg(feature = "metrics")]
log::info!(
"hostname={} public_ip={} network={} region={} instance_id={} bootstrapping with {:?}",
crate::prometheus::HOSTNAME.as_str(),
crate::public_ip_address::PUBLIC_IP_ADDRESS.as_str(),
crate::prometheus::NETWORK
.read()
.expect("Could not get a read lock on NETWORK."),
AWS_REGION
.read()
.expect("Could not get a read lock on AWS_REGION"),
AWS_INSTANCE_ID
.read()
.expect("Could not get a read lock on AWS_INSTANCE_ID"),
bootstrap
);

let _node_prot = NodeProtocol::new(
netid,
opt.listen_addr(),
Expand Down Expand Up @@ -113,13 +96,13 @@ pub async fn main_async(opt: Args) -> anyhow::Result<()> {
};

#[cfg(feature = "metrics")]
crate::prometheus::GLOBAL_STORAGE
.set(storage)
.ok()
.expect("Could not write to GLOBAL_STORAGE");

#[cfg(feature = "metrics")]
std::thread::spawn(|| RUNTIME.block_on(crate::prometheus::prometheus()));
{
crate::prometheus::GLOBAL_STORAGE
.set(storage)
.ok()
.expect("Could not write to GLOBAL_STORAGE");
std::thread::spawn(|| RUNTIME.block_on(crate::prometheus::prometheus()));
}

#[cfg(feature = "dhat-heap")]
for i in 0..300 {
Expand Down
Loading