romanz / electrs

An efficient re-implementation of Electrum Server in Rust
MIT License
1.08k stars 399 forks source link

Bug: blockchain.transaction.get fails on taproot transaction #427

Closed romanz closed 3 years ago

romanz commented 3 years ago

I have sent a signet transaction using Sparrow Wallet 1.4.3 to a pay-to-taproot address tb1p6095xwqhf05uu8rcy7qtlm3eg7ppz08exwy2ka5n352frjtjznws2lnm9j.

The transaction is signed and confirmed: https://explorer.bc-2.jp/tx/8c0d675eb36bbbde2145b6cffb391afcfd1201286ef81f8fd19d641c11f43ed8

However, getting the transaction using blockchain.transaction.get fails with:

WARN  electrs::electrum] RPC blockchain.transaction.get failed: failed to get transaction info: JSON-RPC error: JSON decode error: 
unknown variant `witness_v1_taproot`, expected one of `nonstandard`, `pubkey`, `pubkeyhash`, `scripthash`, `multisig`, `nulldata`, `witness_v0_keyhash`, `witness_v0_scripthash`, `witness_unknown`
romanz commented 3 years ago
$ bitcoin-cli -signet getrawtransaction 8c0d675eb36bbbde2145b6cffb391afcfd1201286ef81f8fd19d641c11f43ed8 true 0000004139cb94ada581edd184d41a8fbe471ebcb375910b849235d37d94edbd
{
  "in_active_chain": true,
  "txid": "8c0d675eb36bbbde2145b6cffb391afcfd1201286ef81f8fd19d641c11f43ed8",
  "hash": "b1fad7628c492e7d0f86e21a5d5cdc31954ee4d42a14ef99f0b697713f6fae37",
  "version": 2,
  "size": 234,
  "vsize": 153,
  "weight": 609,
  "locktime": 46683,
  "vin": [
    {
      "txid": "850559842f3ff5120c38d8cc38f25147f3d110de28cc3dd459f3c06ca90b4d0c",
      "vout": 0,
      "scriptSig": {
        "asm": "",
        "hex": ""
      },
      "txinwitness": [
        "304402203417ce1b43f329c09456626fca073d49b2704142182fb45ee0b01d644bf8c6950220157ec78692f452041981e595e888a2f9fc7f89d0ec8e5d6ecc720df29c79523201",
        "0306746d464e749ffeb77ddc70b16496a01e942fbd7331afe7eeef3742344b7c11"
      ],
      "sequence": 4294967293
    }
  ],
  "vout": [
    {
      "value": 7.99999627,
      "n": 0,
      "scriptPubKey": {
        "asm": "0 951cd768b19793fe22557979445726592e90bc88",
        "hex": "0014951cd768b19793fe22557979445726592e90bc88",
        "address": "tb1qj5wdw693j7flugj409u5g4extyhfp0ygtpwqz6",
        "type": "witness_v0_keyhash"
      }
    },
    {
      "value": 2.00000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "1 d3cb4338174be9ce1c782780bfee394782113cf93388ab76938d1491c97214dd",
        "hex": "5120d3cb4338174be9ce1c782780bfee394782113cf93388ab76938d1491c97214dd",
        "address": "tb1p6095xwqhf05uu8rcy7qtlm3eg7ppz08exwy2ka5n352frjtjznws2lnm9j",
        "type": "witness_v1_taproot"
      }
    }
  ],
  "hex": "020000000001010c4d0ba96cc0f359d43dcc28de10d1f34751f238ccd8380c12f53f2f845905850000000000fdffffff028b06af2f00000000160014951cd768b19793fe22557979445726592e90bc8800c2eb0b00000000225120d3cb4338174be9ce1c782780bfee394782113cf93388ab76938d1491c97214dd0247304402203417ce1b43f329c09456626fca073d49b2704142182fb45ee0b01d644bf8c6950220157ec78692f452041981e595e888a2f9fc7f89d0ec8e5d6ecc720df29c79523201210306746d464e749ffeb77ddc70b16496a01e942fbd7331afe7eeef3742344b7c115bb60000",
  "blockhash": "0000004139cb94ada581edd184d41a8fbe471ebcb375910b849235d37d94edbd",
  "confirmations": 1,
  "time": 1626373240,
  "blocktime": 1626373240
}
romanz commented 3 years ago

CC: @craigraw

craigraw commented 3 years ago

Oddly enough I'm getting a slightly different error with the same call (Bitcoin Core 0.21.1, Electrs P2P latest HEAD):

WARN  electrs::electrum] RPC blockchain.transaction.get failed: failed to get transaction info: JSON-RPC error: JSON decode error: bech32: invalid checksum

I took this to being due to Rust Bitcoin not having released their bech32m support yet, which I assume will happen in 0.26.3. I'm still able to send a transaction with Taproot inputs on Sparrow though.

romanz commented 3 years ago

@craigraw Could you please test https://github.com/romanz/electrs/pull/428? It should not deserialize the resulting JSON from getrawtransaction - so it should not fail due to unsupported taproot-related types.

craigraw commented 3 years ago

Yes that works - I'm not getting any errors anymore, and verbose transaction lookups are working correctly.

romanz commented 3 years ago

Cool, thanks!

craigraw commented 3 years ago

Great - thanks for looking into this and fixing it so quickly!