Skip to content

Commit c206027

Browse files
authored
fix: use pocketic btc init (#4413)
1 parent 786ca0c commit c206027

File tree

15 files changed

+30
-378
lines changed

15 files changed

+30
-378
lines changed

.github/workflows/bitcoin-canister-update.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ Improved the canister snapshot download/upload feature by
1010
- supporting download/upload with resuming.
1111
- supporting download/upload with concurrency, default to 3 tasks in parallel.
1212

13+
### fix: use `pocket-ic` to init BTC canisters
14+
15+
The custom logic was prone to becoming outdated, such as not adapting to changing cycles fees.
16+
By using `pocket-ic`, which gets updated frequently, the BTC integration is significanly less likely to break.
17+
1318
# 0.30.0
1419

1520
### feat: `dfx start --system-canisters` for bootstrapping system canisters

e2e/tests-dfx/bitcoin.bash

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,9 @@ set_local_network_bitcoin_enabled() {
4242
dfx_start --enable-bitcoin
4343

4444
assert_command dfx canister info "$BITCOIN_CANISTER_ID"
45-
assert_contains "Controllers: 2vxsx-fae"
4645
assert_contains "Module hash: 0x"
4746
}
4847

49-
@test "bitcoin canister has decent amount of cycles" {
50-
dfx_start --enable-bitcoin
51-
# The canister is created with default amount of cycles: 100T
52-
cycles_balance=$( dfx --identity anonymous canister status "$BITCOIN_CANISTER_ID" 2>&1 | grep 'Balance:' | sed 's/[^0-9]//g' )
53-
assert_command test "$cycles_balance" -gt 99000000000000 # 99T
54-
}
55-
5648
@test "can call bitcoin API of the management canister" {
5749
install_asset bitcoin
5850
dfx_start --enable-bitcoin

scripts/update-btc-canister.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/dfx/assets/build.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ fn add_assets(sources: Sources) {
241241
add_asset_archive("assetstorage_canister", &mut f, &dfx_assets);
242242
add_asset_archive("wallet_canister", &mut f, &dfx_assets);
243243
add_asset_archive("ui_canister", &mut f, &dfx_assets);
244-
add_asset_archive("btc_canister", &mut f, &dfx_assets);
245244
add_assets_from_directory("language_bindings", &mut f, "assets/language_bindings");
246245
add_assets_from_directory(
247246
"new_project_motoko_files",

src/dfx/assets/dfx-asset-sources.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,10 @@
5454
"sha256": "c41db448cf9fd63d285aac5415e122d1970a94e13a870a381322584f3153c2b4",
5555
"version": "0.16.2"
5656
},
57-
"ic-btc-canister": {
58-
"url": "https://github.com/dfinity/bitcoin-canister/releases/download/release%2F2025-07-02/ic-btc-canister.wasm.gz",
59-
"sha256": "42af59ae4fd5041f30f8ac12f324e3a93533de0cb89cd2278100c2389cbfff65",
60-
"version": "release/2025-07-02"
61-
},
6257
"motoko-core": {
6358
"url": "https://github.com/dfinity/motoko/releases/download/0.16.2/motoko-core.tar.gz",
6459
"sha256": "e4154b1cff9387bb1ead2e3c0ddbeeb39fe9aa2c5a4d8af0142b3f7b174a5fa2",
6560
"version": "0.16.2"
6661
}
6762
}
68-
}
63+
}

src/dfx/assets/prepare_assets.rs

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,6 @@ fn copy_canisters(out_dir: PathBuf) {
5353
}
5454
}
5555

