Skip to content

Commit

Permalink
Merge pull request #480 from hirosystems/feat/hyperchain-adjustments
Browse files Browse the repository at this point in the history
fix: microblocks + hyperchain adjustments
  • Loading branch information
lgalabru authored Jul 14, 2022
2 parents 37c5bc7 + 8dd59d9 commit 3ad30f6
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 109 deletions.
1 change: 1 addition & 0 deletions components/clarinet-deployments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ pub async fn generate_default_deployment(
cost: deployment_fee_rate
.saturating_mul(source.as_bytes().len().try_into().unwrap()),
source,
anchor_block_only: true,
})
};

Expand Down
10 changes: 10 additions & 0 deletions components/clarinet-deployments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ pub struct ContractCallSpecificationFile {
pub method: String,
pub parameters: Vec<String>,
pub cost: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub anchor_block_only: Option<bool>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -101,6 +103,8 @@ pub struct ContractPublishSpecificationFile {
pub path: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub anchor_block_only: Option<bool>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -170,6 +174,7 @@ pub struct ContractCallSpecification {
pub method: ClarityName,
pub parameters: Vec<String>,
pub cost: u64,
pub anchor_block_only: bool,
}

impl ContractCallSpecification {
Expand Down Expand Up @@ -213,6 +218,7 @@ impl ContractCallSpecification {
method,
parameters: specs.parameters.clone(),
cost: specs.cost,
anchor_block_only: specs.anchor_block_only.unwrap_or(true),
})
}
}
Expand All @@ -224,6 +230,7 @@ pub struct ContractPublishSpecification {
pub location: FileLocation,
pub source: String,
pub cost: u64,
pub anchor_block_only: bool,
}

impl ContractPublishSpecification {
Expand Down Expand Up @@ -270,6 +277,7 @@ impl ContractPublishSpecification {
source,
location: location,
cost: specs.cost,
anchor_block_only: specs.anchor_block_only.unwrap_or(true),
})
}
}
Expand Down Expand Up @@ -763,6 +771,7 @@ impl TransactionPlanSpecification {
method: tx.method.to_string(),
parameters: tx.parameters.clone(),
cost: tx.cost,
anchor_block_only: Some(tx.anchor_block_only),
})
}
TransactionSpecification::ContractPublish(tx) => {
Expand All @@ -774,6 +783,7 @@ impl TransactionPlanSpecification {
path: None,
url: None,
cost: tx.cost,
anchor_block_only: Some(tx.anchor_block_only),
},
)
}
Expand Down
20 changes: 15 additions & 5 deletions components/clarinet-files/src/network_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use std::collections::BTreeMap;

use super::FileLocation;
use bip39::{Language, Mnemonic};
use clarity_repl::clarity::util::hash::bytes_to_hex;
use clarity_repl::clarity::util::secp256k1::Secp256k1PublicKey;
use clarity_repl::clarity::util::StacksAddress;
use clarity_repl::clarity::{types::QualifiedContractIdentifier, util::hash::bytes_to_hex};
use libsecp256k1::{PublicKey, SecretKey};
use orchestra_types::{BitcoinNetwork, StacksNetwork};
use tiny_hderive::bip32::ExtendedPrivKey;
Expand Down Expand Up @@ -195,6 +195,7 @@ pub struct DevnetConfig {
pub hyperchain_events_ingestion_port: u16,
pub hyperchain_node_events_observers: Vec<String>,
pub hyperchain_contract_id: String,
pub remapped_hyperchain_contract_id: String,
pub hyperchain_api_image_url: String,
pub hyperchain_api_port: u16,
pub hyperchain_api_events_port: u16,
Expand Down Expand Up @@ -406,6 +407,16 @@ impl NetworkManifest {
},
);
}
let hyperchain_contract_id = devnet_config
.hyperchain_contract_id
.unwrap_or(DEFAULT_HYPERCHAIN_CONTRACT_ID.to_string());
let contract_id = QualifiedContractIdentifier::parse(&hyperchain_contract_id)
.expect("hyperchain contract_id invalid");
let default_deployer = accounts
.get("deployer")
.expect("default deployer account unavailable");
let remapped_hyperchain_contract_id =
format!("{}.{}", default_deployer.stx_address, contract_id.name);

