Skip to content

Commit 68b0d09

Browse files
committed
feat: introduce clean flag for speeding up the development
1 parent 14a32db commit 68b0d09

File tree

8 files changed

+91
-42
lines changed

8 files changed

+91
-42
lines changed

cardano/gateway/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ CARDANO_CHAIN_PORT=3001
1414
CARDANO_NETWORK_MAGIC=42
1515
CARDANO_EPOCH_NONCE_GENESIS="5569014c252a963bad2efaa35e0db74c9581db3d107cb817810916b1463e7550"
1616

17+
HANDLER_JSON_PATH=../deployment/offchain/handler.json
18+
1719
MITHRIL_ENDPOINT=http://127.0.0.1:8080/aggregator
1820
MITHRIL_GENESIS_VERIFICATION_KEY=5b33322c3235332c3138362c3230312c3137372c31312c3131372c3133352c3138372c3136372c3138312c3138382c32322c35392c3230362c3130352c3233312c3135302c3231352c33302c37382c3231322c37362c31362c3235322c3138302c37322c3133342c3133372c3234372c3136312c36385d
1921
# MITHRIL_ENDPOINT=https://aggregator.testing-preview.api.mithril.network/aggregator

cardano/gateway/docker-compose.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
services:
22
app:
3-
build:
3+
build:
44
context: ../..
55
dockerfile: cardano/gateway/Dockerfile
6-
network_mode: "host"
6+
network_mode: 'host'
77
volumes:
88
- ../../chains/mithrils/data/aggregator/stores:/usr/chains/mithrils/data/aggregator/stores
9+
- ../offchain/deployments:/usr/src/app/cardano/offchain/deployments
910
env_file:
1011
- .env
11-
12-

cardano/gateway/src/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { MithrilModule } from './shared/modules/mithril/mithril.module';
1919
load: [
2020
configuration,
2121
() => ({
22-
deployment: require('./deployment/handler.json'),
22+
deployment: require(process.env.HANDLER_JSON_PATH || '../deployment/offchain/handler.json'),
2323
}),
2424
],
2525
isGlobal: true,

cardano/gateway/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@config/*": ["src/config/*"]
2727
}
2828
},
29-
"include": ["src/**/*", "handler.json", "src/deployment/handler.json"],
29+
"include": ["src/**/*"],
3030
"exclude": ["*.test.ts", "*.spec.ts"],
3131
"rootDirs": ["src", "../../proto-types"]
3232
}

