Skip to content

Commit

Permalink
feat: make base node support 1 click mining (#6019)
Browse files Browse the repository at this point in the history
Description
---
On startup make the basenode ask you if you want to run mining or not. 
Add a flag `--enable-mining`
Fix base node flag `--enable-grpc`

Motivation and Context
---
This will make it easier to mine from a 1-click perspective where a new
miner does not need to edit confiles in order to mine

How Has This Been Tested?
---
manual
  • Loading branch information
SWvheerden committed Dec 8, 2023
1 parent a68d0dd commit d377269
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 127 deletions.
Expand Up @@ -72,7 +72,7 @@ pub fn setup_node_identity<P: AsRef<Path>>(
Err(e) => {
debug!(target: LOG_TARGET, "Failed to load node identity: {}", e);
if !create_id {
let prompt = prompt("Node identity does not exist.\nWould you like to to create one (Y/n)?");
let prompt = prompt("Node identity does not exist.\nWould you like to create one (Y/n)?");
if !prompt {
error!(
target: LOG_TARGET,
Expand Down
9 changes: 9 additions & 0 deletions applications/minotari_node/src/cli.rs
Expand Up @@ -47,6 +47,8 @@ pub struct Cli {
pub profile_with_tokio_console: bool,
#[clap(long, env = "MINOTARI_NODE_ENABLE_GRPC", alias = "enable-grpc")]
pub grpc_enabled: bool,
#[clap(long, env = "MINOTARI_NODE_ENABLE_MINING", alias = "enable-mining")]
pub mining_enabled: bool,
}

impl ConfigOverrideProvider for Cli {
Expand All @@ -58,6 +60,13 @@ impl ConfigOverrideProvider for Cli {
overrides.push(("p2p.seeds.override_from".to_string(), network.to_string()));
overrides.push(("auto_update.override_from".to_string(), network.to_string()));
overrides.push(("metrics.override_from".to_string(), network.to_string()));
if self.grpc_enabled {
overrides.push(("base_node.grpc_enabled".to_string(), "true".to_string()));
}
if self.mining_enabled {
overrides.push(("base_node.grpc_enabled".to_string(), "true".to_string()));
overrides.push(("base_node.mining_enabled".to_string(), "true".to_string()));
}
overrides
}
}
3 changes: 3 additions & 0 deletions applications/minotari_node/src/config.rs
Expand Up @@ -94,6 +94,8 @@ pub struct BaseNodeConfig {
pub grpc_authentication: GrpcAuthentication,
/// GRPC tls enabled
pub grpc_tls_enabled: bool,
/// Enable mining on the base node, overriding other settings regarding mining
pub mining_enabled: bool,
/// A path to the file that stores the base node identity and secret key
pub identity_file: PathBuf,
/// Spin up and use a built-in Tor instance. This only works on macos/linux - requires that the wallet was built
Expand Down Expand Up @@ -164,6 +166,7 @@ impl Default for BaseNodeConfig {
],
grpc_authentication: GrpcAuthentication::default(),
grpc_tls_enabled: false,
mining_enabled: false,
identity_file: PathBuf::from("config/base_node_id.json"),
use_libtor: false,
tor_identity_file: PathBuf::from("config/base_node_tor_id.json"),
Expand Down
20 changes: 16 additions & 4 deletions applications/minotari_node/src/grpc/base_node_grpc_server.rs
Expand Up @@ -64,6 +64,7 @@ use crate::{
hash_rate::HashRateMovingAverage,
helpers::{mean, median},
},
BaseNodeConfig,
};

const LOG_TARGET: &str = "minotari::base_node::grpc";
Expand Down Expand Up @@ -95,11 +96,11 @@ pub struct BaseNodeGrpcServer {
comms: CommsNode,
liveness: LivenessHandle,
report_grpc_error: bool,
deny_methods: Vec<GrpcMethod>,
config: BaseNodeConfig,
}

impl BaseNodeGrpcServer {
pub fn from_base_node_context(ctx: &BaseNodeContext, deny_methods: Vec<GrpcMethod>) -> Self {
pub fn from_base_node_context(ctx: &BaseNodeContext, config: BaseNodeConfig) -> Self {
Self {
node_service: ctx.local_node(),
mempool_service: ctx.local_mempool(),
Expand All @@ -110,7 +111,7 @@ impl BaseNodeGrpcServer {
comms: ctx.base_node_comms().clone(),
liveness: ctx.liveness(),
report_grpc_error: ctx.get_report_grpc_error(),
deny_methods,
config,
}
}

Expand All @@ -119,7 +120,18 @@ impl BaseNodeGrpcServer {
}

fn is_method_enabled(&self, grpc_method: GrpcMethod) -> bool {
!self.deny_methods.contains(&grpc_method)
let mining_method = vec![
GrpcMethod::GetNewBlockTemplate,
GrpcMethod::GetNewBlock,
GrpcMethod::GetNewBlockBlob,
GrpcMethod::SubmitBlock,
GrpcMethod::SubmitBlockBlob,
GrpcMethod::GetTipInfo,
];
if self.config.mining_enabled && mining_method.contains(&grpc_method) {
return true;
}
!self.config.grpc_server_deny_methods.contains(&grpc_method)
}
}

Expand Down
7 changes: 3 additions & 4 deletions applications/minotari_node/src/lib.rs
Expand Up @@ -88,6 +88,7 @@ pub async fn run_base_node(
watch: None,
profile_with_tokio_console: false,
grpc_enabled: false,
mining_enabled: false,
};

run_base_node_with_cli(node_identity, config, cli, shutdown).await
Expand Down Expand Up @@ -136,10 +137,8 @@ pub async fn run_base_node_with_cli(
format!("/ip4/127.0.0.1/tcp/{}", port).parse().unwrap()
});
// Go, GRPC, go go
let grpc = grpc::base_node_grpc_server::BaseNodeGrpcServer::from_base_node_context(
&ctx,
config.base_node.grpc_server_deny_methods.clone(),
);
let grpc =
grpc::base_node_grpc_server::BaseNodeGrpcServer::from_base_node_context(&ctx, config.base_node.clone());
let auth = config.base_node.grpc_authentication.clone();

let mut tls_identity = None;
Expand Down
1 change: 0 additions & 1 deletion applications/minotari_node/src/main.rs
Expand Up @@ -103,7 +103,6 @@ fn main() {

fn main_inner() -> Result<(), ExitError> {
let cli = Cli::parse();

let config_path = cli.common.config_path();
let cfg = load_configuration(config_path, true, &cli)?;

Expand Down
82 changes: 49 additions & 33 deletions common/config/presets/b_peer_seeds.toml
Expand Up @@ -20,52 +20,26 @@
dns_seeds = ["seeds.nextnet.tari.com"]
# Custom specified peer seed nodes
peer_seeds = [
# 44444408d5fa29410d9752770f
"2c84ccdf0dcb7b4845f167ea8988166384a36451d068e0ae1bb84b5bf0d52425::/onion3/7gwfakr7ko5uo3fl3yz3fsjc7elccbzter5botggodrmmwi2exm3vbid:18141",
# bbbbbb87215db9ee00bb2763b5
"64639314dc3c9a4b0fa57f812d68b381a882e72eb9cc20e861ce6e04936ef438::/onion3/lvsj75guqc4gfqasgyhg3of2clijf3vkgipbpufh6dmhyapp2dmuelad:18141",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/onion3/rhoqxfbzz3uidp23erxu4mkwwexc2gg4q45rcxfpbhb35ycdv4ex2fid:18141",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/ip4/54.77.66.39/tcp/18189",
]

[stagenet.p2p.seeds]
# DNS seeds hosts - DNS TXT records are queried from these hosts and the resulting peers added to the comms peer list.
dns_seeds = ["seeds.stagenet.tari.com"]
# Custom specified peer seed nodes
peer_seeds = [
# 1337e9449e63134fd5e0ba3207
"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/onion3/rhoqxfbzz3uidp23erxu4mkwwexc2gg4q45rcxfpbhb35ycdv4ex2fid:18141",
"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/ip4/54.77.66.39/tcp/18189",
# 1a1a1a4b79a81467a2c815a371
"b2c5db3a2858451d241d4e88677536f9e82a760111962785fb6a3cddc41f766e::/onion3/q32yxdg7l7os2zzx64e3f5u4mzib3lxlkdyguybkhtkd4pwfkpunjcyd:18141",
# 2b2b2b56e8e1479f1685d5f4ce
"1cdf34d27bee5e1edbc343a17f7d79a8a1974fe3f790e899d8987c1f11697e41::/onion3/fwvmhhcifr7yh7neqsweyjvu4bnlmljg6a6fsjdwify3b4aals2oc3yd:18141",
# 3c3c3c8c3aa72ea4c2a943564a
"a42eea2088e0ef663b8d29a9d039b0e5d51c1ddc1cf5ae28feb05ed52ead5a69::/onion3/k5khqg7fwkq7ujxievps22r42i5ykuieai64ze3kj5snsjkew3v7piid:18141",
# 4d4d4df1add5ac00a8c276f11e
"d49df057e1f1ae399ffabdeb59e7ad542439ab2b0bbd9ed23042175a93e4d03c::/onion3/hjeczose7rjo6o6qhsszkuzhrm6qfs7s4yeqzeuz2m67rkpijrtrwsad:18141",
# 5e5e5eace5fc25c4ce83fbaab6
"e65f18cb4a362b33667e0d39b3c93f06c0e822af09906914bdc65907b7cdc130::/onion3/uuv6j3vwq4dac6z3dblc2mjcoecrnxfka3wg43bcass5avbzix4nmzyd:18141",
# 6f6f6f01facc230ad923de9159
"0a755298f4bee8e6db64e345fe8f937e3882693a48c71b942b88744761b02067::/onion3/ksdogedobmqoud6ampvrjrhoozftgfkolhxqvnt7mo7ajqczku5tyyqd:18141",
# 777777aec8a3e4add50054d457
"0c22d3dc3983c74131d7dfb0c4c8ae9fb90c434826cf8ccc71e793bb72d36213::/onion3/so2be7uyg4kf5l7ys3fbk4eqovsfi63yuaqj7pahkkw2crujq43jdnyd:18141",
"0c22d3dc3983c74131d7dfb0c4c8ae9fb90c434826cf8ccc71e793bb72d36213::/ip4/63.35.51.217/tcp/18189",
# 8888883587be3e94600c246c3b
"2ade610a2e95f1c686873944096f5a1f2c7ffcf47d67112b472c9208cc6e9532::/onion3/rmiknlrf7ngfvgpayf5qzuer2c547rzmyqbkbw45w5uessi3jodasdqd:18141",
"2ade610a2e95f1c686873944096f5a1f2c7ffcf47d67112b472c9208cc6e9532::/ip4/54.73.25.246/tcp/18189",
# 99999903f5951fa1ca9505c3c2
"369ae9a89c3fc2804d6ec07e20bf10e5d0e72f565a71821fc7c611ae5bee0116::/onion3/crvsrmoyrk5uatvnafsmoykiqgywdqowupn3auq25iz7zxyf7xusjxid:18141",
"369ae9a89c3fc2804d6ec07e20bf10e5d0e72f565a71821fc7c611ae5bee0116::/ip4/34.252.174.111/tcp/18189",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/onion3/rhoqxfbzz3uidp23erxu4mkwwexc2gg4q45rcxfpbhb35ycdv4ex2fid:18141",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/ip4/54.77.66.39/tcp/18189",
]

[esmeralda.p2p.seeds]
# DNS seeds hosts - DNS TXT records are queried from these hosts and the resulting peers added to the comms peer list.
dns_seeds = ["seeds.esmeralda.tari.com"]
# Custom specified peer seed nodes
peer_seeds = [
# 111111df4003f0c2c827eddad8
"18386842a298724e50ae4690a2c6dc57337fb5efcc42f75813226c0436948714::/onion3/p7k4tvpefibjew6cnbiqnb4q5zjojdm3kzw2fpu7lt2zm6an547tnkad:18141",
# fffffffb1801b9dd652dc74b19
"3e39734233e413c4935396f335b65dfc49c1f78e48940be6770a8b82966d1551::/onion3/6w2heg6oahozcio5zqsa5w5txeah2zkrf4nlq5igzdnkygvaqqt3mzid:18141",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/onion3/rhoqxfbzz3uidp23erxu4mkwwexc2gg4q45rcxfpbhb35ycdv4ex2fid:18141",
#"a062ae2345b0db0df9fb1504b99511e23d98f8513f9b5503efcc6dad8eca7e47::/ip4/54.77.66.39/tcp/18189",
]


Expand All @@ -79,11 +53,53 @@ peer_seeds = [
# dddd69c587a10c41ef2bf51397
"126c7ee64f71aca36398b977dd31fbbe9f9dad615df96473fb655bef5709c540::/ip6/fd56:2026:93c0:0:9e:96fb:e119:d8ec/tcp/18189",


# Local DAN Seeds, Stringhandler
# da100065d065f839dab6b6fb4f
"f24a6ed54362cee25c8e08e92bcd33e4d8ab2b733862948f863c982040d0d447::/onion3/s7sto2fd6cqf3wak2ec23gygb3d77p2ro7pcl2vesk6notgedjhy4nyd:18141",
# da4000fb6a031eced4ce65fe31
"9c127e9451d6721bfbe2b75434fcc19f6c7ab23523d4dacf7f5f5d601d2c8840::/onion3/kfh6trtkccp6mdbob42sb3sd464lzorn2ufys4zglnqhoxzsa4souaqd:18141"
]

########################################################################################################################
# #
# Base Node Configuration Options (BaseNodeConfig) #
# #
########################################################################################################################

# If you are not running a Minotari Base node, you can simply leave everything in this section commented out. Base nodes
# help maintain the security of the Minotari token and are the surest way to preserve your privacy and be 100% sure that
# no-one is cheating you out of your money.

[dibbler.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_dibbler.json"

[igor.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_igor.json"

[esmeralda.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_esmeralda.json"

[stagenet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_stagenet.json"

[nextnet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_nextnet.json"

[base_node]
# Set to false to disable the base node GRPC server (default = true)
#grpc_enabled = true

# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

# gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# Use gRPC over TLS (default = false)
#grpc_tls_enabled = false
43 changes: 43 additions & 0 deletions common/config/presets/c_base_node_a.toml
@@ -0,0 +1,43 @@

########################################################################################################################
# #
# Base Node Configuration Options (BaseNodeConfig) #
# #
########################################################################################################################

# If you are not running a Minotari Base node, you can simply leave everything in this section commented out. Base nodes
# help maintain the security of the Minotari token and are the surest way to preserve your privacy and be 100% sure that
# no-one is cheating you out of your money.

[dibbler.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_dibbler.json"

[igor.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_igor.json"

[esmeralda.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_esmeralda.json"

[stagenet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_stagenet.json"

[nextnet.base_node]
# A path to the file that stores your node identity and secret key (default = "config/base_node_id.json")
identity_file = "config/base_node_id_nextnet.json"

[base_node]
# Set to false to disable the base node GRPC server (default = true)
#grpc_enabled = true

# The socket to expose for the gRPC base node server (default = "/ip4/127.0.0.1/tcp/18142")
#grpc_address = "/ip4/127.0.0.1/tcp/18142"

# gRPC authentication method (default = "none")
#grpc_authentication = { username = "admin", password = "xxxx" }

# Use gRPC over TLS (default = false)
#grpc_tls_enabled = false
38 changes: 38 additions & 0 deletions common/config/presets/c_base_node_b_mining_deny_methods.toml
@@ -0,0 +1,38 @@

# Uncomment all gRPC server methods that should be denied default (only active when `grpc_enabled = true`)
grpc_server_deny_methods = [
"get_version",
"check_for_updates",
"get_sync_info",
"get_sync_progress",
#"get_tip_info",
"identify",
"get_network_status",
#"list_headers",
"get_header_by_hash",
"get_blocks",
"get_block_timing",
"get_constants",
"get_block_size",
"get_block_fees",
#"get_tokens_in_circulation",
#"get_network_difficulty",
#"get_new_block_template",
#"get_new_block",
#"get_new_block_blob",
#"submit_block",
#"submit_block_blob",
#"submit_transaction",
#"search_kernels",
#"search_utxos",
#"fetch_matching_utxos",
"get_peers",
"get_mempool_transactions",
#"transaction_state",
#"list_connected_peers",
#"get_mempool_stats",
#"get_active_validator_nodes",
#"get_shard_key",
#"get_template_registrations",
#"get_side_chain_utxos",
]
37 changes: 37 additions & 0 deletions common/config/presets/c_base_node_b_non_mining_deny_methods.toml
@@ -0,0 +1,37 @@
# Uncomment all gRPC server methods that should be denied default (only active when `grpc_enabled = true`)
grpc_server_deny_methods = [
"get_version",
"check_for_updates",
"get_sync_info",
"get_sync_progress",
"get_tip_info",
"identify",
"get_network_status",
#"list_headers",
"get_header_by_hash",
"get_blocks",
"get_block_timing",
"get_constants",
"get_block_size",
"get_block_fees",
#"get_tokens_in_circulation",
#"get_network_difficulty",
"get_new_block_template",
"get_new_block",
"get_new_block_blob",
#"submit_block",
#"submit_block_blob",
#"submit_transaction",
#"search_kernels,"
#"search_utxos",
#"fetch_matching_utxos",
"get_peers",
"get_mempool_transactions",
#"transaction_state",
#"list_connected_peers",
#"get_mempool_stats",
#"get_active_validator_nodes",
#"get_shard_key",
#"get_template_registrations",
#"get_side_chain_utxos",
]

0 comments on commit d377269

Please sign in to comment.