Skip to content

Commit

Permalink
Merge pull request #3821 from elsirion/2023-12-single-guardian-p2wkh
Browse files Browse the repository at this point in the history
feat(wallet): special-case descriptor for single-guardian instances
  • Loading branch information
elsirion committed Dec 5, 2023
2 parents a8e6bd8 + 5b9c5ac commit bb0b06e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 4 deletions.
15 changes: 15 additions & 0 deletions devimint/src/main.rs
Expand Up @@ -354,6 +354,21 @@ async fn cli_tests(dev_fed: DevFed) -> Result<()> {
.state();
anyhow::ensure!(invoice_status == tonic_lnd::lnrpc::invoice::InvoiceState::Settled);

// # Test the correct descriptor is used
let config = cmd!(fed, "config").out_json().await?;
let guardian_count = config["global"]["api_endpoints"].as_object().unwrap().len();
let descriptor = config["modules"]["2"]["peg_in_descriptor"]
.as_str()
.unwrap()
.to_owned();

info!("Testing generated descriptor for {guardian_count} guardian federation");
if guardian_count == 1 {
assert!(descriptor.contains("wpkh("));
} else {
assert!(descriptor.contains("wsh(sortedmulti("));
}

// # Client tests
info!("Testing Client");
// ## reissue e-cash
Expand Down
20 changes: 16 additions & 4 deletions modules/fedimint-wallet-common/src/config.rs
Expand Up @@ -7,7 +7,7 @@ use fedimint_core::encoding::{Decodable, Encodable};
use fedimint_core::module::__reexports::serde_json;
use fedimint_core::util::SafeUrl;
use fedimint_core::{plugin_types_trait_impl_config, Feerate, PeerId};
use miniscript::descriptor::Wsh;
use miniscript::descriptor::{Wpkh, Wsh};
use secp256k1::SecretKey;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -150,9 +150,21 @@ impl WalletConfig {
bitcoin_rpc: BitcoinRpcConfig,
client_default_bitcoin_rpc: BitcoinRpcConfig,
) -> Self {
let peg_in_descriptor = PegInDescriptor::Wsh(
Wsh::new_sortedmulti(threshold, pubkeys.values().copied().collect()).unwrap(),
);
let peg_in_descriptor = if pubkeys.len() == 1 {
PegInDescriptor::Wpkh(
Wpkh::new(
*pubkeys
.values()
.next()
.expect("there is exactly one pub key"),
)
.expect("Our key type is always compressed"),
)
} else {
PegInDescriptor::Wsh(
Wsh::new_sortedmulti(threshold, pubkeys.values().copied().collect()).unwrap(),
)
};

Self {
local: WalletConfigLocal { bitcoin_rpc },
Expand Down
6 changes: 6 additions & 0 deletions nix/flakebox.nix
Expand Up @@ -338,6 +338,12 @@ rec {
buildPhaseCargoCommand = "patchShebangs ./scripts ; ./scripts/tests/devimint-cli-test.sh";
};

devimintCliTestSingle = craneLibTests.mkCargoDerivation {
pname = "${commonCliTestArgs.pname}-cli";
cargoArtifacts = workspaceBuild;
buildPhaseCargoCommand = "patchShebangs ./scripts ; ./scripts/tests/devimint-cli-test-single.sh";
};

cliLoadTestToolTest = craneLibTests.mkCargoDerivation {
pname = "${commonCliTestArgs.pname}-cli";
cargoArtifacts = workspaceBuild;
Expand Down
12 changes: 12 additions & 0 deletions scripts/tests/devimint-cli-test-single.sh
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
# Runs a CLI-based integration test

set -euo pipefail
export RUST_LOG="${RUST_LOG:-info}"

source scripts/_common.sh
build_workspace
add_target_dir_to_path
make_fm_test_marker

devimint -n 1 cli-tests
6 changes: 6 additions & 0 deletions scripts/tests/test-ci-all.sh
Expand Up @@ -63,6 +63,11 @@ function devimint_cli_test() {
}
export -f devimint_cli_test

function devimint_cli_test_single() {
fm-run-test "${FUNCNAME[0]}" ./scripts/tests/devimint-cli-test-single.sh
}
export -f devimint_cli_test_single

function load_test_tool_test() {
fm-run-test "${FUNCNAME[0]}" ./scripts/tests/load-test-tool-test.sh
}
Expand Down Expand Up @@ -126,6 +131,7 @@ if parallel \
lightning_reconnect_test \
gateway_reboot_test \
devimint_cli_test \
devimint_cli_test_single \
load_test_tool_test \
recoverytool_tests ; then
>&2 echo "All tests successful"
Expand Down

0 comments on commit bb0b06e

Please sign in to comment.