Skip to content

Commit

Permalink
diem-node: enable open publishing with --test
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed Aug 12, 2021
1 parent 000e602 commit 05b91a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
15 changes: 11 additions & 4 deletions diem-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use diem_metrics::metric_server;
use diem_time_service::TimeService;
use diem_types::{
account_config::diem_root_address, account_state::AccountState, chain_id::ChainId,
move_resource::MoveStorage,
move_resource::MoveStorage, on_chain_config::VMPublishingOption,
};
use diem_vm::DiemVM;
use diemdb::DiemDB;
Expand Down Expand Up @@ -92,8 +92,12 @@ pub fn start(config: &NodeConfig, log_file: Option<PathBuf>) {
}
}

pub fn load_test_environment<R>(config_path: Option<PathBuf>, random_ports: bool, rng: R)
where
pub fn load_test_environment<R>(
config_path: Option<PathBuf>,
random_ports: bool,
publishing_option: Option<VMPublishingOption>,
rng: R,
) where
R: ::rand::RngCore + ::rand::CryptoRng,
{
// Either allocate a temppath or reuse the passed in path and make sure the directory exists
Expand All @@ -110,12 +114,15 @@ where
maybe_config.push("validator_node_template.yaml");
let template = NodeConfig::load_config(maybe_config)
.unwrap_or_else(|_| NodeConfig::default_for_validator());
let builder = diem_genesis_tool::validator_builder::ValidatorBuilder::new(
let mut builder = diem_genesis_tool::validator_builder::ValidatorBuilder::new(
&config_path,
diem_framework_releases::current_module_blobs().to_vec(),
)
.template(template)
.randomize_first_validator_ports(random_ports);
if let Some(publishing_option) = publishing_option {
builder = builder.publishing_option(publishing_option);
}
let test_config =
diem_genesis_tool::swarm_config::SwarmConfig::build_with_rng(&builder, &config_path, rng)
.unwrap();
Expand Down
18 changes: 16 additions & 2 deletions diem-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![forbid(unsafe_code)]

use diem_config::config::NodeConfig;
use diem_types::on_chain_config::VMPublishingOption;
use hex::FromHex;
use rand::{rngs::StdRng, SeedableRng};
use std::path::PathBuf;
Expand All @@ -29,7 +30,15 @@ struct Args {
requires("test")
)]
seed: Option<[u8; 32]>,
#[structopt(long, help = "Enabling random ports for testnet")]

#[structopt(
long,
help = "Enable open publishing when starting single validator testnet",
requires("test")
)]
open_publishing: bool,

#[structopt(long, help = "Enabling random ports for testnet", requires("test"))]
random_ports: bool,
}

Expand All @@ -45,7 +54,12 @@ fn main() {
.seed
.map(StdRng::from_seed)
.unwrap_or_else(StdRng::from_entropy);
diem_node::load_test_environment(args.config, args.random_ports, rng);
let publishing_option = if args.open_publishing {
Some(VMPublishingOption::open())
} else {
None
};
diem_node::load_test_environment(args.config, args.random_ports, publishing_option, rng);
} else {
let config = NodeConfig::load(args.config.unwrap()).expect("Failed to load node config");
println!("Using node config {:?}", &config);
Expand Down

0 comments on commit 05b91a5

Please sign in to comment.