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

Make SER_GETHASH implicit for CHashWriter and SerializeHash #13462

Closed
wants to merge 4 commits into from

Conversation

Empact
Copy link
Member

@Empact Empact commented Jun 13, 2018

Most invocations of CHashWriter use SER_GETHASH and version 0, this allows for eliding those values, and removes SER_GETHASH as a type, because it functions simply as "has no external destination" in practice.

SerializeHash basically existed due to the overhead of CHashWriter construction, now that that is minimized, it's unnecessary.

@Empact Empact force-pushed the serialize-hash-type branch 2 times, most recently from bfa47a8 to d697362 Compare June 13, 2018 20:52
@Empact Empact changed the title scripted-diff: Simplify common case of CHashWriter and drop SER_GETHASH scripted-diff: Simplify common case of CHashWriter and drop SER_GETHASH & SerializeHash Jun 13, 2018
src/primitives/block.cpp Outdated Show resolved Hide resolved
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 14, 2018

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24410 ([kernel 2a/n] Split hashing/index GetUTXOStats codepaths, decouple from coinstatsindex by dongcarl)
  • #24058 (BIP-322 basic support by kallewoof)

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.

@Empact
Copy link
Member Author

Empact commented Jun 14, 2018

Withdrawing this pending #10785. Will re-open after.

@Empact Empact closed this Jun 14, 2018
@sipa
Copy link
Member

sipa commented Jun 14, 2018

@Empact #10785 is low priority, and will probably take a while. Don't let it stop you.

@Empact Empact reopened this Jun 14, 2018
@Empact
Copy link
Member Author

Empact commented Jun 14, 2018

Good to know, thanks.

@Empact Empact closed this Jun 14, 2018
@Empact Empact reopened this Jun 14, 2018
@sipa
Copy link
Member

sipa commented Jun 14, 2018

I don't understand "scripted-diff: Drop SER_GETHASH"; it changes !(s.GetType() & SER_GETHASH) to s.GetType(). That means that what used to be the branch for DISK/NETWORK will end up being run just for DISK, and what used to be the branch for GETHASH will end up being run for NETWORK and GETHASH.

@Empact
Copy link
Member Author

Empact commented Jun 14, 2018

@sipa SER_NETWORK is (1 << 0) i.e. 0x01, SER_DISK is (1 << 1) i.e. 0x02, so both will evaluate to true, while with 0 used where SER_GETHASH once was, it will evaluate to false. Note also while they're defined as flags all uses of SER_GETHASH are singular.
https://github.com/bitcoin/bitcoin/pull/13462/files#diff-1fc2d3d7edc00ab8ea29eb1ca30cdcbbR163

@sipa
Copy link
Member

sipa commented Jun 14, 2018

Ah of course; I missed the (1 << ...) around it.

This isn't very readable code though. Would you mind keeping SER_GETHASH as a constant (perhaps just defined as 0), and explicit comparisons with it (rather than bit masking). That should still be a nice simplification.

@Empact Empact force-pushed the serialize-hash-type branch 3 times, most recently from d697362 to 95d73e0 Compare June 15, 2018 00:11
@Empact Empact changed the title scripted-diff: Simplify common case of CHashWriter and drop SER_GETHASH & SerializeHash scripted-diff: Simplify common case of CHashWriter and drop SerializeHash Jun 15, 2018
@Empact
Copy link
Member Author

Empact commented Jun 15, 2018

@sipa Fair enough, I dropped that commit. Def more straight-forward now.

@sipa
Copy link
Member

sipa commented Jun 15, 2018

Thinking a bit more about this, I think you can actually go further. I believe none of the serializers which have conditionals that mention SER_GETHASH (CDiskBlockIndex, CBlockLocator, CAddress, CKeyPool, CWalletKey, CAccountingEntry, CAccount) are ever actually invoked with SER_GETHASH as nType, so we could literally delete SER_GETHASH entire and all conditions that test for it. SerializeHash could then just use SER_NETWORK afaict.

@Empact
Copy link
Member Author

Empact commented Jun 15, 2018

@sipa Nice I'll look into that.

src/hash.h Outdated Show resolved Hide resolved
@Empact Empact changed the title scripted-diff: Simplify common case of CHashWriter and drop SerializeHash Simplify common case of CHashWriter and drop SerializeHash Jun 28, 2018
@DrahtBot DrahtBot closed this Aug 10, 2018
@DrahtBot DrahtBot reopened this Aug 10, 2018
All callers either relied on the default value of SER_GETHASH or provided
SER_GETHASH.
-BEGIN VERIFY SCRIPT-
sed -i -E "s/CHashWriter\(SER_GETHASH, 0\)(.[^{])/CHashWriter()\1/" $(git grep -l 'CHashWriter')
sed -i -E "s/CHashWriter (.+)\(SER_GETHASH, 0\)/CHashWriter \1/" $(git grep -l 'CHashWriter')
sed -i -E "s/CHashWriter (.+)\(SER_GETHASH, /CHashWriter \1(/" $(git grep -l 'CHashWriter')
-END VERIFY SCRIPT-
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Apr 29, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Apr 29, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request Apr 29, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request May 6, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request May 17, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
@jonatack
Copy link
Member

Approach ACK on this simplification, code looks reasonable on first read.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

At nearly four years old, this may be the pull that has been open the longest so far.

ACK c05246b code review, clean rebase to master, clean debug build, ran unit tests

@Empact
Copy link
Member Author

Empact commented May 21, 2022

Incidentally, @jonatack do you happen to know the situation with Cirrus-CI? I'd like to retry this build, but I don't have the option to do so on the site.

@hebasto
Copy link
Member

hebasto commented May 21, 2022

Incidentally, @jonatack do you happen to know the situation with Cirrus-CI? I'd like to retry this build, but I don't have the option to do so on the site.

Restarted.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

Munkybooty pushed a commit to Munkybooty/dash that referenced this pull request May 30, 2022
893628b Drop minor GetSerializeSize template (Ben Woosley)
da74db0 Drop unused GetType() from CSizeComputer (Ben Woosley)

Pull request description:

  Based on conversation in bitcoin#13462, it seems the serialization `GetType` has very narrow use/effect. In every case except for `CAddress`, which specifically relates to a network peer's address, not a wallet address etc., the serialized representation of an object is irrespective of its destination / type.

  This removes the unused `GetType` method from `CSizeComputer` as a step to further narrowing that use.

Tree-SHA512: e72b8e9e5160396691e05aeaee3aba5a57935a75bd5005cfcc7fb51c936f3d1728a397f999da5c36696506dd815fafa5c738f3894df8864f25f91f639eba9c3d
@maflcko
Copy link
Member

maflcko commented Jun 6, 2022

Not sure on this. I think it might be cleaner to remove ser-type and ser-version completely. See #19477 (comment)

@maflcko
Copy link
Member

maflcko commented Jun 10, 2022

See #25331

@maflcko
Copy link
Member

maflcko commented Jul 20, 2022

Can this be closed now?

@Empact
Copy link
Member Author

Empact commented Jul 22, 2022

Closing in favor of #25331

Thanks, yours is cleaner, but for those brackets. ;)

@Empact Empact closed this Jul 22, 2022
@Empact Empact deleted the serialize-hash-type branch July 22, 2022 07:18
@Empact Empact restored the serialize-hash-type branch November 18, 2022 20:45
@bitcoin bitcoin locked and limited conversation to collaborators Nov 18, 2023
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.

None yet

9 participants