let mut config = DevnetConfig {
orchestrator_ingestion_port: devnet_config.orchestrator_port.unwrap_or(20445),
Expand All @@ -422,7 +433,7 @@ impl NetworkManifest {
.unwrap_or("devnet".to_string()),
bitcoin_controller_block_time: devnet_config
.bitcoin_controller_block_time
.unwrap_or(30_000),
.unwrap_or(90_000),
bitcoin_controller_automining_disabled: devnet_config
.bitcoin_controller_automining_disabled
.unwrap_or(false),
Expand Down Expand Up @@ -511,9 +522,8 @@ impl NetworkManifest {
.hyperchain_node_events_observers
.take()
.unwrap_or(vec![]),
hyperchain_contract_id: devnet_config
.hyperchain_contract_id
.unwrap_or(DEFAULT_HYPERCHAIN_CONTRACT_ID.to_string()),
hyperchain_contract_id,
remapped_hyperchain_contract_id,
hyperchain_api_image_url: devnet_config
.hyperchain_api_image_url
.take()
Expand Down
3 changes: 2 additions & 1 deletion 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 @@ -104,6 +104,7 @@ bitcoin_controller_block_time = 30_000
# disable_stacks_explorer = true
# disable_stacks_api = false
enable_hyperchain_node = true
# hyperchain_contract_id = "STXMJXCJDCT4WPF2X1HE42T6ZCCK3TPMBRZ51JEG.hyperchain"
# 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
Expand Down
22 changes: 20 additions & 2 deletions src/deployments/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,12 @@ fn sign_transaction_payload(
payload: TransactionPayload,
nonce: u64,
tx_fee: u64,
anchor_mode: TransactionAnchorMode,
network: &StacksNetwork,
) -> Result<StacksTransaction, String> {
let (_, secret_key, public_key) = get_keypair(account);
let signer_addr = get_stacks_address(&public_key, network);

let anchor_mode = TransactionAnchorMode::OnChainOnly;

let spending_condition = TransactionSpendingCondition::Singlesig(SinglesigSpendingCondition {
signer: signer_addr.bytes.clone(),
nonce: nonce,
Expand Down Expand Up @@ -169,6 +168,7 @@ pub fn encode_contract_call(
account: &AccountConfig,
nonce: u64,
tx_fee: u64,
anchor_mode: TransactionAnchorMode,
network: &StacksNetwork,
) -> Result<StacksTransaction, String> {
let payload = TransactionContractCall {
Expand All @@ -182,6 +182,7 @@ pub fn encode_contract_call(
TransactionPayload::ContractCall(payload),
nonce,
tx_fee,
anchor_mode,
network,
)
}
Expand All @@ -192,6 +193,7 @@ pub fn encode_contract_publish(
account: &AccountConfig,
nonce: u64,
tx_fee: u64,
anchor_mode: TransactionAnchorMode,
network: &StacksNetwork,
) -> Result<StacksTransaction, String> {
let payload = TransactionSmartContract {
Expand All @@ -203,6 +205,7 @@ pub fn encode_contract_publish(
TransactionPayload::SmartContract(payload),
nonce,
tx_fee,
anchor_mode,
network,
)
}
Expand Down Expand Up @@ -448,13 +451,19 @@ pub fn apply_on_chain_deployment(
})
.collect::<Vec<_>>();

let anchor_mode = match tx.anchor_block_only {
true => TransactionAnchorMode::OnChainOnly,
false => TransactionAnchorMode::Any,
};

let transaction = match encode_contract_call(
&tx.contract_id,
tx.method.clone(),
function_args,
*account,
nonce,
tx.cost,
anchor_mode,
&network,
) {
Ok(res) => res,
Expand Down Expand Up @@ -509,12 +518,18 @@ pub fn apply_on_chain_deployment(
tx.source.clone()
};

let anchor_mode = match tx.anchor_block_only {
true => TransactionAnchorMode::OnChainOnly,
false => TransactionAnchorMode::Any,
};

let transaction = match encode_contract_publish(
&tx.contract_name,
&source,
*account,
nonce,
tx.cost,
anchor_mode,
&network,
) {
Ok(res) => res,
Expand Down Expand Up @@ -577,12 +592,15 @@ pub fn apply_on_chain_deployment(
}
}

let anchor_mode = TransactionAnchorMode::OnChainOnly;

let transaction = match encode_contract_publish(
&tx.contract_id.name,
&source,
*account,
nonce,
tx.cost,
anchor_mode,
&network,
) {
Ok(res) => res,
Expand Down
10 changes: 7 additions & 3 deletions src/integrate/chains_coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ pub async fn start_chains_coordinator(
chains_coordinator_commands_rx: Receiver<ChainsCoordinatorCommand>,
chains_coordinator_commands_tx: Sender<ChainsCoordinatorCommand>,
chains_coordinator_terminator_tx: Sender<bool>,
observer_command_tx: Sender<ObserverCommand>,
observer_command_rx: Receiver<ObserverCommand>,
) -> Result<(), String> {
let (deployment_events_tx, deployment_events_rx) = channel();
let (deployment_commands_tx, deployments_command_rx) = channel();
Expand All @@ -146,7 +148,6 @@ pub async fn start_chains_coordinator(
}

// Spawn event observer
let (observer_command_tx, observer_command_rx) = channel();
let (observer_event_tx, observer_event_rx) = channel();
let event_observer_config = config.event_observer_config.clone();
let observer_event_tx_moved = observer_event_tx.clone();
Expand Down Expand Up @@ -282,8 +283,9 @@ pub async fn start_chains_coordinator(
}
}
StacksChainEvent::ChainUpdatedWithMicroblocks(_) => {
let _ = devnet_event_tx.send(DevnetEvent::StacksChainEvent(chain_event));
continue;
// TODO(lgalabru): good enough for now - code path unreachable in the context of Devnet
// TODO(lgalabru): good enough for now
}
StacksChainEvent::ChainUpdatedWithMicroblocksReorg(_) => {
unreachable!() // TODO(lgalabru): good enough for now - code path unreachable in the context of Devnet
Expand Down Expand Up @@ -359,7 +361,9 @@ pub async fn start_chains_coordinator(
.send(DevnetEvent::info(format!("{} hooks triggered", count)));
}
}
ObserverEvent::Terminate => {}
ObserverEvent::Terminate => {
break;
}
ObserverEvent::StacksChainMempoolEvent(mempool_event) => match mempool_event {
StacksChainMempoolEvent::TransactionsAdmitted(transactions) => {
// Temporary UI patch
Expand Down
6 changes: 6 additions & 0 deletions src/integrate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,20 @@ pub async fn do_run_devnet(
let chains_coordinator_tx = devnet_events_tx.clone();
let (chains_coordinator_commands_tx, chains_coordinator_commands_rx) = channel();
let (orchestrator_terminator_tx, terminator_rx) = channel();
let (observer_command_tx, observer_command_rx) = channel();
let moved_orchestrator_terminator_tx = orchestrator_terminator_tx.clone();
let moved_chains_coordinator_commands_tx = chains_coordinator_commands_tx.clone();
let moved_observer_command_tx = observer_command_tx.clone();

let chains_coordinator_handle = std::thread::spawn(move || {
let future = start_chains_coordinator(
config,
chains_coordinator_tx,
chains_coordinator_commands_rx,
moved_chains_coordinator_commands_tx,
moved_orchestrator_terminator_tx,
observer_command_tx,
observer_command_rx,
);
let rt = utils::create_basic_runtime();
rt.block_on(future)
Expand All @@ -119,6 +124,7 @@ pub async fn do_run_devnet(
devnet_events_tx,
devnet_events_rx,
moved_chains_coordinator_commands_tx,
moved_observer_command_tx,
orchestrator_terminated_rx,
&devnet_path,
devnet_config.enable_hyperchain_node,
Expand Down
2 changes: 1 addition & 1 deletion src/integrate/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ observer_port = {hyperchain_events_ingestion_port}
orchestrator_port = devnet_config.orchestrator_ingestion_port,
hyperchain_events_ingestion_port = devnet_config.hyperchain_events_ingestion_port,
first_burn_header_height = 0,
hyperchain_contract_id = "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.hc" //devnet_config.hyperchain_contract_id,
hyperchain_contract_id = devnet_config.remapped_hyperchain_contract_id,
);

hyperchain_conf.push_str(&format!(
Expand Down
22 changes: 19 additions & 3 deletions src/integrate/ui/app.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
use super::util::{StatefulList, TabsState};
use crate::integrate::{LogData, MempoolAdmissionData, ServiceStatusData};
use orchestra_types::{StacksBlockData, StacksTransactionData};
use orchestra_types::{StacksBlockData, StacksMicroblockData, StacksTransactionData};
use tui::style::{Color, Style};
use tui::text::{Span, Spans};

pub enum BlockData {
Block(StacksBlockData),
Microblock(StacksMicroblockData),
}

pub struct App<'a> {
pub title: &'a str,
pub hyperchain_enabled: bool,
pub devnet_path: &'a str,
pub should_quit: bool,
pub blocks: Vec<StacksBlockData>,
pub blocks: Vec<BlockData>,
pub tabs: TabsState<'a>,
pub transactions: StatefulList<StacksTransactionData>,
pub mempool: StatefulList<MempoolAdmissionData>,
Expand Down Expand Up @@ -119,7 +124,18 @@ impl<'a> App<'a> {
Style::default().fg(Color::LightYellow)
},
)));
self.blocks.push(block);
self.blocks.push(BlockData::Block(block));
if self.tabs.index != 0 {
self.tabs.index += 1;
}
}

pub fn display_microblock(&mut self, block: StacksMicroblockData) {
self.tabs.titles.push_front(Spans::from(Span::styled(
format!("[·]"),
Style::default().fg(Color::White),
)));
self.blocks.push(BlockData::Microblock(block));
if self.tabs.index != 0 {
self.tabs.index += 1;
}
Expand Down
Loading

0 comments on commit 3ad30f6

Please sign in to comment.