Add weight utilities to TxIn and TxOut#1467
Conversation
|
Heads up (though CI will flag I'm sure) that this doesn't compile with 1.41.0: otherwise d758074a8f583cd722f8b02deb0958789ea4a97f look good. |
|
Pardon my ignorance, but what is the use of Is this about the one byte flag whether the tx contains witnesses or not? |
|
@sanket1729 it's the weird reported to pre-segwit nodes ... which, okay, there's an argument that we don't really care about pre-segwit nodes 6 years after Segwit activation, but that's the value. |
|
Do we know someone who actually uses it? If not, I'd just drop it for now and add when someone asks. |
bitcoin/src/blockdata/transaction.rs
Outdated
There was a problem hiding this comment.
If this is not called min_segwit_weight (why?) it should have a well-visible warning that it doesn't account for varint changing so naive sum wouldn't work.
Also I recently found out that Core has FeeRate type but we don't which feels ridiculous. I obviously don't ask you to add it just a note.
There was a problem hiding this comment.
Right! I just added a warning to the docs, let me know how you feel about it :)
+ /// Keep in mind that when adding a TxIn to a transaction, the total weight of the transaction
+ /// might increase more than `TxIn::segwit_weight`. This happens when:
+ /// - the new input added causes the input length `VarInt` to increase its encoding length
+ /// - the new input is the first segwit input added - this will add an additional 2WU to the
+ /// transaction weight to take into account the segwit markerd758074 to
a3ca7e8
Compare
Updated, thanks!
This is needed for rust-bitcoin/rust-miniscript#476 :)
Yes, and also the correct weight of non-segwit inputs when included in non-segwit transactions, since the |
apoelstra
left a comment
There was a problem hiding this comment.
ACK a3ca7e8e51f8dc00eb41803b1e4be82310ca5a78
- Add `segwit_weight` and `legacy_weight` methods to `TxIn` - Add `weight` method to `TxOut`
a3ca7e8 to
6d51e92
Compare
|
The new docs look great. Though I really wish there were a way to compute transaction weight without these footguns :/. Maybe we could have a method on |
Kixunil
left a comment
There was a problem hiding this comment.
The doc looks great.
I guess you missed my question about naming. I think naming it min_legacy_weight, min_segwit_weight and min_weight would make the potential foot gun more visible in the code. Is there some reason why the min_ prefix is undesirable?
| /// might increase more than `TxIn::segwit_weight`. This happens when: | ||
| /// - the new input added causes the input length `VarInt` to increase its encoding length | ||
| /// - the new input is the first segwit input added - this will add an additional 2WU to the | ||
| /// transaction weight to take into account the segwit marker |
There was a problem hiding this comment.
Shouldn't there be two more spaces for the line to be counted towards the bullet point?
There was a problem hiding this comment.
Btw, cargo doc renders this just fine:
But I agree that it should be fixed for the people reading the docs in the files itself, I'll do it as a part of #828. Do you think there are enough typos to fix it immediately, or should I wait a bit longer?
There was a problem hiding this comment.
Oh, interesting, I didn't expect that. That decreases the severity quite a bit. If you feel like doing whole #828 sure, go ahead.
|
@apoelstra I was thinking about it too and I envision something like this: /// Predicts the transaction weight without knowing the exact data of the transaction if the weights of inputs/outputs are known.
///
/// This is mainly useful when constructing the transaction before signing since signing data is not known but if one knows which
/// spending conditions are used their sizes may be known an can be used to compute the total size of the transaction.
pub fn predict_transaction_weight(inputs: impl IntoIterator<Item=InputWeightInfo>, outputs: implIterator<Weight>) -> Weight {
// ...
}
pub struct InputWeightInfo {
pub script_sig: Weight,
pub witness: Weight,
} |
|
+1 to adding _min to the names -- sorry, I forgot about this suggestion too. |
Ops, sorry! |
|
I don't think the For the same reasoning, should we use |
|
Yeah, these are good arguments. |
|
Yeah, good points. |
|
Sure, I'm afk now, but I'll fix asap!
…-------- Original Message --------
On Dec 15, 2022, 19:15, Martin Habovštiak wrote:
@Kixunil approved this pull request.
ACK [6d51e92](6d51e92)
But please consider fixing the doc formatting in a subsequent PR.
—
Reply to this email directly, [view it on GitHub](#1467 (review)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AF7B4KJ5Z55JCSJVRUK4SDLWNNN5HANCNFSM6AAAAAAS47XNMU).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|

segwit_weightandlegacy_weightmethods toTxInweightmethod toTxOut