Skip to content

Commit

Permalink
Merge pull request #432 from hirosystems/fix/hyperchain-setup
Browse files Browse the repository at this point in the history
fix: hyperchain setup
  • Loading branch information
lgalabru authored Jul 12, 2022
2 parents 80bcbe1 + 45d384a commit 44798e5
Show file tree
Hide file tree
Showing 14 changed files with 489 additions and 168 deletions.
14 changes: 14 additions & 0 deletions components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,20 @@ pub async fn generate_default_deployment(
let mut remap_principals = BTreeMap::new();
remap_principals
.insert(contract_id.issuer.clone(), default_deployer_address.clone());
match network_manifest.devnet {
Some(ref devnet)
if devnet.hyperchain_contract_id == contract_id.to_string() =>
{
remap_principals.insert(
contract_id.issuer.clone(),
PrincipalData::parse_standard_principal(
&devnet.hyperchain_leader_stx_address,
)
.unwrap(),
);
}
_ => {}
}
let data = RequirementPublishSpecification {
contract_id: contract_id.clone(),
remap_sender: default_deployer_address.clone(),
Expand Down
103 changes: 58 additions & 45 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ pub const DEFAULT_BITCOIN_EXPLORER_IMAGE: &str = "quay.io/hirosystems/bitcoin-ex
pub const DEFAULT_STACKS_API_IMAGE: &str = "blockstack/stacks-blockchain-api:latest";
pub const DEFAULT_STACKS_EXPLORER_IMAGE: &str = "hirosystems/explorer:latest";
pub const DEFAULT_POSTGRES_IMAGE: &str = "postgres:alpine";
pub const DEFAULT_HYPERCHAINS_IMAGE: &str = "hirosystems/hyperchains:103-merge-stretch";
pub const DEFAULT_HYPERCHAIN_CONTRACT_ID: &str =
"ST3A7S7GFKR8E3TVZ41Z2N441265CKXS0QPZ94N6B.hc-alpha-2";
pub const DEFAULT_HYPERCHAIN_NODE_IMAGE: &str = "hirosystems/hyperchains:0.0.2-stretch";
pub const DEFAULT_HYPERCHAIN_CONTRACT_ID: &str = "STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.hc";
pub const DEFAULT_STACKS_MINER_MNEMONIC: &str = "fragile loan twenty basic net assault jazz absorb diet talk art shock innocent float punch travel gadget embrace caught blossom hockey surround initial reduce";
pub const DEFAULT_FAUCET_MNEMONIC: &str = "shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform";
pub const DEFAULT_HYPERCHAIN_MNEMONIC: &str = "female adjust gallery certain visit token during great side clown fitness like hurt clip knife warm bench start reunion globe detail dream depend fortune";

#[derive(Serialize, Deserialize, Debug)]
pub struct NetworkManifestFile {
Expand Down Expand Up @@ -67,7 +69,8 @@ pub struct DevnetConfigFile {
pub postgres_port: Option<u16>,
pub postgres_username: Option<String>,
pub postgres_password: Option<String>,
pub postgres_database: Option<String>,
pub stacks_api_postgres_database: Option<String>,
pub hyperchain_api_postgres_database: Option<String>,
pub pox_stacking_orders: Option<Vec<PoxStackingOrder>>,
pub execute_script: Option<Vec<ExecuteScript>>,
pub bitcoin_node_image_url: Option<String>,
Expand All @@ -81,14 +84,18 @@ pub struct DevnetConfigFile {
pub disable_stacks_api: Option<bool>,
pub bind_containers_volumes: Option<bool>,
pub enable_hyperchain_node: Option<bool>,
pub hyperchain_image_url: Option<String>,
pub hyperchain_node_image_url: Option<String>,
pub hyperchain_leader_mnemonic: Option<String>,
pub hyperchain_leader_derivation_path: Option<String>,
pub hyperchain_node_p2p_port: Option<u16>,
pub hyperchain_node_rpc_port: Option<u16>,
pub hyperchain_events_ingestion_port: Option<u16>,
pub hyperchain_node_events_observers: Option<Vec<String>>,
pub hyperchain_contract_id: Option<String>,
pub hyperchain_api_image_url: Option<String>,
pub hyperchain_api_port: Option<u16>,
pub hyperchain_api_events_port: Option<u16>,
pub disable_hyperchain_api: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -162,7 +169,8 @@ pub struct DevnetConfig {
pub postgres_port: u16,
pub postgres_username: String,
pub postgres_password: String,
pub postgres_database: String,
pub stacks_api_postgres_database: String,
pub hyperchain_api_postgres_database: String,
pub pox_stacking_orders: Vec<PoxStackingOrder>,
pub execute_script: Vec<ExecuteScript>,
pub bitcoin_node_image_url: String,
Expand All @@ -176,7 +184,7 @@ pub struct DevnetConfig {
pub disable_stacks_api: bool,
pub bind_containers_volumes: bool,
pub enable_hyperchain_node: bool,
pub hyperchain_image_url: String,
pub hyperchain_node_image_url: String,
pub hyperchain_leader_stx_address: String,
pub hyperchain_leader_secret_key_hex: String,
pub hyperchain_leader_btc_address: String,
Expand All @@ -187,6 +195,10 @@ pub struct DevnetConfig {
pub hyperchain_events_ingestion_port: u16,
pub hyperchain_node_events_observers: Vec<String>,
pub hyperchain_contract_id: String,
pub hyperchain_api_image_url: String,
pub hyperchain_api_port: u16,
pub hyperchain_api_events_port: u16,
pub disable_hyperchain_api: bool,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -324,54 +336,45 @@ impl NetworkManifest {
dir.push(format!("stacks-devnet-{}/", now));
let default_working_dir = dir.display().to_string();

let miner_mnemonic = devnet_config.miner_mnemonic.take().unwrap_or("fragile loan twenty basic net assault jazz absorb diet talk art shock innocent float punch travel gadget embrace caught blossom hockey surround initial reduce".to_string());
let miner_mnemonic = devnet_config
.miner_mnemonic
.take()
.unwrap_or(DEFAULT_STACKS_MINER_MNEMONIC.to_string());
let miner_derivation_path = devnet_config
.miner_derivation_path
.take()
.unwrap_or(DEFAULT_DERIVATION_PATH.to_string());
let (miner_stx_address, miner_btc_address, miner_secret_key_hex) =
compute_addresses(&miner_mnemonic, &miner_derivation_path, networks);

let faucet_mnemonic = devnet_config.faucet_mnemonic.take().unwrap_or("shadow private easily thought say logic fault paddle word top book during ignore notable orange flight clock image wealth health outside kitten belt reform".to_string());
let faucet_mnemonic = devnet_config
.faucet_mnemonic
.take()
.unwrap_or(DEFAULT_FAUCET_MNEMONIC.to_string());
let faucet_derivation_path = devnet_config
.faucet_derivation_path
.take()
.unwrap_or(DEFAULT_DERIVATION_PATH.to_string());
let (faucet_stx_address, faucet_btc_address, faucet_secret_key_hex) =
compute_addresses(&faucet_mnemonic, &faucet_derivation_path, networks);
// If unset, we'll reuse the miner's keypair for the hyperchain leader

let hyperchain_leader_mnemonic = devnet_config
.hyperchain_leader_mnemonic
.take()
.unwrap_or(DEFAULT_HYPERCHAIN_MNEMONIC.to_string());
let hyperchain_leader_derivation_path = devnet_config
.hyperchain_leader_derivation_path
.take()
.unwrap_or(DEFAULT_DERIVATION_PATH.to_string());
let (
hyperchain_leader_stx_address,
hyperchain_leader_btc_address,
hyperchain_leader_secret_key_hex,
hyperchain_leader_derivation_path,
hyperchain_leader_mnemonic,
) = if let Some(mnemonic) = devnet_config.hyperchain_leader_mnemonic.take() {
let derivation_path = devnet_config
.hyperchain_leader_derivation_path
.take()
.unwrap_or(DEFAULT_DERIVATION_PATH.to_string());
let (stx_address, btc_address, secret_key_hex) = compute_addresses(
&mnemonic,
&derivation_path,
&StacksNetwork::Devnet.get_networks(),
);
(
stx_address,
btc_address,
secret_key_hex,
derivation_path,
mnemonic,
)
} else {
(
miner_stx_address.clone(),
miner_btc_address.clone(),
miner_secret_key_hex.clone(),
miner_derivation_path.clone(),
miner_mnemonic.clone(),
)
};
) = compute_addresses(
&hyperchain_leader_mnemonic,
&hyperchain_leader_derivation_path,
networks,
);

let enable_hyperchain_node = devnet_config.enable_hyperchain_node.unwrap_or(false);
let hyperchain_events_ingestion_port = devnet_config
Expand Down Expand Up @@ -453,10 +456,14 @@ impl NetworkManifest {
.postgres_password
.take()
.unwrap_or("postgres".to_string()),
postgres_database: devnet_config
.postgres_database
stacks_api_postgres_database: devnet_config
.stacks_api_postgres_database
.take()
.unwrap_or("postgres".to_string()),
.unwrap_or("stacks_api".to_string()),
hyperchain_api_postgres_database: devnet_config
.hyperchain_api_postgres_database
.take()
.unwrap_or("hyperchain_api".to_string()),
execute_script: devnet_config.execute_script.take().unwrap_or(vec![]),
bitcoin_node_image_url: devnet_config
.bitcoin_node_image_url
Expand Down Expand Up @@ -488,10 +495,10 @@ impl NetworkManifest {
disable_stacks_explorer: devnet_config.disable_stacks_explorer.unwrap_or(false),
bind_containers_volumes: devnet_config.bind_containers_volumes.unwrap_or(false),
enable_hyperchain_node,
hyperchain_image_url: devnet_config
.hyperchain_image_url
hyperchain_node_image_url: devnet_config
.hyperchain_node_image_url
.take()
.unwrap_or(DEFAULT_HYPERCHAINS_IMAGE.to_string()),
.unwrap_or(DEFAULT_HYPERCHAIN_NODE_IMAGE.to_string()),
hyperchain_leader_btc_address,
hyperchain_leader_stx_address,
hyperchain_leader_mnemonic,
Expand All @@ -507,11 +514,17 @@ impl NetworkManifest {
hyperchain_contract_id: devnet_config
.hyperchain_contract_id
.unwrap_or(DEFAULT_HYPERCHAIN_CONTRACT_ID.to_string()),
hyperchain_api_image_url: devnet_config
.hyperchain_api_image_url
.take()
.unwrap_or(DEFAULT_STACKS_API_IMAGE.to_string()),
hyperchain_api_port: devnet_config.hyperchain_api_port.unwrap_or(13999),
hyperchain_api_events_port: devnet_config.stacks_api_events_port.unwrap_or(13700),
disable_hyperchain_api: devnet_config.disable_stacks_api.unwrap_or(false),
};
if !config.disable_stacks_api && config.disable_stacks_api {
config.disable_stacks_api = false;
}

Some(config)
} else {
None
Expand Down
32 changes: 18 additions & 14 deletions examples/counter/deployments/default.devnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,35 @@
id: 0
name: Devnet deployment
network: devnet
node: "http://localhost:20443"
stacks-node: "http://localhost:20443"
bitcoin-node: "http://devnet:devnet@localhost:18443"
plan:
batches:
- id: 0
transactions:
- requirement-publish:
contract-id: STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.ft-trait-standard
contract-id: STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.nft-trait-standard
remap-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
remap-principals: {}
path: "./.requirements/STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.ft-trait-standard.clar"
cost: 8340
remap-principals:
STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
cost: 4680
path: "./.requirements/STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.nft-trait-standard.clar"
- requirement-publish:
contract-id: STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.nft-trait-standard
contract-id: STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.ft-trait-standard
remap-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
remap-principals: {}
path: "./.requirements/STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.nft-trait-standard.clar"
cost: 4670
remap-principals:
STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
cost: 8340
path: "./.requirements/STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.ft-trait-standard.clar"
- requirement-publish:
contract-id: STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.hc-alpha
contract-id: STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.hc
remap-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
remap-principals: { STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM }
path: "./.requirements/STFTX3F4XCY7RS5VRHXP2SED0WC0YRKNWTNXD74P.hc-alpha.clar"
cost: 95010
remap-principals:
STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG: ST3NBRSFKX28FQ2ZJ1MAKX58HKHSDGNV5N7R21XCP
cost: 191170
path: "./.requirements/STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.hc.clar"
- contract-publish:
contract-name: counter
expected-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/counter.clar
cost: 5960
path: contracts/counter.clar
9 changes: 6 additions & 3 deletions examples/counter/settings/Devnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ balance = 100_000_000_000_000
# bitcoin_node_rpc_port = 18443
# bitcoin_node_username = "devnet"
# bitcoin_node_password = "devnet"
# bitcoin_controller_block_time = 30_000
bitcoin_controller_block_time = 30_000
# stacks_node_rpc_port = 20443
# stacks_node_p2p_port = 20444
# stacks_node_events_observers = ["localhot:8002"]
Expand All @@ -101,9 +101,12 @@ balance = 100_000_000_000_000
# postgres_image_url = "postgres:alpine"
# bitcoin_controller_automining_disabled = true
# disable_bitcoin_explorer = false
disable_stacks_explorer = true
disable_stacks_api = true
# disable_stacks_explorer = true
# disable_stacks_api = false
enable_hyperchain_node = true
# hyperchain_contract_id = "ST3A7S7GFKR8E3TVZ41Z2N441265CKXS0QPZ94N6B.hc"
# hyperchain_leader_mnemonic = "female adjust gallery certain visit token during great side clown fitness like hurt clip knife warm bench start reunion globe detail dream depend fortune"
# disable_hyperchain_api = true

[[devnet.pox_stacking_orders]]
start_at_cycle = 3
Expand Down
7 changes: 0 additions & 7 deletions node-bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,6 @@ impl StacksDevnet {
overrides.postgres_password = Some(res.value(&mut cx));
}

if let Ok(res) = devnet_settings
.get(&mut cx, "postgres_database")?
.downcast::<JsString, _>(&mut cx)
{
overrides.postgres_database = Some(res.value(&mut cx));
}

if let Ok(res) = devnet_settings
.get(&mut cx, "bitcoin_node_image_url")?
.downcast::<JsString, _>(&mut cx)
Expand Down
16 changes: 10 additions & 6 deletions src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1426,17 +1426,21 @@ impl DiagnosticsDigest {
let total = deployment.contracts.len();

for (contract_id, diags) in contracts_diags.into_iter() {
contracts_checked += 1;
let (source, contract_location) = match deployment.contracts.get(&contract_id) {
Some(entry) => {
contracts_checked += 1;
entry
}
None => {
// `deployment.contracts` only includes contracts from the project, requirements should be ignored
continue;
}
};
if diags.is_empty() {
full_success += 1;
continue;
}

let (source, contract_location) = deployment
.contracts
.get(&contract_id)
.expect("unable to retrieve contract");

let lines = source.lines();
let formatted_lines: Vec<String> = lines.map(|l| l.to_string()).collect();

Expand Down
5 changes: 3 additions & 2 deletions src/generate/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,10 @@ disable_stacks_api = false
# bitcoin_explorer_image_url = "quay.io/hirosystems/bitcoin-explorer:devnet"
# postgres_image_url = "postgres:alpine"
# enable_hyperchain_node = true
# hyperchain_image_url = "hirosystems/hyperchains:103-merge-stretch"
# hyperchain_leader_mnemonic = "twice kind fence tip hidden tilt action fragile skin nothing glory cousin green tomorrow spring wrist shed math olympic multiply hip blue scout claw"
# hyperchain_node_image_url = "hirosystems/hyperchains:0.0.2-stretch"
# hyperchain_leader_mnemonic = "female adjust gallery certain visit token during great side clown fitness like hurt clip knife warm bench start reunion globe detail dream depend fortune"
# hyperchain_leader_derivation_path = "m/44'/5757'/0'/0/0"
# hyperchain_contract_id = "STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.hc"
# hyperchain_node_rpc_port = 30443
# hyperchain_node_p2p_port = 30444
# hyperchain_events_ingestion_port = 30445
Expand Down
Loading

0 comments on commit 44798e5

Please sign in to comment.