56-
async fn download_canisters(
57-
client: Client,
58-
sources: Arc<HashMap<String, Source>>,
59-
out_dir: PathBuf,
60-
) {
61-
// replace with joinset setup from download_binaries if another gets added
62-
let source = sources["ic-btc-canister"].clone();
63-
let btc_canister = download_and_check_sha(client, source).await;
64-
spawn_blocking(move || {
65-
let mut tar = Builder::new(GzEncoder::new(
66-
BufWriter::new(File::create(out_dir.join("btc_canister.tgz")).unwrap()),
67-
Compression::new(6),
68-
));
69-
let mut header = Header::new_gnu();
70-
header.set_mode(0o644);
71-
header.set_size(btc_canister.len() as u64);
72-
tar.append_data(
73-
&mut header,
74-
"ic-btc-canister.wasm.gz",
75-
btc_canister.reader(),
76-
)
77-
.unwrap();
78-
tar.finish().unwrap();
79-
})
80-
.await
81-
.unwrap();
82-
}
83-
8456
async fn make_binary_cache(out_dir: PathBuf, sources: HashMap<String, Source>) {
8557
let sources = Arc::new(sources);
8658
let client = Client::builder()
@@ -91,13 +63,8 @@ async fn make_binary_cache(out_dir: PathBuf, sources: HashMap<String, Source>) {
9163
let mo_core = spawn(download_mo_core(client.clone(), sources.clone()));
9264
let bins = spawn(download_binaries(client.clone(), sources.clone()));
9365
let bin_tars = spawn(download_bin_tarballs(client.clone(), sources.clone()));
94-
let canisters = spawn(download_canisters(
95-
client.clone(),
96-
sources.clone(),
97-
out_dir.clone(),
98-
));
99-
let (mo_base, mo_core, bins, bin_tars, _) =
100-
tokio::try_join!(mo_base, mo_core, bins, bin_tars, canisters).unwrap();
66+
let (mo_base, mo_core, bins, bin_tars) =
67+
tokio::try_join!(mo_base, mo_core, bins, bin_tars).unwrap();
10168
spawn_blocking(|| write_binary_cache(out_dir, mo_base, mo_core, bins, bin_tars))
10269
.await
10370
.unwrap();

src/dfx/src/actors/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use anyhow::Context;
88
use dfx_core::config::model::local_server_descriptor::LocalServerDescriptor;
99
use dfx_core::config::model::replica_config::ReplicaConfig;
1010
use fn_error_context::context;
11-
use pocketic::BitcoinIntegrationConfig;
1211
use post_start::PostStart;
1312
use std::path::PathBuf;
1413

@@ -47,19 +46,12 @@ pub fn start_pocketic_actor(
4746
)
4847
})?;
4948

