Skip to content

Commit

Permalink
[genesis] Only allow open module publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and aptos-bot committed May 5, 2022
1 parent cfd2320 commit 9f93f94
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 88 deletions.
2 changes: 0 additions & 2 deletions api/src/tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use aptos_types::{
block_metadata::BlockMetadata,
chain_id::ChainId,
ledger_info::{LedgerInfo, LedgerInfoWithSignatures},
on_chain_config::VMPublishingOption,
transaction::{Transaction, TransactionStatus},
};
use aptos_vm::AptosVM;
Expand Down Expand Up @@ -54,7 +53,6 @@ pub fn new_test_context(test_name: &'static str) -> TestContext {
let mut rng = ::rand::rngs::StdRng::from_seed([0u8; 32]);
let builder =
ValidatorBuilder::new(&tmp_dir, cached_framework_packages::module_blobs().to_vec())
.publishing_option(VMPublishingOption::open())
.min_price_per_gas_unit(0)
.randomize_first_validator_ports(false);

Expand Down
14 changes: 10 additions & 4 deletions aptos-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use aptos_types::{
chain_id::ChainId,
contract_event::ContractEvent,
on_chain_config::{
ConsensusConfigV1, OnChainConsensusConfig, VMPublishingOption, APTOS_MAX_KNOWN_VERSION,
ConsensusConfigV1, ConsensusConfigV2, OnChainConsensusConfig, VMPublishingOption,
APTOS_MAX_KNOWN_VERSION,
},
transaction::{authenticator::AuthenticationKey, ChangeSet, Transaction, WriteSetPayload},
};
Expand Down Expand Up @@ -53,16 +54,21 @@ pub fn encode_genesis_transaction(
aptos_root_key: Ed25519PublicKey,
validators: &[Validator],
stdlib_module_bytes: &[Vec<u8>],
vm_publishing_option: Option<VMPublishingOption>,
consensus_config: OnChainConsensusConfig,
chain_id: ChainId,
min_price_per_gas_unit: u64,
) -> Transaction {
let consensus_config = OnChainConsensusConfig::V2(ConsensusConfigV2 {
two_chain: true,
decoupled_execution: true,
back_pressure_limit: 10,
exclude_round: 20,
});

Transaction::GenesisTransaction(WriteSetPayload::Direct(encode_genesis_change_set(
&aptos_root_key,
validators,
stdlib_module_bytes,
vm_publishing_option.unwrap_or_else(VMPublishingOption::open),
VMPublishingOption::open(),
consensus_config,
chain_id,
min_price_per_gas_unit,
Expand Down
15 changes: 4 additions & 11 deletions aptos-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ use aptos_telemetry::{
};
use aptos_time_service::TimeService;
use aptos_types::{
account_config::aptos_root_address,
account_view::AccountView,
chain_id::ChainId,
move_resource::MoveStorage,
on_chain_config::{VMPublishingOption, ON_CHAIN_CONFIG_REGISTRY},
waypoint::Waypoint,
account_config::aptos_root_address, account_view::AccountView, chain_id::ChainId,
move_resource::MoveStorage, on_chain_config::ON_CHAIN_CONFIG_REGISTRY, waypoint::Waypoint,
};
use aptos_vm::AptosVM;
use aptosdb::AptosDB;
Expand Down Expand Up @@ -129,7 +125,6 @@ pub fn load_test_environment<R>(
config_path: Option<PathBuf>,
random_ports: bool,
lazy: bool,
publishing_option: Option<VMPublishingOption>,
genesis_modules: Vec<Vec<u8>>,
rng: R,
) where
Expand Down Expand Up @@ -173,15 +168,13 @@ pub fn load_test_environment<R>(
template.consensus.mempool_poll_count = u64::MAX;
}

let mut builder = aptos_genesis_tool::validator_builder::ValidatorBuilder::new(
let builder = aptos_genesis_tool::validator_builder::ValidatorBuilder::new(
&config_path,
genesis_modules,
)
.template(template)
.randomize_first_validator_ports(random_ports);
if let Some(publishing_option) = publishing_option {
builder = builder.publishing_option(publishing_option);
}

let (root_keys, _genesis, genesis_waypoint, validators) = builder.build(rng).unwrap();

let serialized_keys = bcs::to_bytes(&root_keys.root_key).unwrap();
Expand Down
14 changes: 0 additions & 14 deletions aptos-node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#![forbid(unsafe_code)]
use aptos_config::config::NodeConfig;
use aptos_types::on_chain_config::VMPublishingOption;
use hex::FromHex;
use rand::{rngs::StdRng, SeedableRng};
use std::path::PathBuf;
Expand All @@ -30,13 +29,6 @@ struct Args {
)]
seed: Option<[u8; 32]>,

#[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 Down Expand Up @@ -67,11 +59,6 @@ fn main() {
.seed
.map(StdRng::from_seed)
.unwrap_or_else(StdRng::from_entropy);
let publishing_option = if args.open_publishing {
Some(VMPublishingOption::open())
} else {
None
};
let genesis_modules = if let Some(module_paths) = args.genesis_modules {
framework::load_modules_from_paths(&module_paths)
} else {
Expand All @@ -81,7 +68,6 @@ fn main() {
args.config,
args.random_ports,
args.lazy,
publishing_option,
genesis_modules,
rng,
);
Expand Down
10 changes: 1 addition & 9 deletions config/management/genesis/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use aptos_management::constants::{self, VALIDATOR_CONFIG, VALIDATOR_OPERATOR};
use aptos_secure_storage::{KVStorage, Namespaced};
use aptos_types::{
chain_id::ChainId,
on_chain_config::{OnChainConsensusConfig, VMPublishingOption},
transaction::{
authenticator::AuthenticationKey, ScriptFunction, Transaction, TransactionPayload,
},
Expand Down Expand Up @@ -206,12 +205,7 @@ impl<S: KVStorage> GenesisBuilder<S> {
.map_err(Into::into)
}

pub fn build(
&self,
chain_id: ChainId,
publishing_option: Option<VMPublishingOption>,
consensus_config: OnChainConsensusConfig,
) -> Result<Transaction> {
pub fn build(&self, chain_id: ChainId) -> Result<Transaction> {
let aptos_root_key = self.root_key()?;
let validators = self.validators()?;
let move_modules = self.move_modules()?;
Expand All @@ -221,8 +215,6 @@ impl<S: KVStorage> GenesisBuilder<S> {
aptos_root_key,
&validators,
&move_modules,
publishing_option,
consensus_config,
chain_id,
min_price_per_gas_unit,
);
Expand Down
17 changes: 2 additions & 15 deletions config/management/genesis/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
use crate::builder::GenesisBuilder;
use aptos_management::{config::ConfigPath, error::Error, secure_backend::SharedBackend};
use aptos_secure_storage::Storage;
use aptos_types::{
chain_id::ChainId,
on_chain_config::{ConsensusConfigV2, OnChainConsensusConfig, VMPublishingOption},
transaction::Transaction,
};
use aptos_types::{chain_id::ChainId, transaction::Transaction};
use std::{fs::File, io::Write, path::PathBuf};
use structopt::StructOpt;

Expand Down Expand Up @@ -39,16 +35,7 @@ impl Genesis {
let chain_id = config.chain_id;
let storage = Storage::from(&config.shared_backend);
let genesis = GenesisBuilder::new(storage)
.build(
chain_id,
Some(VMPublishingOption::open()),
OnChainConsensusConfig::V2(ConsensusConfigV2 {
two_chain: true,
decoupled_execution: true,
back_pressure_limit: 10,
exclude_round: 20,
}),
)
.build(chain_id)
.map_err(|e| Error::UnexpectedError(e.to_string()))?;

if let Some(path) = self.path {
Expand Down
21 changes: 1 addition & 20 deletions config/management/genesis/src/validator_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use aptos_management::{
use aptos_secure_storage::{CryptoStorage, KVStorage, OnDiskStorage, Storage};
use aptos_types::{
chain_id::ChainId,
on_chain_config::{ConsensusConfigV2, OnChainConsensusConfig, VMPublishingOption},
transaction::{authenticator::AuthenticationKey, Transaction},
waypoint::Waypoint,
};
Expand Down Expand Up @@ -147,7 +146,6 @@ pub struct ValidatorBuilder {
move_modules: Vec<Vec<u8>>,
num_validators: NonZeroUsize,
randomize_first_validator_ports: bool,
publishing_option: Option<VMPublishingOption>,
template: NodeConfig,
min_price_per_gas_unit: u64,
}
Expand All @@ -159,7 +157,6 @@ impl ValidatorBuilder {
move_modules,
num_validators: NonZeroUsize::new(1).unwrap(),
randomize_first_validator_ports: true,
publishing_option: Some(VMPublishingOption::open()),
template: NodeConfig::default_for_validator(),
min_price_per_gas_unit: 1,
}
Expand All @@ -175,11 +172,6 @@ impl ValidatorBuilder {
self
}

pub fn publishing_option(mut self, publishing_option: VMPublishingOption) -> Self {
self.publishing_option = Some(publishing_option);
self
}

pub fn template(mut self, template: NodeConfig) -> Self {
self.template = template;
self
Expand Down Expand Up @@ -215,7 +207,6 @@ impl ValidatorBuilder {
&mut genesis_storage,
&root_keys,
&validators,
self.publishing_option,
self.move_modules,
self.min_price_per_gas_unit,
)?;
Expand Down Expand Up @@ -368,7 +359,6 @@ impl ValidatorBuilder {
genesis_storage: &mut OnDiskStorage,
root_keys: &RootKeys,
validators: &[ValidatorConfig],
publishing_option: Option<VMPublishingOption>,
move_modules: Vec<Vec<u8>>,
min_price_per_gas_unit: u64,
) -> Result<(Transaction, Waypoint)> {
Expand Down Expand Up @@ -417,16 +407,7 @@ impl ValidatorBuilder {
genesis_builder.set_min_price_per_gas_unit(min_price_per_gas_unit)?;

// Create Genesis and Genesis Waypoint
let genesis = genesis_builder.build(
ChainId::test(),
publishing_option,
OnChainConsensusConfig::V2(ConsensusConfigV2 {
two_chain: true,
decoupled_execution: true,
back_pressure_limit: 10,
exclude_round: 20,
}),
)?;
let genesis = genesis_builder.build(ChainId::test())?;
let waypoint = create_genesis_waypoint(&genesis)?;

Ok((genesis, waypoint))
Expand Down
14 changes: 1 addition & 13 deletions crates/aptos/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use crate::{
CliCommand, CliResult,
};
use aptos_crypto::ed25519::Ed25519PublicKey;
use aptos_types::{
chain_id::ChainId,
on_chain_config::{ConsensusConfigV2, OnChainConsensusConfig, VMPublishingOption},
};
use aptos_types::chain_id::ChainId;
use async_trait::async_trait;
use clap::Parser;
use vm_genesis::Validator;
Expand Down Expand Up @@ -61,19 +58,10 @@ impl CliCommand<()> for GenerateGenesis {
async fn execute(self) -> CliTypedResult<()> {
let genesis_info = fetch_genesis_info(self.github_options)?;

let consensus_config = OnChainConsensusConfig::V2(ConsensusConfigV2 {
two_chain: true,
decoupled_execution: true,
back_pressure_limit: 10,
exclude_round: 20,
});

vm_genesis::encode_genesis_transaction(
genesis_info.root_key.clone(),
&genesis_info.validators,
&genesis_info.modules,
Some(VMPublishingOption::open()), // TODO: Remove
consensus_config, // TODO: Remove
genesis_info.chain_id,
MIN_PRICE_PER_GAS_UNIT,
);
Expand Down

0 comments on commit 9f93f94

Please sign in to comment.