Skip to content

Conversation

@instagibbs
Copy link
Member

During the loading of the genesis block, the bench print lines in ConnectTip divide by zero due to early return in ConnectBlock.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Funny that DisconnectTip doesn't decrement nBlocksTotal 👀

ACK ec30a79, nBlocksTotal is only used in logging.

@fanquake I don't think this should have validation label.

return error("%s: ConnectBlock %s failed, %s", __func__, pindexNew->GetBlockHash().ToString(), FormatStateMessage(state));
}
nTime3 = GetTimeMicros(); nTimeConnectTotal += nTime3 - nTime2;
assert(nBlocksTotal > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd avoid this, I think it is noise as there is already a "divide by nBlocksTotal" which implies this assertion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not a fan of silently committing UB.

Copy link
Contributor

Choose a reason for hiding this comment

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

There are 11 occurrences of / nBlocksTotal.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 29, 2019

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 maflcko changed the title Fix UB with bench on genesis block log: Fix UB with bench on genesis block Jan 29, 2019
@maflcko
Copy link
Member

maflcko commented Jan 29, 2019

ACK

@practicalswift
Copy link
Contributor

practicalswift commented Jan 30, 2019

This is already fixed in #14239 which was submitted back in September and is scheduled for 0.18.0 :-)

@promag @MarcoFalke @instagibbs Would you mind reviewing #14239?

@instagibbs
Copy link
Member Author

@practicalswift sure

@maflcko maflcko added this to the 0.18.0 milestone Jan 30, 2019
@practicalswift
Copy link
Contributor

Close in favour of #14239?

@laanwj
Copy link
Member

laanwj commented Jan 31, 2019

Yes this exact change is included in #14239.
Unless the rest of that PR is controversial and this part really needs to be factored out, it's probably better to focus on getting that one merged.

@instagibbs
Copy link
Member Author

SGTM. Closing.

@instagibbs instagibbs closed this Jan 31, 2019
@practicalswift
Copy link
Contributor

@laanwj PR #14239 is highly uncontroversial so I don't think that should be a problem :-)

@instagibbs
Copy link
Member Author

@practicalswift you ended up closing that PR ;P d'oh

@practicalswift
Copy link
Contributor

@instagibbs Please re-open this PR :)

@practicalswift
Copy link
Contributor

ACK ec30a79

@instagibbs instagibbs reopened this Feb 20, 2020
@jonatack
Copy link
Member

Concept ACK

@jonatack
Copy link
Member

Ok, this PR doesn't resolve all the UBSan issues that #17208 does, only the one involving nBlocksTotal.

As has been noted several times previously, nBlocksTotal appears to be used solely for bench logging purposes and it seems to me the approach in #17208 of initializing it to 1 instead of 0 is more straightforward to review and robust against regression; this comment by @gmaxwell concurs with that.

@practicalswift
Copy link
Contributor

practicalswift commented Feb 21, 2020

@jonatack Feel free to attack the remaining ones -- I'd be glad to review :)

@sipa
Copy link
Member

sipa commented Mar 17, 2020

utACK ec30a79

@maflcko maflcko merged commit 39497d1 into bitcoin:master Mar 17, 2020
@practicalswift
Copy link
Contributor

Nice to see this one merged!

Anyone (perhaps fellow UBSan-fan @jonatack?) who would like to volunteer to get rid of the remaining UBSan suppressions? If so #17208 can be used as a starting point :)

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 18, 2020
ec30a79 Fix UB with bench on genesis block (Gregory Sanders)

Pull request description:

  During the loading of the genesis block, the bench print lines in ConnectTip divide by zero due to early return in ConnectBlock.

ACKs for top commit:
  practicalswift:
    ACK ec30a79
  sipa:
    utACK ec30a79
  promag:
    ACK ec30a79, `nBlocksTotal` is only used in logging.

