Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into share-chain-sy…
Browse files Browse the repository at this point in the history
…nc-fix

# Conflicts:
#	src/main.rs
#	src/server/p2p/client.rs
  • Loading branch information
ksrichard committed Jul 11, 2024
2 parents 71dc2a8 + 81139b6 commit 00683da
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 44 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ jobs:
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly
- name: cargo test compile
run: cargo test --no-run --locked --all-features --release ${{ env.TARGET_BINS }}

- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
Expand Down Expand Up @@ -158,10 +155,6 @@ jobs:
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly-${{ hashFiles('**/Cargo.lock') }}
tari-${{ runner.os }}-${{ runner.cpu-model }}-${{ env.toolchain }}-nightly
- name: cargo test compile
if: ${{ env.CI_FFI == 'true' }}
run: cargo test --no-run --locked --all-features --release ${{ env.TARGET_BINS }}

- name: upload artifact
uses: actions/upload-artifact@v4 # upload test results as artifact
if: always()
Expand Down
45 changes: 21 additions & 24 deletions Cargo.lock

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

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ thiserror = "1.0"
serde = "1.0.203"
anyhow = "1.0"
log = "0.4.21"
env_logger = "0.11.3"
tonic = "0.8.3"
async-trait = "0.1.80"
serde_cbor = "0.11.2"
Expand All @@ -43,5 +42,4 @@ digest = "0.10.7"
clap = { version = "4.5.7", features = ["derive"] }
moka = { version = "0.12.7", features = ["future"] }
rand = "0.8.0"


dirs = "4.0.0"
53 changes: 53 additions & 0 deletions log4rs_sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
refresh_rate: 30 seconds
appenders:
# An appender named "stdout" that writes to stdout
stdout:
kind: console
encoder:
pattern: "{d(%Y-%m-%dT%H:%M:%S%Z)} {h({l}):5} {t} {m}{n}"
filters:
- kind: threshold
level: info

# An appender named "p2pool" that writes to a file with a custom pattern encoder
p2pool:
kind: rolling_file
path: "{{log_dir}}/log/p2pool.log"
policy:
kind: compound
trigger:
kind: size
limit: 10mb
roller:
kind: fixed_window
base: 1
count: 5
pattern: "{{log_dir}}/log/p2pool.{}.log"
encoder:
pattern: "[{d(%Y-%m-%d %H:%M:%S.%f)} [{t}] [Thread:{I}] {l:5} {m}{n}]"

# Set the default logging level to "warn" and attach the "stdout" appender to the root
root:
level: info
appenders:
- stdout

loggers:
sharechain:
level: info
appenders:
- p2pool
- stdout
additive: false
p2p:
level: info
appenders:
- p2pool
- stdout
additive: false
server:
level: info
appenders:
- p2pool
- stdout
additive: false
32 changes: 26 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use clap::{
builder::{styling::AnsiColor, Styles},
Parser,
};
use env_logger::Builder;
use log::LevelFilter;

use tari_common::initialize_logging;

use crate::sharechain::in_memory::InMemoryShareChain;

mod server;
Expand All @@ -26,7 +27,7 @@ fn cli_styles() -> Styles {
.valid(AnsiColor::BrightGreen.on_default())
}

#[derive(Parser)]
#[derive(Clone, Parser)]
#[command(version)]
#[command(styles = cli_styles())]
#[command(about = "⛏ Decentralized mining pool for Tari network ⛏", long_about = None)]
Expand Down Expand Up @@ -83,25 +84,44 @@ struct Cli {
/// If set, mDNS local peer discovery is disabled.
#[arg(long, value_name = "mdns-disabled", default_value_t = false)]
mdns_disabled: bool,

base_dir: Option<PathBuf>,
}

impl Cli {
pub fn base_dir(&self) -> PathBuf {
self.base_dir
.clone()
.unwrap_or_else(|| dirs::home_dir().unwrap().join(".p2pool/miner"))
}
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
// cli
let cli = Cli::parse();
Builder::new().filter_level(cli.log_level).init();

// logger setup
if let Err(e) = initialize_logging(
&cli.base_dir().join("configs/logs.yml"),
&cli.base_dir(),
include_str!("../log4rs_sample.yml"),
) {
eprintln!("{}", e);
return Err(e.into());
}

let mut config_builder = server::Config::builder();
if let Some(grpc_port) = cli.grpc_port {
config_builder.with_grpc_port(grpc_port);
}
if let Some(p2p_port) = cli.p2p_port {
config_builder.with_p2p_port(p2p_port);
}
if let Some(seed_peers) = cli.seed_peers {
if let Some(seed_peers) = cli.seed_peers.clone() {
config_builder.with_seed_peers(seed_peers);
}
config_builder.with_stable_peer(cli.stable_peer);
config_builder.with_private_key_folder(cli.private_key_folder);
config_builder.with_private_key_folder(cli.private_key_folder.clone());
config_builder.with_mining_enabled(!cli.mining_disabled);
config_builder.with_mdns_enabled(!cli.mdns_disabled);

Expand Down
2 changes: 1 addition & 1 deletion src/server/grpc/p2pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
sharechain::{block::Block, ShareChain, SHARE_COUNT},
};

const LOG_TARGET: &str = "p2pool_grpc";
const LOG_TARGET: &str = "p2pool::server::grpc::p2pool";

/// P2Pool specific gRPC service to provide `get_new_block` and `submit_block` functionalities.
pub struct ShaP2PoolGrpc<S>
Expand Down
2 changes: 1 addition & 1 deletion src/server/p2p/peer_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use moka::future::{Cache, CacheBuilder};

use crate::server::p2p::messages::PeerInfo;

const LOG_TARGET: &str = "peer_store";
const LOG_TARGET: &str = "p2pool::server::p2p::peer_store";

#[derive(Copy, Clone, Debug)]
pub struct PeerStoreConfig {
Expand Down
2 changes: 1 addition & 1 deletion src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
sharechain::ShareChain,
};

const LOG_TARGET: &str = "server";
const LOG_TARGET: &str = "p2pool::server::server";

#[derive(Error, Debug)]
pub enum Error {
Expand Down
2 changes: 1 addition & 1 deletion src/sharechain/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::sharechain::{
Block, ShareChain, ShareChainResult, SubmitBlockResult, ValidateBlockResult, MAX_BLOCKS_COUNT, SHARE_COUNT,
};

const LOG_TARGET: &str = "in_memory_share_chain";
const LOG_TARGET: &str = "p2pool::sharechain::in_memory";

pub struct InMemoryShareChain {
max_blocks_count: usize,
Expand Down

0 comments on commit 00683da

Please sign in to comment.