Skip to content

Commit

Permalink
Merge pull request #570 from hirosystems/fix/boot-contracts-performances
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru authored Oct 7, 2022
2 parents ce2f5a3 + 061b284 commit 42b0ae0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
3 changes: 2 additions & 1 deletion components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use clarity_repl::clarity::vm::types::QualifiedContractIdentifier;
use clarity_repl::clarity::vm::ContractName;
use clarity_repl::clarity::vm::EvaluationResult;
use clarity_repl::clarity::vm::ExecutionResult;
use clarity_repl::repl::session::BOOT_CONTRACTS_ASTS;
use clarity_repl::repl::Session;
use clarity_repl::repl::SessionSettings;
use std::collections::{BTreeMap, HashMap, VecDeque};
Expand Down Expand Up @@ -271,7 +272,7 @@ pub async fn generate_default_deployment(
settings.repl_settings = manifest.repl_settings.clone();

let session = Session::new(settings.clone());
let mut boot_contracts_asts = session.get_boot_contracts_asts();
let mut boot_contracts_asts = BOOT_CONTRACTS_ASTS.clone();
let boot_contracts_ids = boot_contracts_asts
.iter()
.map(|(k, _)| k.clone())
Expand Down
61 changes: 30 additions & 31 deletions components/clarity-repl/src/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::{
use crate::analysis::ast_dependency_detector::{ASTDependencyDetector, Dependency};
use crate::analysis::coverage::{self, TestCoverageReport};
use crate::repl::settings::InitialContract;
use crate::repl::Settings;
use crate::utils;
use ansi_term::{Colour, Style};
use clarity::codec::StacksMessageCodec;
Expand Down Expand Up @@ -49,6 +50,35 @@ lazy_static! {
PrincipalData::parse_standard_principal(&BOOT_MAINNET_ADDRESS).unwrap();
}

lazy_static! {
pub static ref BOOT_CONTRACTS_ASTS: BTreeMap<QualifiedContractIdentifier, ContractAST> = {
let mut asts = BTreeMap::new();
let deploy: [(&StandardPrincipalData, [(&str, &str); 9]); 2] = [
(&*BOOT_TESTNET_PRINCIPAL, *STACKS_BOOT_CODE_TESTNET),
(&*BOOT_MAINNET_PRINCIPAL, *STACKS_BOOT_CODE_MAINNET),
];

let interpreter =
ClarityInterpreter::new(StandardPrincipalData::transient(), Settings::default());
for contract in deploy.iter() {
let deployer = contract.0;
let boot_code = contract.1;
for (name, code) in boot_code.iter() {
let boot_contract = ClarityContract {
code_source: ClarityCodeSource::ContractInMemory(code.to_string()),
deployer: ContractDeployer::Address(deployer.to_address()),
name: name.to_string(),
clarity_version: ClarityVersion::Clarity1,
epoch: StacksEpochId::Epoch20,
};
let (ast, _, _) = interpreter.build_ast(&boot_contract);
asts.insert(boot_contract.expect_resolved_contract_identifier(None), ast);
}
}
asts
};
}

enum Command {
LoadLocalContract(String),
LoadDeployContract(String),
Expand Down Expand Up @@ -159,37 +189,6 @@ impl Session {
}
}

pub fn get_boot_contracts_asts(&self) -> BTreeMap<QualifiedContractIdentifier, ContractAST> {
let mut asts = BTreeMap::new();
let deploy: [(&StandardPrincipalData, [(&str, &str); 9]); 2] = [
(&*BOOT_TESTNET_PRINCIPAL, *STACKS_BOOT_CODE_TESTNET),
(&*BOOT_MAINNET_PRINCIPAL, *STACKS_BOOT_CODE_MAINNET),
];
// for (deployer, boot_code) in deploy.iter() {
for contract in deploy.iter() {
let deployer = contract.0;
let boot_code = contract.1;
for (name, code) in boot_code.iter() {
if self
.settings
.include_boot_contracts
.contains(&name.to_string())
{
let boot_contract = ClarityContract {
code_source: ClarityCodeSource::ContractInMemory(code.to_string()),
deployer: ContractDeployer::Address(deployer.to_address()),
name: name.to_string(),
clarity_version: ClarityVersion::Clarity1,
epoch: StacksEpochId::Epoch20,
};
let (ast, _, _) = self.interpreter.build_ast(&boot_contract);
asts.insert(boot_contract.expect_resolved_contract_identifier(None), ast);
}
}
}
asts
}

#[cfg(feature = "wasm")]
pub async fn start_wasm(&mut self) -> String {
let mut output = Vec::<String>::new();
Expand Down

0 comments on commit 42b0ae0

Please sign in to comment.