Skip to content

Expose txinwitness for coinbase in JSON form from RPC#18826

Merged
maflcko merged 2 commits intobitcoin:masterfrom
rvagg:rvagg/txinwitness-for-coinbase
Jun 8, 2020
Merged

Expose txinwitness for coinbase in JSON form from RPC#18826
maflcko merged 2 commits intobitcoin:masterfrom
rvagg:rvagg/txinwitness-for-coinbase

Conversation

@rvagg
Copy link
Copy Markdown
Contributor

@rvagg rvagg commented Apr 30, 2020

Rationale

The CLI can provide you with everything about transactions and blocks that you need to reconstruct the block structure and raw block itself except for the witness commitment nonce which is stored in the scriptWitness of the coinbase and is not printed. You could manually parse the raw "hex" fields for transactions if you really wanted to, but this seems to defeat the point of having a JSONification of the raw block/transaction data.

Without the nonce you can't:

  1. calculate and validate the witness commitment yourself, you can generate the witness tx merkle root but you don't have the nonce to combine it with
  2. reconstruct the raw block form because you don't have scriptWitness stack associated with the coinbase (although you know how big it will be and can guess the common case of [0x000...000])

I'm building some archiving tooling for block data and being able to do a validated two-way conversion is very helpful.

What

This PR simply makes the txinwitness field not dependent on whether we are working with the coinbase or not. So you get it for the coinbase as well as the rest.

Examples

Common case of a [0x000...000] nonce: 00000000000000000000140a7289f3aada855dfd23b0bb13bb5502b0ca60cdd7

      "vin": [
        {
          "coinbase": "0368890904c1fe8d5e2f706f6f6c696e2e636f6d2ffabe6d6d5565843a681160cf7b08b1b74ac90a719e6d6ab28c16d336b924f0dc2fcabdc6010000000000000051bf2ad74af345dbe642154b2658931612a70d195e007add0100ffffffff",
          "txinwitness": [
            "0000000000000000000000000000000000000000000000000000000000000000"
          ],
          "sequence": 4294967295
        }
      ],
...

Novel nonce value: 000000000000000000008c31945b2012258366cc600a3e9a3ee0598e8f797731

      "vin": [
        {
          "coinbase": "031862082cfabe6d6d80c099b5e21f4c186d54eb292e17026932e52b1b807fa1380574c5adc1c843450200000000000000",
          "txinwitness": [
            "5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d"
          ],
          "sequence": 4294967295
        }
      ],
...

Alternatives

This field could be renamed for the coinbase, "witnessnonce" perhaps. It could also be omitted when null/zero (0x000...000).

Tests

This didn't break any tests and I couldn't find an obvious way to include a test for this. If this is desired I'd apreicate some pointers.

@DrahtBot
Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@brakmic
Copy link
Copy Markdown
Contributor

brakmic commented May 1, 2020

ACK 2a52c3c4caaf8dbe5c3d406c2fc7b1fd4347d0fd

Built, run and tested on macOS Catalina 10.15.4

Regarding functional tests, I'd recommend to expand wallet_basic.py.
You could, for example, add to the end of run_test method the following lines:

witnesses = tx["decoded"]["vin"][0]['txinwitness']
for witness in witnesses:
    assert_is_hex_string(witness)

Copy link
Copy Markdown
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update some test with the new field.

@rvagg
Copy link
Copy Markdown
Contributor Author

rvagg commented May 4, 2020

OK, I figured out how to get it wired up into the functional tests, see latest commit exercising this new field successfully. Thanks @brakmic & @promag, PTAL.

@brakmic
Copy link
Copy Markdown
Contributor

brakmic commented May 4, 2020

Re-ACK 3a20ee8a1c0f86fb7628240f144d02fb6a32022d

@luke-jr
Copy link
Copy Markdown
Member

luke-jr commented May 4, 2020

utACK

Copy link
Copy Markdown
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, just a nit on the test

@rvagg
Copy link
Copy Markdown
Contributor Author

rvagg commented May 5, 2020

Moved to feature_segwit.py as suggested. It's a more logical place for it to be, but there's not really anything else in there testing anything similar so it doesn't seem perfectly in place. But perhaps that's just a matter of increasing the coverage in general.

