Page MenuHomePhabricator

refactor: rpc: Pass CBlockIndex by reference instead of pointer
ClosedPublic

Authored by PiRK on Jun 14 2025, 14:58.

Details

Summary

All functions assume that the pointer is never null, so pass by
reference, to avoid accidental segfaults at runtime, or at least make
them more obvious.

Also, remove unused casts in touched lines.

Also, add CHECK_NONFATAL checks, to turn segfault crashes into an
recoverable runtime error with debug information.

This concludes backport of core#29021
https://github.com/bitcoin/bitcoin/pull/29021/commits/fa5989d514d246e56977c528b2dd2abe6dc8efcc

Depends on D18257

Test Plan

ninja all check-all bench-bitcoin

Event Timeline

PiRK requested review of this revision.Jun 14 2025, 14:58

Tail of the build log:

-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/field_mask.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/source_context.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/struct.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/timestamp.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/type.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/wrappers.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/any.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/api.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/compiler/plugin.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/descriptor.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/duration.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/empty.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/field_mask.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/source_context.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/struct.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/timestamp.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/type.proto
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/include/google/protobuf/wrappers.proto
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-targets.cmake
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-targets-release.cmake
-- Up-to-date: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-config-version.cmake
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-options.cmake
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-module.cmake
-- Installing: /work/depends/work/staging/x86_64-apple-darwin/native_protobuf/21.12-6a0b0aa1335/work/depends/x86_64-apple-darwin/native/lib/cmake/protobuf/protobuf-config.cmake
Postprocessing native_protobuf...
Caching native_protobuf...
Extracting boost...
/root/abc-depends/sources/boost_1_81_0.tar.bz2: OK
Preprocessing boost...
patching file boost/process/detail/posix/handles.hpp
Configuring boost...
Building boost...
Staging boost...
Postprocessing boost...
Caching boost...
Extracting libevent...
/root/abc-depends/sources/libevent-2.1.12-stable.tar.gz: OK
Preprocessing libevent...
Configuring libevent...
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for x86_64-apple-darwin-strip... no
checking for strip... strip
configure: WARNING: using cross tools not prefixed with host triplet
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU style)
checking for x86_64-apple-darwin-gcc... env -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH -u OBJC_INCLUDE_PATH -u OBJCPLUS_INCLUDE_PATH -u CPATH -u LIBRARY_PATH /usr/bin/clang --target=x86_64-apple-darwin -isysroot/work/depends/SDKs/Xcode-15.0-15A240d-extracted-SDK-with-libcxx-headers -nostdlibinc -iwithsysroot/usr/include -iframeworkwithsysroot/System/Library/Frameworks
checking whether the C compiler works... no
configure: error: in `/work/depends/work/build/x86_64-apple-darwin/libevent/2.1.12-stable-e97fed94c4b':
configure: error: C compiler cannot create executables
See `config.log' for more details
make[1]: *** [funcs.mk:297: /work/depends/work/build/x86_64-apple-darwin/libevent/2.1.12-stable-e97fed94c4b/./.stamp_configured] Error 77
make: *** [Makefile:251: build-osx] Error 2
Build build-osx failed with exit code 2
This revision is now accepted and ready to land.Jun 17 2025, 09:39