50-
let bitcoin_integration_config = if local_server_descriptor.bitcoin.enabled {
51-
Some(BitcoinIntegrationConfig {
52-
canister_init_arg: local_server_descriptor.bitcoin.canister_init_arg.clone(),
53-
})
54-
} else {
55-
None
56-
};
5749
let actor_config = pocketic::Config {
5850
pocketic_path,
5951
effective_config_path: local_server_descriptor.effective_config_path(),
6052
replica_config,
6153
bitcoind_addr: local_server_descriptor.bitcoin.nodes.clone(),
62-
bitcoin_integration_config,
54+
enable_bitcoin: local_server_descriptor.bitcoin.enabled,
6355
port: local_server_descriptor.replica.port,
6456
port_file: pocketic_port_path,
6557
pid_file: local_server_descriptor.pocketic_pid_path(),

src/dfx/src/actors/pocketic.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ use crate::actors::shutdown_controller::signals::outbound::Shutdown;
88
use crate::lib::error::{DfxError, DfxResult};
99
#[cfg(unix)]
1010
use crate::lib::info::replica_rev;
11-
#[cfg(unix)]
12-
use crate::lib::integrations::bitcoin::initialize_bitcoin_canister;
13-
#[cfg(unix)]
14-
use crate::lib::integrations::create_integrations_agent;
1511
use actix::{
1612
Actor, ActorContext, ActorFutureExt, Addr, AsyncContext, Context, Handler, Recipient,
1713
ResponseActFuture, Running, WrapFuture,
@@ -58,7 +54,7 @@ pub struct Config {
5854
pub effective_config_path: PathBuf,
5955
pub replica_config: ReplicaConfig,
6056
pub bitcoind_addr: Option<Vec<SocketAddr>>,
61-
pub bitcoin_integration_config: Option<BitcoinIntegrationConfig>,
57+
pub enable_bitcoin: bool,
6258
pub port: Option<u16>,
6359
pub port_file: PathBuf,
6460
pub pid_file: PathBuf,
@@ -67,11 +63,6 @@ pub struct Config {
6763
pub pocketic_proxy_config: PocketIcProxyConfig,
6864
}
6965

70-
#[derive(Clone)]
71-
pub struct BitcoinIntegrationConfig {
72-
pub canister_init_arg: String,
73-
}
74-
7566
/// A PocketIC actor. Starts the server, can subscribe to a Ready signal and a
7667
/// Killed signal.
7768
/// This starts a thread that monitors the process and send signals to any subscriber
@@ -287,7 +278,7 @@ fn pocketic_start_thread(
287278
port,
288279
&config.effective_config_path,
289280
&config.bitcoind_addr,
290-
&config.bitcoin_integration_config,
281+
config.enable_bitcoin,
291282
&config.replica_config,
292283
config.pocketic_proxy_config.domains.clone(),
293284
config.pocketic_proxy_config.bind,
@@ -350,7 +341,7 @@ async fn initialize_pocketic(
350341
port: u16,
351342
effective_config_path: &Path,
352343
bitcoind_addr: &Option<Vec<SocketAddr>>,
353-
bitcoin_integration_config: &Option<BitcoinIntegrationConfig>,
344+
enable_bitcoin: bool,
354345
replica_config: &ReplicaConfig,
355346
domains: Option<Vec<String>>,
356347
addr: SocketAddr,
@@ -383,10 +374,11 @@ async fn initialize_pocketic(
383374
}
384375
}
385376

377+
let icp_features = IcpFeatures::default();
386378
let icp_features = if replica_config.system_canisters {
387379
// Explicitly enabling specific system canisters here
388380
// ensures we'll notice if pocket-ic adds support for additional ones
389-
Some(IcpFeatures {
381+
IcpFeatures {
390382
registry: Some(IcpFeaturesConfig::default()),
391383
cycles_minting: Some(IcpFeaturesConfig::default()),
392384
icp_token: Some(IcpFeaturesConfig::default()),
@@ -395,10 +387,18 @@ async fn initialize_pocketic(
395387
sns: Some(IcpFeaturesConfig::default()),
396388
ii: Some(IcpFeaturesConfig::default()),
397389
nns_ui: Some(IcpFeaturesConfig::default()),
398-
bitcoin: None,
399-
})
390+
bitcoin: icp_features.bitcoin,
391+
}
392+
} else {
393+
icp_features
394+
};
395+
let icp_features = if bitcoind_addr.is_some() || enable_bitcoin {
396+
IcpFeatures {
397+
bitcoin: Some(IcpFeaturesConfig::default()),
398+
..icp_features
399+
}
400400
} else {
401-
None
401+
icp_features
402402
};
403403

404404
let resp = init_client
@@ -412,7 +412,7 @@ async fn initialize_pocketic(
412412
}),
413413
log_level: Some(replica_config.log_level.to_pocketic_string()),
414414
bitcoind_addr: bitcoind_addr.clone(),
415-
icp_features,
415+
icp_features: Some(icp_features),
416416
http_gateway_config: Some(InstanceHttpGatewayConfig {
417417
ip_addr: Some(addr.ip().to_string()),
418418
port: Some(addr.port()),
@@ -455,11 +455,6 @@ async fn initialize_pocketic(
455455
debug!(logger, "Waiting for replica to report healthy status");
456456
crate::lib::replica::status::ping_and_wait(&agent_url).await?;
457457

458-
if let Some(bitcoin_integration_config) = bitcoin_integration_config {
459-
let agent = create_integrations_agent(&agent_url, &logger).await?;
460-
initialize_bitcoin_canister(&agent, &logger, bitcoin_integration_config.clone()).await?;
461-
}
462-
463458
debug!(logger, "Initialized PocketIC with gateway.");
464459
Ok(server_instance)
465460
}
@@ -469,7 +464,7 @@ fn initialize_pocketic(
469464
_: u16,
470465
_: &Path,
471466
_: &Option<Vec<SocketAddr>>,
472-
_: &Option<BitcoinIntegrationConfig>,
467+
_: bool,
473468
_: &ReplicaConfig,
474469
_: Option<Vec<String>>,
475470
_: SocketAddr,

src/dfx/src/commands/canister/logs.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ struct FilterOpts {
5151
last_idx: Option<u64>,
5252
}
5353

54-
fn filter_canister_logs<'a>(
55-
logs: &'a FetchCanisterLogsResult,
56-
opts: FilterOpts,
57-
) -> &'a [CanisterLogRecord] {
54+
fn filter_canister_logs(logs: &FetchCanisterLogsResult, opts: FilterOpts) -> &[CanisterLogRecord] {
5855
if let Some(number) = opts.tail {
5956
&logs.canister_log_records[logs
6057
.canister_log_records

0 commit comments

Comments
 (0)