Repository navigation
bitcoin: add sign-only and getrawtransaction RPCs - #279
Conversation
| let signed = self | ||
| .sign_raw_transaction_with_wallet(tx) | ||
| .inspect_err(|stderr| { | ||
| log::debug!("bitcoin-cli signrawtransactionwithwallet failed: {stderr}"); |
There was a problem hiding this comment.
Under what circumstances would we expect an error?
Should we still panic for errors that are unexpected?
There was a problem hiding this comment.
It only makes sense for the interactive-tx. Since the fuzzer and target might build invalid transactions that we can't sign. E.g a transaction without any input.
There was a problem hiding this comment.
I asked Claude under what circumstances signrawtransactionwithwallet can return an error, and it gave me this table.
┌─────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────┐
│ Error │ Can smite hit it? │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ GetWalletForJSONRPCRequest: no wallet │ │
│ loaded, or several loaded without │ Only if the environment is broken │
│ -rpcwallet │ │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ DecodeHexTx fails ("TX decode failed. Make │ Only with zero inputs. rust-bitcoin always produces a valid serialization; │
│ sure the tx has at least one input.") │ with zero inputs it adds a segwit marker but no witnesses, which Core │
│ │ rejects as "Superfluous witness record" │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ EnsureWalletIsUnlocked │ No, the wallet isn't encrypted │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ ParsePrevouts / ParseSighashString │ No, smite passes neither argument │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ "Missing amount" (the one per-input error │ No. It needs amount == MAX_MONEY, which only happens when prevtxs is passed │
│ that becomes an RPC error) │ without an amount (rawtransaction_util.cpp:244) │
├─────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────┤
│ bitcoind down, still starting up, or │ Only if the environment is broken │
│ failing auth │ │
└─────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘
The only one I can imagine us hitting is "zero inputs". But even then it seems like something we shouldn't ever hit unless there's a bug in smite.
- splicing always has the funding input
- for dual funding smite should only ever do the RPC if it added its own input, otherwise there's no reason to sign. And if the target allowed this, it seems like a bug we should detect and report early, before we ever try to sign.
There was a problem hiding this comment.
Makes sense. We can check it before calling the RPC. I've updated the code to panic.
3feef63 to
5ad1310
Compare
Lets a sign-only caller that does not require complete signing reuse it.
Channel establishment v2 needs our own witnesses for tx_signatures, which the wallet can only produce as a partial signing of the shared transaction.
Channel establishment v2 needs the previous transaction bytes for tx_add_input's prevtx.
5ad1310 to
88b50f1
Compare
Channel establishment v2 needs the previous transaction bytes for
tx_add_inputand our own witnesses fortx_signatures, which the wallet can only produce as a partial signing of the shared transaction.This is part of breaking down PR #239 into smaller PRs to make them easier to review.