Skip to content

Conversation

@harding
Copy link
Collaborator

@harding harding commented Jan 16, 2020

This adds a crude Javascript-based transaction size calculator to /en/tools/calc-size/. No links are added to the tool from other parts of the site and I'm not sure we should add any unless the tool is improved.

However, I've found it good enough for my own use and I think it might help y'all when you're burdened with verifying my transaction size math in newsletter and workbook content. Future improvements can let it deal with a wider range of multisig variations, differing types of input and output scripts, non-keypath P2TR, uncompressed pubkeys, low-R signatures, LN onchain scripts, and other common transaction types.

That said, if you don't think this is a good fit for the Optech website, let me know and I can easily host it somewhere else.

@jnewbery
Copy link
Contributor

I think it's fine to add this. I also agree that we shouldn't link to it until it's a bit more polished.

One thing that I'd like to see added is documentation on how the values are calculated.

@harding
Copy link
Collaborator Author

harding commented Jan 21, 2020

One thing that I'd like to see added is documentation on how the values are calculated.

I don't understand this. Is this more code documentation (I thought that was ok), more description about what fields are included in a transaction in the HTML output, or something else?

@jnewbery
Copy link
Contributor

I don't understand this. Is this more code documentation (I thought that was ok), more description about what fields are included in a transaction in the HTML output, or something else?

More description in the html about how the values are calculated.

Copy link
Contributor

@bitschmidty bitschmidty left a comment

Choose a reason for hiding this comment

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

tACK

Cool tool! Left a couple suggestion.

@harding harding force-pushed the 2020-01-tx-size-calculator branch from 2ea75d6 to 9567b7b Compare January 27, 2020 17:18
@harding
Copy link
Collaborator Author

harding commented Jan 27, 2020

Forced push, hopefully addressing all comments (including providing more information about how the values are calculated). Thanks for the reviews, @jnewbery and @bitschmidty!

Copy link
Contributor

@bitschmidty bitschmidty left a comment

Choose a reason for hiding this comment

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

@harding I think the legend is really informational. Im also using the table calcs in a presentation right now!

Resolved previous comments and added a few new ones.

Copy link
Contributor

@0xB10C 0xB10C left a comment

Choose a reason for hiding this comment

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

I like this.


<br>
Number of inputs: <input type="number" id="inputs" value="1" onchange="calculateTotal()"/><br>
Number of outputs: <input type="number" id="outputs" value="2" onchange="calculateTotal()"/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Both HTML form inputs could do with a min=0 attribute.

image

Comment on lines +272 to +309
// TODO: maybe allow the input type to be different from the output
// type, or multiple inputs of different types (or multiple
// outputs of different types)
Copy link
Contributor

Choose a reason for hiding this comment

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

That would be cool! I might do a follow up PR that adds this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That'd be great! Also having someone work on this who actually knows JS would probably be very beneficial. :-)

@harding harding force-pushed the 2020-01-tx-size-calculator branch 2 times, most recently from e8ba382 to 0bbfd33 Compare February 8, 2020 01:31
@harding
Copy link
Collaborator Author

harding commented Feb 8, 2020

Force pushed some edits:

  • Hopefully resolved @bitschmidty's editing feedback
  • added min="1" to input and output count form fields (@0xB10C suggested min=0, but since consensus rules require all transactions contain at least one input and one output, I decided to use a minimum of 1)
  • Separated the size calculation logic function from the HTML presentation function
  • Added some crude semi-automated testing to verify the form is generating accurate results. I only tested the default 1-in, 2-out cases; linking each of them (except P2WSH) to an actual transaction on the block chain. This revealed two minor errors, which I corrected:
    • P2SH 2-of-3 was off by 2 vbytes because its scriptSig field size uses a 3-byte compactSize uint instead of the 1-byte uint I expected
    • P2WSH 2-of-3 was off by 0.25 vbytes because I forgot to include the size of the witnessScript field in the calculation (which would've been obvious if I read my own documentation on the page). Additionally, using a quick scan of blocks 600,000 to 601,000, I was unable to find a P2WSH 2-of-3 transaction with 1-in, 2-outs that used 72 byte signatures for both of its sigs, so I don't have a txid reference for that. However, I'm sure it's correct based on a mixed 71/72 byte signature transaction I checked.
  • I also disabled breadcrumbs for this page because it wants to link to an /en/tools/ page that doesn't exist. Obviously we can add that page later if we want to publicize this

@harding
Copy link
Collaborator Author

harding commented Feb 8, 2020

P2SH 2-of-3 was off by 2 vbytes because its scriptSig field size uses a 3-byte compactSize uint instead of the 1-byte uint I expected

Oh, perhaps worth a dorky note, I think that if at least one signature both signatures for P2SH 2-of-3 use low-R (and all pubkeys are compressed), then this can be a 1-byte compactSize uint. Obviously, anyone who cares about space savings should be using P2WSH instead, but it might be worth a footnote in the scaling workbook or somewhere else that using low-R sigs can save you up to 4 vbytes here instead of just the expected 2 vbytes. 🤓

@harding harding force-pushed the 2020-01-tx-size-calculator branch from 0bbfd33 to 6d0712c Compare February 8, 2020 16:37
@bitschmidty
Copy link
Contributor

tACK 6d0712c (Chrome, Safari, Firefox on macOS)

@jnewbery jnewbery added book Scaling book website General website changes and maintenance labels Feb 13, 2020
Copy link
Contributor

@0xB10C 0xB10C left a comment

Choose a reason for hiding this comment

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

tAck 6d0712c

  • tested in Firefox, Chrome and Chromium
  • looked over the size definitions
  • checked for dead links (automatically)

@harding harding force-pushed the 2020-01-tx-size-calculator branch from 6d0712c to d5d75cd Compare February 14, 2020 10:58
@harding
Copy link
Collaborator Author

harding commented Feb 14, 2020

Pushed a single line edit to make the P2WSH 2-of-3 witness example more accurate and less confusing.

@harding harding force-pushed the 2020-01-tx-size-calculator branch from d5d75cd to a4b46e9 Compare February 14, 2020 11:01
@jnewbery jnewbery merged commit 0453ca4 into bitcoinops:master Feb 14, 2020
@jnewbery
Copy link
Contributor

Looks great. Thanks Dave!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

book Scaling book website General website changes and maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants