Skip to content

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Jul 7, 2021

UniValue doesn't define push_back(bool), so C++ silently converts the bool to int and we end up with a Number of 0/1 instead
Explicitly passing a bool UniValue, however, works fine.

Fixes regressions introduced by #20012 and #21302

…(UniValue(bool))

UniValue doesn't define push_back(bool), so C++ silently converts the bool to int and we end up with a Number of 0/1 instead
Explicitly passing a bool UniValue, however, works fine.
@maflcko
Copy link
Member

maflcko commented Jul 7, 2021

Thank you for your contribution. However we do not accept patches that are only meant for downstream projects that are shipping modified versions of Bitcoin Core. This project's goal is to maintain the vanilla version of Bitcoin Core.

bitcoin-core/univalue-subtree@98fadc0

@maflcko maflcko closed this Jul 7, 2021
@maflcko
Copy link
Member

maflcko commented Jul 7, 2021

Happy to reopen for more feedback

@maflcko maflcko reopened this Jul 7, 2021
@hebasto
Copy link
Member

hebasto commented Jul 7, 2021

Fixes regressions introduced by #20012 and #21302

Do we need tests to prevent such regressions in the future?

@maflcko
Copy link
Member

maflcko commented Jul 7, 2021

Agree that this needs tests if it is decided that the workaround should be applied. Also the minimum dependency version should be properly documented in https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md#dependencies to have an objective criteria to decide on what workarounds are acceptable and which ones are not. Currently it is not documented and I (incorrectly?) assumed that only the bundled univalue is supported. The lack of clarification will lead to subjective disagreement about what versions are supported.

Finally, the patch seems incomplete anyway. It is a workaround for the fix for arrays I submitted in bitcoin-core/univalue-subtree@98fadc0, however it doesn't seem to address the same issue that was fixed for dictionaries in bitcoin-core/univalue-subtree@51d3ab3

@maflcko
Copy link
Member

maflcko commented Jul 7, 2021

To reply to my own comment: The minimum required univalue version is hidden in the configure.ac. The last time it was bumped was #12666 to require the bool dictionary fix.

So Concept NACK on this pull. I'd prefer to bump the minimum univalue dependency to require the bool array fix. This is a reliable fix for the bug (unlike this pull request) that also prevents the bug from silently appearing again.

@@ -606,8 +606,9 @@ void RPCHelpMan::AppendArgMap(UniValue& arr) const
map.push_back(m_name);
map.push_back(i);
map.push_back(arg_name);
map.push_back(arg.m_type == RPCArg::Type::STR ||
arg.m_type == RPCArg::Type::STR_HEX);
// NOTE: push_back(bool) converts the bool to Number, so explicitly make a boolean UniValue first
Copy link
Member

Choose a reason for hiding this comment

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

This note is only true for broken versions of univalue. push_back in our tree works just fine.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 7, 2021

However we do not accept patches that are only meant for downstream projects that are shipping modified versions of Bitcoin Core.

Many changes that benefit other projects (eg, Liquid) have been accepted into Core. This particular fix, however, affects Core itself, without modifications.

Do we need tests to prevent such regressions in the future?

It would be good to get one of the CI tasks using official UniValue, yes. That would have caught this. However, many of our tests don't differentiate between Number and boolean JSON return values, and would have ignored the issue if the bug hadn't been in the test itself.

Personally, I have modified my UniValue to give a deprecation warning when push_back(bool) is used. That could be put in our UniValue fork - or perhaps there's a way to make it stronger (ie, an error)?

Also the minimum dependency version should be properly documented in https://github.com/bitcoin/bitcoin/blob/master/doc/dependencies.md

Done

So Concept NACK on this pull. I'd prefer to bump the minimum univalue dependency to require the bool array fix. This is a reliable fix for the bug (unlike this pull request) that also prevents the bug from silently appearing again.

For that approach, the fix needs to be released upstream first. AFAIK, you have never submitted it upstream (despite me bringing it to your attention previously), so that hasn't even begun...

Until that happens, this fix is needed.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 8, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

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.

@maflcko
Copy link
Member

maflcko commented Jul 8, 2021

AFAIK, you have never submitted it upstream (despite me bringing it to your attention previously), so that hasn't even begun...

Assuming others are obliged to do something is not how open source dev works.

Regardless, I just looked into this and it seems this issue is fixed in the latest release? At least the code where the patch could be applied is removed.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

Assuming others are obliged to do something is not how open source dev works.

I didn't assume that. It's simply what would be necessary to avoid this workaround.

Regardless, I just looked into this and it seems this issue is fixed in the latest release? At least the code where the patch could be applied is removed.

It's still an issue in the latest stable 1.0.5, and 1.1.1 (a development release, possibly with a new API) can't be used to build Core at all (jgarzik/univalue#76)

@maflcko
Copy link
Member

maflcko commented Jul 8, 2021

In my view there are two options:

  • The univalue upstream that you are using is unmaintained and/or dropped support for Bitcoin Core. In this case we should simply remove --with-system-univalue, because there is no long-term prospect in keeping it.
  • It is still maintained. In that case, the bug(s) should be fixed upstream and the minimum version be bumped in our build system to require the bugfix to be included. Reporting the bug upstream to the dependency you are using also seems a more logical first step to me than to craft a workaround.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

In that case, the bug(s) should be fixed upstream and the minimum version be bumped in our build system to require the bugfix to be included.

IMO this is the ideal approach to take.

Reporting the bug upstream to the dependency you are using also seems a more logical first step to me than to craft a workaround.

It is unclear if this is going to happen before 22.0.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

To get the ball rolling on eventually not needing this, I opened jgarzik/univalue#83

@jnewbery
Copy link
Contributor

jnewbery commented Jul 8, 2021

In this case we should simply remove --with-system-univalue, because there is no long-term prospect in keeping it.

Strong concept ACK. The upstream https://github.com/jgarzik/univalue/ project is barely maintained.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

In this case we should simply remove --with-system-univalue, because there is no long-term prospect in keeping it.

Strong concept ACK. The upstream https://github.com/jgarzik/univalue/ project is barely maintained.

Strong concept NACK. It appears to be maintained just fine. The only reason this has broken is because @MarcoFalke has gone out of his way to create a divergent fork in the Core subtree for no benefit.

Ideally, we should just drop the subtree entirely, but at the very least, continuing to support building with official UniValue releases is a bare minimum level of competence we should keep.

@maflcko
Copy link
Member

maflcko commented Jul 8, 2021

The only reason this has broken is because @MarcoFalke has gone out of his way to create a divergent fork in the Core subtree for no benefit.

This is false; I did not create the repo that feeds the subtree. Also, it is irrelevant who created the repo, it was created so that bugfixes can be merged faster into the subtree.

In fact, as you can see from all the cross-merge commits, I was putting effort into keeping them in sync.

@maflcko
Copy link
Member

maflcko commented Jul 8, 2021

Ideally, we should just drop the subtree entirely

Related discussion about this happened in at least:

Re-hashing the same topic every year isn't going to help this project.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

What I see, is that you made an incompatible API change, ignored efforts to reconcile the official UniValue tree, rudely insta-closed this PR to fix compatibility, and when pushed here, you created a PR for it with 15 unrelated commits that you know you would never merge to Core.

Re-hashing the same topic every year isn't going to help this project.

So don't rehash it. We had something that worked. You're the one who apparently wants to change that.

@sipa
Copy link
Member

sipa commented Jul 8, 2021

Sorry @luke-jr, but this is ridiculous. Upstream is obviously unmaintained. It seems the maintainer has not had any comments/commits or other activity in over two years, while there have been PRs opened and commented on on a semi-regular basis. Bitcoin Core has had its own fork for a while, because the maintenance situation was sporadic before for time before already, but at this point there is no reason to keep treating that repo as upstream - it's dead. And the fact that it works without maintenance is not a reason why improvements to our fork can't be made. So I think we should simply start treating the https://github.com/bitcoin-core/univalue repository as upstream. You can't go call clear improvements to the codebase "going out of your way to create a divergent fork" when upstream isn't accepting any changes at all.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 8, 2021

@sipa There has been nothing to merge during that time. I glanced at the PRs. Some are enhancements tagged for a future release. None are merged in the Core subtree (aside from the ones just opened yesterday), so if upstream is unmaintained, so is Core's fork.

So I think we should simply start treating the https://github.com/bitcoin-core/univalue repository as upstream.

IF upstream is in fact unmaintained, that would seem like a good alternative solution. However, as things stand, that repo breaks compatibility by removing the std::pair stuff, and the README explicitly recommends using upstream instead. To start treating the Core fork as the official UniValue, we should probably add back the std::pair stuff (maybe with an #ifndef so we can avoid using it in Core) and update the README and tag a new version (which configure can then check for).

Edit: We should probably also merge in the bugfix(es) in upstream that Core's fork is still missing... (ironic to complain upstream hasn't acted in 1 day, when we're missing at least one 2+ year old bugfix)

You can't go call clear improvements to the codebase "going out of your way to create a divergent fork" when upstream isn't accepting any changes at all.

That isn't established yet. Upstream hasn't had more than 1 day to triage the push_back change.

@sipa
Copy link
Member

sipa commented Jul 8, 2021

You can't go call clear improvements to the codebase "going out of your way to create a divergent fork" when upstream isn't accepting any changes at all.

That isn't established yet. Upstream hasn't had more than 1 day to triage the push_back change.

I assumed you were talking about earlier changes when making that accusation. If that's not the case, I take my words back on that aspect.

I still disagree that there aren't any useful improvements PRed (e.g. jgarzik/univalue#70 or jgarzik/univalue#79), or that "it's maintained" - there has been no activity at all.

@maflcko
Copy link
Member

maflcko commented Jul 9, 2021

you created a PR for it with 15 unrelated commits that you know you would never merge to Core.

This is also false. Both the forks did merge PRs with "unrelated commits":

Merging one branch into another (with all commits) is one way to keep them in sync.

Edit: We should probably also merge in the bugfix(es) in upstream that Core's fork is still missing... (ironic to complain upstream hasn't acted in 1 day, when we're missing at least one 2+ year old bugfix)

It might be good to explain which fixes you are referring to.

IF upstream is in fact unmaintained, that would seem like a good alternative solution. However, as things stand, that repo breaks compatibility by removing the std::pair stuff, and the README explicitly recommends using upstream instead. To start treating the Core fork as the official UniValue, we should probably add back the std::pair stuff (maybe with an #ifndef so we can avoid using it in Core) and update the README and tag a new version (which configure can then check for).

There is no maintained version of Bitcoin Core that uses std::pair wrapper. Simply bumping the version to indicate a breaking change would be easier than adding it back.

@luke-jr
Copy link
Member Author

luke-jr commented Jul 9, 2021

It might be good to explain which fixes you are referring to.

jgarzik/univalue#58

@luke-jr
Copy link
Member Author

luke-jr commented Jul 9, 2021

Mr. Garzik advises that he still maintains UniValue and will make a new stable release (presumably with the fix) this month.

Perhaps the best approach at this time, is to simply bump the minimum version required to 1.0.6 assuming it will be available by the time 22.0 is final?

@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".

@fanquake
Copy link
Member

Mr. Garzik advises that he still maintains UniValue and will make a new stable release (presumably with the fix) this month.

It's now essentially the end of the month, and I can't yet see any new activity in https://github.com/jgarzik/univalue.

@maflcko
Copy link
Member

maflcko commented Jul 30, 2021

In this case we should remove --with-system-univalue. See #22412 (comment)

@luke-jr
Copy link
Member Author

luke-jr commented Jul 30, 2021

Or just fix the bug in Core. Upstream not agreeing to your API change is not an excuse to break compatibility.

If you want to become upstream, fine, but don't be a jerk to everyone who wishes to use proper shared libraries. NACK to removing UniValue support and creating divergent vendor-only forks for no reason.

@fanquake
Copy link
Member

fanquake commented Sep 2, 2021

Concept NACK. I agree with the discussion here, in regards to why this is not something we want to, or should have to do. I've summarized my thoughts in #22646, which removes support for system univalue.

PRs like #22412 highlight the "issue" with us operating with our own Univalue fork, where we actively fix bugs, and make improvements, when upstream (https://github.com/jgarzik/univalue) may not be taking those improvements, and by all accounts, is not currently actively maintained. Bitcoin Core should not be hamstrung into not being able to fix bugs in a library, and/or have to litter our source with "workarounds", i.e #22412, for bugs we've already fixed, based on the fact that an upstream project is not actively being maintained. Allowing builders to use system libs is really only exacerbating this problem, with little benefit to our project.

Also

It's now essentially the end of the month, and I can't yet see any new activity in https://github.com/jgarzik/univalue.

Another month has passed and there's neither release activity, not commentary on any of the new PRs by Bitcoin Core contributors in the https://github.com/jgarzik/univalue/ repo.

fanquake added a commit that referenced this pull request Oct 20, 2021
…tem-univalue`

0f95247 Integrate univalue into our buildsystem (Cory Fields)
9b49ed6 Squashed 'src/univalue/' changes from 98fadc0909..a44caf65fe (fanquake)

Pull request description:

  This PR more tightly integrates building Univalue into our build system. This follows the same approach we use for [LevelDB](https://github.com/bitcoin-core/leveldb/), ([`Makefile.leveldb.include`](https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.leveldb.include)), and [CRC32C](https://github.com/bitcoin-core/crc32c) ([`Makefile.crc32c.include`](https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.crc32c.include)), and will be the same approach we use for [minisketch](https://github.com/sipa/minisketch); see #23114.

  This approach yields a number of benefits, including:
  * Faster configuration due to one less subconfigure being run during `./configure` i.e 22s with this PR vs 26s
  * Faster autoconf i.e 13s with this PR vs 17s
  * Improved caching
  * No more issues with compiler flags i.e #12467
  * More direct control means we can build exactly the objects we want

  There might be one argument against making this change, which is that builders should have the option to use "proper shared/system libraries". However, I think that falls down for a few reasons. The first being that we already don't support building with a number of system libraries (secp256k1, leveldb, crc32c); some for good reason. Univalue is really the odd one out at the moment.

  Note that the only fork of Core I'm aware of, that actively patches in support for using system libs, also explicitly marks them as ["DANGEROUS"](https://github.com/bitcoinknots/bitcoin/blob/a886811721ce66eb586871706b3f5dd27518ac3e/configure.ac#L1430) and ["NOT SUPPORTED"](https://github.com/bitcoinknots/bitcoin/blob/a886811721ce66eb586871706b3f5dd27518ac3e/configure.ac#L1312). So it would seem they exist more to satisfy a distro requirement, as opposed to something that anyone should, or would actually use in practice.

  PRs like #22412 highlight the "issue" with us operating with our own Univalue fork, where we actively fix bugs, and make improvements, when upstream (https://github.com/jgarzik/univalue) may not be taking those improvements, and by all accounts, is not currently actively maintained. Bitcoin Core should not be hamstrung into not being able to fix bugs in a library, and/or have to litter our source with "workarounds", i.e #22412, for bugs we've already fixed, based on the fact that an upstream project is not actively being maintained. Allowing builders to use system libs is really only exacerbating this problem, with little benefit to our project. Bitcoin Core is not quite like your average piece of distro packaged software.

  There is the potential for us to give the same treatment to libsecp256k1, however it seems doing that is currently less straightforward.

ACKs for top commit:
  dongcarl:
    ACK 0f95247 less my comment above, always nice to have an include-able `sources.mk` which makes integration easier.
  theuni:
    ACK 0f95247. Thanks fanquake for keeping this going.

Tree-SHA512: a7f2e41ee7cba06ae72388638e86b264eca1b9a8b81c15d1d7b45df960c88c3b91578b4ade020f8cc61d75cf8d16914575f9a78fa4cef9c12be63504ed804b99
@fanquake
Copy link
Member

I'm closing this now that #22646 has been merged. For the record, there still doesn't seem to be any new activity upstream, and this is now nearly 3 months after upstream advised they were going to make a new release.

@fanquake fanquake closed this Oct 20, 2021
dekm pushed a commit to unigrid-project/daemon that referenced this pull request Oct 27, 2022
…ith-system-univalue`

0f95247 Integrate univalue into our buildsystem (Cory Fields)
9b49ed6 Squashed 'src/univalue/' changes from 98fadc0909..a44caf65fe (fanquake)

Pull request description:

  This PR more tightly integrates building Univalue into our build system. This follows the same approach we use for [LevelDB](https://github.com/bitcoin-core/leveldb/), ([`Makefile.leveldb.include`](https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.leveldb.include)), and [CRC32C](https://github.com/bitcoin-core/crc32c) ([`Makefile.crc32c.include`](https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.crc32c.include)), and will be the same approach we use for [minisketch](https://github.com/sipa/minisketch); see bitcoin#23114.

  This approach yields a number of benefits, including:
  * Faster configuration due to one less subconfigure being run during `./configure` i.e 22s with this PR vs 26s
  * Faster autoconf i.e 13s with this PR vs 17s
  * Improved caching
  * No more issues with compiler flags i.e bitcoin#12467
  * More direct control means we can build exactly the objects we want

  There might be one argument against making this change, which is that builders should have the option to use "proper shared/system libraries". However, I think that falls down for a few reasons. The first being that we already don't support building with a number of system libraries (secp256k1, leveldb, crc32c); some for good reason. Univalue is really the odd one out at the moment.

  Note that the only fork of Core I'm aware of, that actively patches in support for using system libs, also explicitly marks them as ["DANGEROUS"](https://github.com/bitcoinknots/bitcoin/blob/a886811721ce66eb586871706b3f5dd27518ac3e/configure.ac#L1430) and ["NOT SUPPORTED"](https://github.com/bitcoinknots/bitcoin/blob/a886811721ce66eb586871706b3f5dd27518ac3e/configure.ac#L1312). So it would seem they exist more to satisfy a distro requirement, as opposed to something that anyone should, or would actually use in practice.

  PRs like bitcoin#22412 highlight the "issue" with us operating with our own Univalue fork, where we actively fix bugs, and make improvements, when upstream (https://github.com/jgarzik/univalue) may not be taking those improvements, and by all accounts, is not currently actively maintained. Bitcoin Core should not be hamstrung into not being able to fix bugs in a library, and/or have to litter our source with "workarounds", i.e bitcoin#22412, for bugs we've already fixed, based on the fact that an upstream project is not actively being maintained. Allowing builders to use system libs is really only exacerbating this problem, with little benefit to our project. Bitcoin Core is not quite like your average piece of distro packaged software.

  There is the potential for us to give the same treatment to libsecp256k1, however it seems doing that is currently less straightforward.

ACKs for top commit:
  dongcarl:
    ACK 0f95247 less my comment above, always nice to have an include-able `sources.mk` which makes integration easier.
  theuni:
    ACK 0f95247. Thanks fanquake for keeping this going.

Tree-SHA512: a7f2e41ee7cba06ae72388638e86b264eca1b9a8b81c15d1d7b45df960c88c3b91578b4ade020f8cc61d75cf8d16914575f9a78fa4cef9c12be63504ed804b99
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 2022
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.

8 participants