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

[script] Add method count_sigops #1890

Merged
merged 1 commit into from Jun 4, 2023

Conversation

junderw
Copy link
Contributor

@junderw junderw commented Jun 1, 2023

Planning to also add methods for the various parts of Transaction etc. to eventually allow for easier sigops calculation.

Bare multisig is making a comeback, which is causing a large amount of transactions' effective vSizes (for fee calculation) to be dependent on the sigop count.

This is a first step at making those transactions easier to estimate fees for / template blocks for etc.

@junderw
Copy link
Contributor Author

junderw commented Jun 1, 2023

A preview of what's to come:

junderw/rust-bitcoin@feat/getsigopcount...feat/wip-sigop-tx

This is very rough, and I'm assuming it will need to be behind the consensus flag and needs tests... but this is a rough WIP idea of where I'm trying to go with this.

Eventually, we want Esplora to return sigop based vSize as well (if it's higher).

But for now (this PR) I'm putting it off until we discuss here.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Concept ACK

bitcoin/src/blockdata/script/borrowed.rs Outdated Show resolved Hide resolved
bitcoin/src/blockdata/script/borrowed.rs Outdated Show resolved Hide resolved
bitcoin/src/blockdata/script/borrowed.rs Outdated Show resolved Hide resolved
bitcoin/src/blockdata/script/borrowed.rs Outdated Show resolved Hide resolved
@junderw
Copy link
Contributor Author

junderw commented Jun 1, 2023

Continuing on the thread of things that aren't rust-like, perhaps we should make two methods, get_sigop_count and get_sigop_count_legacy which used accurate = true and false respectively.

Either that or create a bool-enum that's more descriptive, like Accurate, Legacy... any thoughts?

@apoelstra
Copy link
Member

I'd prefer two methods to an enum, but I don't feel strongly.

tcharding
tcharding previously approved these changes Jun 2, 2023
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Its no biggy but I'd prefer it all in one patch because later patches change earlier patches. I added a rustdoc suggestion to test for off-by-one errors.

bitcoin/src/blockdata/opcodes.rs Outdated Show resolved Hide resolved
@tcharding
Copy link
Member

Now we definitely want a single commit, this is going to be annoying for others to review :)

@junderw
Copy link
Contributor Author

junderw commented Jun 2, 2023

Done.

@tcharding
Copy link
Member

hmmm, I don't really like the co-authored-by tag but because you put it in it forced me to look a lot closer at the code so I guess that's a win. (All I did was give some review suggestions so I totally don't need attribution, but thanks for the thought.)

To the best of my knowledge this PR mirrors the behavior in Core CScript::GetSigOpCount.

ACK 85e4672

@junderw
Copy link
Contributor Author

junderw commented Jun 2, 2023

I think I just invented a new underhanded way to get a review! hahahahahah /s

@Kixunil
Copy link
Collaborator

Kixunil commented Jun 2, 2023

I like changing it to two methods, I was thinking about it before but forgot to mention it. Bit more bikeshedding: in Rust we tend to not use the get_ prefix, so maybe get rid of it? And maybe even rename the method to count_sigops to signal this has linear complexity?

(Also @tcharding you forgot to hit approve)

@junderw
Copy link
Contributor Author

junderw commented Jun 2, 2023

  1. Made the name change. (I agree, the count_sigops name is better)
  2. Removed @tcharding as Co-author. Thanks for your suggestion on the doctest!
  3. Force pushed. (You can see the diff here)

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 638445f

Can be improved in a followup PR.

bitcoin/src/blockdata/script/borrowed.rs Show resolved Hide resolved
bitcoin/src/blockdata/script/borrowed.rs Show resolved Hide resolved
bitcoin/src/blockdata/opcodes.rs Show resolved Hide resolved
@junderw junderw mentioned this pull request Jun 2, 2023
@junderw
Copy link
Contributor Author

junderw commented Jun 2, 2023

Follow up PR started here: 24a3352

Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

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

ACK 638445f

@apoelstra apoelstra merged commit 1a1fe0e into rust-bitcoin:master Jun 4, 2023
58 checks passed
@sanket1729
Copy link
Member

post merge ACK 1a1fe0e. Double checked with bitcoin core source.

apoelstra added a commit that referenced this pull request Jun 5, 2023
d961b9c Fix minor comments on count_sigops PR (junderw)

Pull request description:

  Fixing some comments that were left on #1890

ACKs for top commit:
  yancyribbens:
    ACK d961b9c
  apoelstra:
    ACK d961b9c
  tcharding:
    ACK d961b9c

Tree-SHA512: caa04428eb7c09915964e4a7bae2d1fca2426317f3620d16e73e992269a99d7adb3d360affb954a173835661a9960cf760d29ae9861816b1a898c01428b0f2d6
@tcharding tcharding changed the title [script] Add method get_sigop_count [script] Add method count_sigops Jun 29, 2023
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

Successfully merging this pull request may close these issues.

None yet

6 participants