Tree-SHA512: b3bdbb58d10d002a2293d7f99196b227ed9f4ca8c6cd08981e95cc964be47efed98b91fad276ee6da5cf7e6684610998ace7ce9bace172dd6c51c386d985b83c
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Apr 7, 2020
- doc: fix git add argument bitcoin#18513
- build: Fix libevent linking for bench_bitcoin binary bitcoin#18397
- script: fix SCRIPT_ERR_SIG_PUSHONLY error string bitcoin#18412
- doc: Comment fix merkle.cpp bitcoin#18379
- log: Fix UB with bench on genesis block bitcoin#15283
- test: Fix mining to an invalid target + ensure that a new block has the correct hash internally bitcoin#18350
- Fix missing header in sync.h bitcoin#18357
- refactor: Fix implicit value conversion in formatPingTime bitcoin#18260
- Fix .gitignore policy in build_msvc directory bitcoin#18108
- build: Fix behavior when ALLOW_HOST_PACKAGES unset bitcoin#18051
- test: Fix p2p_invalid_messages failing in Python 3.8 because of warning bitcoin#17931
- qa: Fix double-negative arg test bitcoin#17893
- build: Fix configure report about qr bitcoin#17547
- log: Fix log message for -par=1 bitcoin#17325
- bench: Fix negative values and zero for -evals flag bitcoin#17267
- depends: fix boost mac cross build with clang 9+ bitcoin#17231
- doc: Fix broken bitcoin-cli examples bitcoin#17119
- doc: fix Makefile target in benchmarking.md bitcoin#17081
- contrib: fix minor typos in makeseeds.py bitcoin#17042
- test: Fix Python Docstring to include all Args. bitcoin#17030
- doc: Fix some misspellings bitcoin#17351
- doc: Doxygen-friendly script/descriptor.h comments bitcoin#16947
- doc: Fix doxygen errors bitcoin#17945
- doc: Doxygen-friendly CuckooCache comments bitcoin#16986
- doc: Add to Doxygen documentation guidelines bitcoin#17873
- depends: Consistent use of package variable bitcoin#17928
- init: Replace URL_WEBSITE with PACKAGE_URL bitcoin#18503
- doc: Add missed copyright headers bitcoin#17691
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
ec30a79 Fix UB with bench on genesis block (Gregory Sanders)

Pull request description:

  During the loading of the genesis block, the bench print lines in ConnectTip divide by zero due to early return in ConnectBlock.

ACKs for top commit:
  practicalswift:
    ACK ec30a79
  sipa:
    utACK ec30a79
  promag:
    ACK ec30a79, `nBlocksTotal` is only used in logging.

Tree-SHA512: b3bdbb58d10d002a2293d7f99196b227ed9f4ca8c6cd08981e95cc964be47efed98b91fad276ee6da5cf7e6684610998ace7ce9bace172dd6c51c386d985b83c
maflcko pushed a commit that referenced this pull request Nov 13, 2020
… divide-by-zero in validation.cpp)

0ccb3ad tests: Remove no longer needed UBSan suppression (float-divide-by-zero in validation.cpp) (practicalswift)

Pull request description:

  Remove no longer needed UBSan suppression.

  The float divide-by-zero in `validation.cpp` was fixed by instagibbs in ec30a79 (#15283).

ACKs for top commit:
  MarcoFalke:
    ACK 0ccb3ad

Tree-SHA512: 89a4f4b7371fa5725d9f801cee7ebbd17523f66017c9acfa813657dcb8d837f42209eff44ce9e5d48296a630bab9599d75f10024a0c7da7defb228f4eae3392a
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 13, 2020
… (float divide-by-zero in validation.cpp)

0ccb3ad tests: Remove no longer needed UBSan suppression (float-divide-by-zero in validation.cpp) (practicalswift)

Pull request description:

  Remove no longer needed UBSan suppression.

  The float divide-by-zero in `validation.cpp` was fixed by instagibbs in ec30a79 (bitcoin#15283).

ACKs for top commit:
  MarcoFalke:
    ACK 0ccb3ad

Tree-SHA512: 89a4f4b7371fa5725d9f801cee7ebbd17523f66017c9acfa813657dcb8d837f42209eff44ce9e5d48296a630bab9599d75f10024a0c7da7defb228f4eae3392a
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 9, 2021
Summary:
> During the loading of the genesis block, the bench print lines in ConnectTip divide by zero due to early return in ConnectBlock.

Increment `nBlocksTotal` before returning in ConnectBlock

This is a backport of Core [[bitcoin/bitcoin#15283 | PR15283]]

Test Plan: `ninja && ./src/bitcoind  -debug=bench | grep "Connect total:"`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8857
ftrader pushed a commit to bitcoin-cash-node/bitcoin-cash-node that referenced this pull request Apr 14, 2021
Summary:
> During the loading of the genesis block, the bench print lines in ConnectTip divide by zero due to early return in ConnectBlock.

Increment `nBlocksTotal` before returning in ConnectBlock

This is a backport of Core [[bitcoin/bitcoin#15283 | PR15283]]

Test Plan: `ninja && ./src/bitcoind  -debug=bench | grep "Connect total:"`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8857
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 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.

9 participants