This is a backport of [[https://github.com/bitcoin/bitcoin/pull/22146 | core#22146]]
We can bypassing the temporary ubsan suppressions ([[https://github.com/bitcoin/bitcoin/pull/22202 | core#22202]]).
The casting to uint32_t is necessary to avoid a -Wsign-compare warning. A block height can not be negative.