caribic/src/main.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ enum Commands {
7878
Start {
7979
#[arg(value_enum, default_value_t = StartTarget::All)]
8080
target: StartTarget,
81+
/// Cleans up the local environment before starting the services
82+
#[arg(long, default_value_t = false)]
83+
clean: bool,
8184
},
8285
/// Stops a specific bridge component. The component can be either the network, bridge, demo or all. Default is all
8386
Stop {
@@ -276,10 +279,12 @@ async fn main() {
276279
);
277280
}
278281
}
279-
Commands::Start { target } => {
282+
Commands::Start { target, clean } => {
280283
let project_config = config::get_config();
281284
let project_root_path = Path::new(&project_config.project_root);
282285

286+
let mut cardano_current_epoch = 0;
287+
283288
if target == StartTarget::Network || target == StartTarget::All {
284289
// Start the local Cardano network and its services
285290
match start_local_cardano_network(&project_root_path).await {
@@ -289,26 +294,26 @@ async fn main() {
289294
error
290295
)),
291296
}
292-
293-
let mut cardano_current_epoch = 0;
294297
// Start Mithril if needed
295-
match start_mithril(&project_root_path).await {
296-
Ok(current_epoch) => {
297-
cardano_current_epoch = current_epoch;
298-
logger::log("✅ Mithril up and running")
299-
}
300-
Err(error) => {
301-
network_down_with_error(&format!("❌ Failed to start Mithril: {}", error))
298+
if target == StartTarget::All {
299+
match start_mithril(&project_root_path).await {
300+
Ok(current_epoch) => {
301+
cardano_current_epoch = current_epoch;
302+
logger::log("✅ Mithril up and running")
303+
}
304+
Err(error) => network_down_with_error(&format!(
305+
"❌ Failed to start Mithril: {}",
306+
error
307+
)),
302308
}
309+
} else {
310+
// Wait for Mithril to start reading the immutable cardano node files
311+
match wait_and_start_mithril_genesis(&project_root_path, cardano_current_epoch) {
312+
Ok(_) => logger::log("✅ Immutable Cardano node files have been created, and Mithril is working as expected"),
313+
Err(error) => {
314+
network_down_with_error(&format!("❌ Mithril failed to read the immutable cardano node files: {}", error))
315+
}}
303316
}
304-
305-
// Wait for Mithril to start reading the immutable cardano node files
306-
match wait_and_start_mithril_genesis(&project_root_path, cardano_current_epoch) {
307-
Ok(_) => logger::log("✅ Immutable Cardano node files have been created, and Mithril is working as expected"),
308-
Err(error) => {
309-
network_down_with_error(&format!("❌ Mithril failed to read the immutable cardano node files: {}", error))
310-
}}
311-
312317
logger::log("\n✅ Cardano Network started successfully");
313318
}
314319

@@ -323,7 +328,7 @@ async fn main() {
323328
));
324329

325330
// Deploy Contracts
326-
match deploy_contracts(&project_root_path).await {
331+
match deploy_contracts(&project_root_path, clean).await {
327332
Ok(_) => logger::log("✅ Cardano Scripts correcty deployed"),
328333
Err(error) => bridge_down_with_error(&format!(
329334
"❌ Failed to deploy Cardano Scripts: {}",
@@ -341,7 +346,7 @@ async fn main() {
341346
));
342347

343348
// Start gateway
344-
match start_gateway(project_root_path.join("cardano/gateway").as_path()) {
349+
match start_gateway(project_root_path.join("cardano/gateway").as_path(), clean) {
345350
Ok(_) => logger::log("✅ Gateway started successfully"),
346351
Err(error) => {
347352
bridge_down_with_error(&format!("❌ Failed to start gateway: {}", error))
@@ -353,6 +358,14 @@ async fn main() {
353358
"addr_test1vz8nzrmel9mmmu97lm06uvm55cj7vny6dxjqc0y0efs8mtqsd8r5m",
354359
);
355360
logger::log(&format!("Final balance {}", &balance.to_string().as_str()));
361+
if target == StartTarget::All {
362+
match wait_and_start_mithril_genesis(&project_root_path, cardano_current_epoch) {
363+
Ok(_) => logger::log("✅ Immutable Cardano node files have been created, and Mithril is working as expected"),
364+
Err(error) => {
365+
network_down_with_error(&format!("❌ Mithril failed to read the immutable cardano node files: {}", error))
366+
}
367+
}
368+
}
356369
}
357370
}
358371
}

caribic/src/setup.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,13 @@ fn get_genesis_hash(era: String, script_dir: &Path) -> Result<String, Box<dyn st
457457
genesis_file.as_str(),
458458
];
459459
} else {
460-
cli_args = vec!["conway", "genesis", "hash", "--genesis", genesis_file.as_str()];
460+
cli_args = vec![
461+
"conway",
462+
"genesis",
463+
"hash",
464+
"--genesis",
465+
genesis_file.as_str(),
466+
];
461467
}
462468

463469
let genesis_hash = Command::new("docker")

caribic/src/start.rs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -216,25 +216,54 @@ pub async fn start_local_cardano_network(
216216
Ok(())
217217
}
218218

219-
pub async fn deploy_contracts(project_root_path: &Path) -> Result<(), Box<dyn std::error::Error>> {
219+
pub async fn deploy_contracts(
220+
project_root_path: &Path,
221+
clean: bool,
222+
) -> Result<(), Box<dyn std::error::Error>> {
220223
let optional_progress_bar = match logger::get_verbosity() {
221224
logger::Verbosity::Verbose => None,
222225
_ => Some(ProgressBar::new_spinner()),
223226
};
224227

225-
log_or_show_progress(
226-
&format!(
227-
"{} 🛠️ Building Aiken validators",
228-
style("Step 4/5").bold().dim()
229-
),
230-
&optional_progress_bar,
231-
);
232-
execute_script(
233-
project_root_path.join("cardano").join("onchain").as_path(),
234-
"aiken",
235-
Vec::from(["build", "--trace-filter", "all", "--trace-level", "verbose"]),
236-
None,
237-
)?;
228+
let is_verbose = logger::get_verbosity() == logger::Verbosity::Verbose;
229+
230+
if !project_root_path
231+
.join("cardano")
232+
.join("plutus.json")
233+
.as_path()
234+
.exists()
235+
|| clean
236+
|| is_verbose
237+
{
238+
log_or_show_progress(
239+
&format!(
240+
"{} 🛠️ Building Aiken validators",
241+
style("Step 4/5").bold().dim()
242+
),
243+
&optional_progress_bar,
244+
);
245+
246+
let build_args = if is_verbose {
247+
vec!["build", "--trace-filter", "all", "--trace-level", "verbose"]
248+
} else {
249+
vec!["build"]
250+
};
251+
252+
execute_script(
253+
project_root_path.join("cardano").join("onchain").as_path(),
254+
"aiken",
255+
build_args,
256+
None,
257+
)?;
258+
} else {
259+
log_or_show_progress(
260+
&format!(
261+
"{} 🛠️ Aiken validators already built",
262+
style("Step 4/5").bold().dim()
263+
),
264+
&optional_progress_bar,
265+
);
266+
}
238267

239268
log_or_show_progress(
240269
&format!(

chains/cardano/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
cardano-node:
3-
image: ghcr.io/blinklabs-io/cardano-node:10.1.4-1
3+
image: ghcr.io/blinklabs-io/cardano-node:10.1.4-3
44
container_name: cardano-node
55
volumes:
66
- ./devnet:/devnet

0 commit comments

Comments
 (0)