Skip to content

feat: initial implementation of mainnet execution simulation #1509

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

Closed
wants to merge 6 commits into from
Closed
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
77 changes: 76 additions & 1 deletion Cargo.lock

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

22 changes: 21 additions & 1 deletion components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use clarity_repl::clarity::vm::types::QualifiedContractIdentifier;
use clarity_repl::clarity::ClarityVersion;
use clarity_repl::frontend::terminal::print_clarity_wasm_warning;
use clarity_repl::repl::diagnostic::output_diagnostic;
use clarity_repl::repl::settings::{ApiUrl, RemoteDataSettings};
use clarity_repl::repl::{ClarityCodeSource, ClarityContract, ContractDeployer, DEFAULT_EPOCH};
use clarity_repl::{analysis, repl, Terminal};
use stacks_network::{self, DevnetOrchestrator};
Expand Down Expand Up @@ -334,6 +335,7 @@ struct Console {
/// Path to Clarinet.toml
#[clap(long = "manifest-path", short = 'm')]
pub manifest_path: Option<String>,

/// If specified, use this deployment file
#[clap(long = "deployment-plan-path", short = 'p')]
pub deployment_plan_path: Option<String>,
Expand All @@ -351,6 +353,17 @@ struct Console {
conflicts_with = "use_on_disk_deployment_plan"
)]
pub use_computed_deployment_plan: bool,

/// Enable remote data fetching from mainnet or a testnet
#[clap(long = "enable-remote-data", short = 'r')]
pub enable_remote_data: bool,
/// Set a custom Hiro API URL for remote data fetching
#[clap(long = "remote-data-api-url", short = 'a')]
pub remote_data_api_url: Option<ApiUrl>,
/// Initial remote Stacks block height
#[clap(long = "remote-data-initial-height", short = 'b')]
pub remote_data_initial_height: Option<u32>,

/// Allow the Clarity Wasm preview to run in parallel with the Clarity interpreter (beta)
#[clap(long = "enable-clarity-wasm")]
pub enable_clarity_wasm: bool,
Expand Down Expand Up @@ -941,6 +954,12 @@ pub fn main() {
}
},
Command::Console(cmd) => {
let remote_data_settings = RemoteDataSettings {
enabled: cmd.enable_remote_data,
api_url: cmd.remote_data_api_url.unwrap_or_default(),
initial_height: cmd.remote_data_initial_height,
};

// Loop to handle `::reload` command
loop {
let manifest = load_manifest_or_warn(cmd.manifest_path.clone());
Expand Down Expand Up @@ -988,7 +1007,8 @@ pub fn main() {
}
}
None => {
let settings = repl::SessionSettings::default();
let mut settings = repl::SessionSettings::default();
settings.repl_settings.remote_data = remote_data_settings.clone();
if cmd.enable_clarity_wasm {
let mut settings_wasm = repl::SessionSettings::default();
settings_wasm.repl_settings.clarity_wasm_mode = true;
Expand Down
41 changes: 25 additions & 16 deletions components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,16 @@ pub fn update_session_with_deployment_plan(
) -> UpdateSessionExecutionResult {
update_session_with_genesis_accounts(session, deployment);

let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();

let mut boot_contracts = BTreeMap::new();
for (contract_id, (boot_contract, ast)) in boot_contracts_data {
let result = session
.interpreter
.run(&boot_contract, Some(&ast), false, None);
boot_contracts.insert(contract_id, result);
if !session.settings.repl_settings.remote_data.enabled {
let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();

for (contract_id, (boot_contract, ast)) in boot_contracts_data {
let result = session
.interpreter
.run(&boot_contract, Some(&ast), false, None);
boot_contracts.insert(contract_id, result);
}
}

let mut contracts = BTreeMap::new();
Expand Down Expand Up @@ -343,17 +345,21 @@ pub async fn generate_default_deployment(
repl_settings: manifest.repl_settings.clone(),
..Default::default()
};

let session = Session::new(settings.clone());

let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();
let simnet_remote_data = matches!(network, StacksNetwork::Simnet)
&& session.settings.repl_settings.remote_data.enabled;

let mut boot_contracts_ids = BTreeSet::new();
let mut boot_contracts_asts = BTreeMap::new();
for (id, (contract, ast)) in boot_contracts_data {
boot_contracts_ids.insert(id.clone());
boot_contracts_asts.insert(id, (contract.clarity_version, ast));
if !simnet_remote_data {
let boot_contracts_data = BOOT_CONTRACTS_DATA.clone();
let mut boot_contracts_asts = BTreeMap::new();
for (id, (contract, ast)) in boot_contracts_data {
boot_contracts_ids.insert(id.clone());
boot_contracts_asts.insert(id, (contract.clarity_version, ast));
}
requirements_data.append(&mut boot_contracts_asts);
}
requirements_data.append(&mut boot_contracts_asts);

let mut queue = VecDeque::new();

Expand Down Expand Up @@ -429,7 +435,10 @@ pub async fn generate_default_deployment(
location: contract_location,
clarity_version,
};
emulated_contracts_publish.insert(contract_id.clone(), data);

if !simnet_remote_data {
emulated_contracts_publish.insert(contract_id.clone(), data);
}
} else if matches!(network, StacksNetwork::Devnet | StacksNetwork::Testnet) {
let mut remap_principals = BTreeMap::new();
remap_principals
Expand Down Expand Up @@ -533,7 +542,7 @@ pub async fn generate_default_deployment(
}

// Avoid listing requirements as deployment transactions to the deployment specification on Mainnet
if !matches!(network, StacksNetwork::Mainnet) {
if !matches!(network, StacksNetwork::Mainnet) && !simnet_remote_data {
let mut ordered_contracts_ids = match ASTDependencyDetector::order_contracts(
&requirements_deps,
&contract_epochs,
Expand Down
14 changes: 7 additions & 7 deletions components/clarinet-files/src/project_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ pub struct ClarityContractMetadata {
pub epoch: StacksEpochId,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ProjectManifestFile {
project: ProjectConfigFile,
contracts: Option<TomlValue>,
repl: Option<repl::SettingsFile>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ProjectConfigFile {
name: String,
Expand All @@ -48,6 +41,13 @@ pub struct ProjectConfigFile {
cache_dir: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ProjectManifestFile {
project: ProjectConfigFile,
contracts: Option<TomlValue>,
repl: Option<repl::SettingsFile>,
}

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct ProjectManifest {
pub project: ProjectConfig,
Expand Down
Loading