Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Computing witness lengths of a TxIn #2659

Open
yancyribbens opened this issue Apr 5, 2024 · 5 comments
Open

Computing witness lengths of a TxIn #2659

yancyribbens opened this issue Apr 5, 2024 · 5 comments

Comments

@yancyribbens
Copy link
Contributor

To use the constructor for InputWeightPrediction, the input_script_len and witness_element_lengths is needed. Given a TxIn and accessing the Witness field, is it possible to compute the witness_element_lengths?

For example:

    #[test]
    fn tx_in_weight_predict() {
        let tx_in = TxIn::default();
        let input_script_len = tx_in.script_sig.len();
        let witness_element_lengths = tx_in.witness.witness_element_lengths; // how to compute?
        let i = InputWeightPrediction::new(input_script_len, witness_element_lengths);
    }

The Witness struct has content and witness_elements (which are private) but not witness_element_lengths from what I can tell..

@sanket1729
Copy link
Member

sanket1729 commented Apr 5, 2024

As discussed in rust-minsicript issue, you need a descriptor to do this. rust-bitcoin/rust-miniscript#675 (comment)

@apoelstra
Copy link
Member

If the witness is already populated then Witness::size gives you this.

@yancyribbens
Copy link
Contributor Author

If the witness is already populated then Witness::size gives you this.

@apoelstra thanks, although my confusion is that The Witness size method returns a usize, while PredictIntputWeight constructor requires something that can be iterable. I mean size() could just be shoved into a vec but that doesn't feel like the intent.

@sanket1729
Copy link
Member

In most/all cases we never know the exact witness before using PredictInputWeight, thus descriptors. I am somewhat confused with this flow. There are several constants P2PKH_MAX and more that help more most common use cases. For other use-cases involving script hash, you need some information about the descriptor and the spend path that you plan to use.

@yancyribbens
Copy link
Contributor Author

In most/all cases we never know the exact witness before using PredictInputWeight, thus descriptors. I am somewhat confused with this flow. There are several constants P2PKH_MAX and more that help more most common use cases. For other use-cases involving script hash, you need some information about the descriptor and the spend path that you plan to use.

@sanket1729 hmm ok. I'll take a look at how to incorporate descriptors. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants