Skip to content

Commit

Permalink
Forbid prioritizing a spend if...
Browse files Browse the repository at this point in the history
...the cpfp key is missing
  • Loading branch information
danielabrozzoni committed Nov 3, 2021
1 parent c6f0fd7 commit 95c0c76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/daemon/jsonrpc/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,15 @@ impl RpcApi for RpcImpl {
let revaultd = meta.rpc_utils.revaultd.read().unwrap();
let db_path = revaultd.db_file();

if revaultd.cpfp_key.is_none() {
return Err(JsonRpcError::invalid_params(
"Can't read the cpfp key. \
Make sure you have a file called cpfp_secret containing \
the private key in your datadir"
.to_string(),
));
}

// Get the referenced Spend and the vaults it spends from the DB
let mut spend_tx = db_spend_transaction(&db_path, &spend_txid)
.map_err(|e| Error::from(e))?
Expand Down
19 changes: 19 additions & 0 deletions tests/test_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,3 +1141,22 @@ def test_getserverstatus(revault_network, bitcoind):
assert not cosigner["reachable"]
# Sadly we don't persist the cosigner ports
assert cosigner["host"].startswith("127.0.0.1:")


@pytest.mark.skipif(not POSTGRES_IS_SETUP, reason="Needs Postgres for servers db")
def test_setspendtx_cpfp_not_enabled(revault_network, bitcoind):
CSV = 12
revault_network.deploy(2, 1, n_stkmanagers=1, csv=CSV, cpfp_enabled=False)
man = revault_network.mans()[1]
stks = revault_network.stks()
amount = 0.24
vault = revault_network.fund(amount)
deposit = f"{vault['txid']}:{vault['vout']}"

revault_network.secure_vault(vault)
revault_network.activate_vault(vault)
with pytest.raises(
RpcError,
match="Can't read the cpfp key",
):
revault_network.unvault_vaults_anyhow_unconfirmed([vault], priority=True)

0 comments on commit 95c0c76

Please sign in to comment.