rvagg added 2 commits May 8, 2020 12:19
txinwitness is used as the witness commitment nonce so is necessary if
reconstructing block data from RPC data.
@rvagg rvagg force-pushed the rvagg/txinwitness-for-coinbase branch from 959a17d to 34645c4 Compare May 8, 2020 02:20
@rvagg
Copy link
Copy Markdown
Contributor Author

rvagg commented May 8, 2020

Squashed the fixups and rebased to master, I think there was a rebasing problem previously and I ended up with stray commits. It should just be the two commits in here now and should be ready for landing if there are no further suggestions or objections.

@maflcko
Copy link
Copy Markdown
Member

maflcko commented May 8, 2020

ACK 34645c4

@rvagg
Copy link
Copy Markdown
Contributor Author

rvagg commented May 27, 2020

Wondering what the process is for getting things merged in this project? This is not super urgent but it'd be nice to know if it's in a process and not going to get lost.

@maflcko
Copy link
Copy Markdown
Member

maflcko commented May 27, 2020

@rvagg There is a very loose process described in CONTRIBUTING.md

I was hoping that someone else reviews this, because it is a relatively easy rpc change. If no one else reviews it, I will merge it at some point because it is a clear improvement.

@maflcko maflcko merged commit 297466b into bitcoin:master Jun 8, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 8, 2020
…m RPC

34645c4 Test txinwitness is accessible on coinbase vin (Rod Vagg)
3e44210 Expose txinwitness for coinbase in JSON form (Rod Vagg)

Pull request description:

  ## Rationale

  The CLI can provide you with everything about transactions and blocks that you need to reconstruct the block structure and raw block itself **except** for the witness commitment nonce which is stored in the `scriptWitness` of the coinbase and is not printed. You could manually parse the raw `"hex"` fields for transactions if you really wanted to, but this seems to defeat the point of having a JSONification of the raw block/transaction data.

  Without the nonce you can't:

  1. calculate and validate the witness commitment yourself, you can generate the witness tx merkle root but you don't have the nonce to combine it with
  2. reconstruct the raw block form because you don't have `scriptWitness` stack associated with the coinbase (although you know how big it will be and can guess the common case of `[0x000...000]`)

  I'm building some archiving tooling for block data and being able to do a validated two-way conversion is very helpful.

  ## What

  This PR simply makes the `txinwitness` field not dependent on whether we are working with the coinbase or not. So you get it for the coinbase as well as the rest.

  ## Examples

  Common case of a `[0x000...000]` nonce: 00000000000000000000140a7289f3aada855dfd23b0bb13bb5502b0ca60cdd7

  ```json
        "vin": [
          {
            "coinbase": "0368890904c1fe8d5e2f706f6f6c696e2e636f6d2ffabe6d6d5565843a681160cf7b08b1b74ac90a719e6d6ab28c16d336b924f0dc2fcabdc6010000000000000051bf2ad74af345dbe642154b2658931612a70d195e007add0100ffffffff",
            "txinwitness": [
              "0000000000000000000000000000000000000000000000000000000000000000"
            ],
            "sequence": 4294967295
          }
        ],
  ...
  ```

  Novel nonce value: 000000000000000000008c31945b2012258366cc600a3e9a3ee0598e8f797731

  ```json
        "vin": [
          {
            "coinbase": "031862082cfabe6d6d80c099b5e21f4c186d54eb292e17026932e52b1b807fa1380574c5adc1c843450200000000000000",
            "txinwitness": [
              "5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d5b5032506f6f6c5d"
            ],
            "sequence": 4294967295
          }
        ],
  ...
  ```

  ## Alternatives

  This field could be renamed for the coinbase, `"witnessnonce"` perhaps. It could also be omitted when null/zero (`0x000...000`).

  ## Tests

  This didn't break any tests and I couldn't find an obvious way to include a test for this. If this is desired I'd apreicate some pointers.

ACKs for top commit:
  MarcoFalke:
    ACK 34645c4

Tree-SHA512: b192facc1dfd210a5ec3f0d5d1ac6d0cae81eb35be15eaa71f60009a538dd6a79ab396f218434e7e998563f7f0df2c396cc925cb91619f6841c5a67806148c85
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants