Page MenuHomePhabricator

rpc: getblockfrompeer
ClosedPublic

Authored by PiRK on Dec 1 2022, 10:47.

Details

Reviewers
Fabien
Group Reviewers
Restricted Project
Commits
rABC93ae2058ec9e: rpc: getblockfrompeer
Summary

This adds an RPC method to fetch a block directly from a peer. This can used to fetch stale blocks with lower proof of work that are normally ignored by the node (headers-only in getchaintips).

Limitations:

  • you have to specify which peer to fetch the block from
  • the node must already have the header

Co-authored-by: John Newbery <john@johnnewbery.com>

This is a backport of core#20295, core#23702 and core#23706 (partial)
https://github.com/bitcoin/bitcoin/pull/20295/commits/dce8c4c38111556ca480aa0e63c46b71f66b508f
https://github.com/bitcoin/bitcoin/pull/23702/commits/aaaa34e34db6ff0f9ca3407bda42e7f0db887737
https://github.com/bitcoin/bitcoin/pull/23706/commits/bfbf91d0b2004dde358253ac174982f784b43b59
https://github.com/bitcoin/bitcoin/pull/23706/commits/809d66bb65aa78048e27c2a878d6f7becaecfe11
https://github.com/bitcoin/bitcoin/pull/23706/commits/0e3d7c5ee16d5a4c061ab9a57285bceb7899b512

The main commit is the first one. The other commits are minor style & comments improvements, and one commit removing an unnecessary argument in the newly added FetchBlock function.

Test Plan

ninja all check-all

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

PiRK requested review of this revision.Dec 1 2022, 10:47

Tail of the build log:

In file included from ../../src/test/util/setup_common.cpp:19:
../../src/./net_processing.h:65:20: error: parameter 'pindex' not found in the function declaration [-Werror,-Wdocumentation]
     * @param[in]  pindex   The block index
                   ^~~~~~
../../src/./net_processing.h:65:20: note: did you mean 'block_index'?
     * @param[in]  pindex   The block index
                   ^~~~~~
                   block_index
1 error generated.
[403/529] Building CXX object src/CMakeFiles/server.dir/rpc/avalanche.cpp.o
FAILED: src/CMakeFiles/server.dir/rpc/avalanche.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_AC_USE_STD_ATOMIC -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SP_USE_STD_ATOMIC -DBOOST_THREAD_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/rpc/avalanche.cpp.o -MF src/CMakeFiles/server.dir/rpc/avalanche.cpp.o.d -o src/CMakeFiles/server.dir/rpc/avalanche.cpp.o -c ../../src/rpc/avalanche.cpp
In file included from ../../src/rpc/avalanche.cpp:17:
../../src/./net_processing.h:65:20: error: parameter 'pindex' not found in the function declaration [-Werror,-Wdocumentation]
     * @param[in]  pindex   The block index
                   ^~~~~~
../../src/./net_processing.h:65:20: note: did you mean 'block_index'?
     * @param[in]  pindex   The block index
                   ^~~~~~
                   block_index
1 error generated.
[404/529] Building CXX object src/CMakeFiles/server.dir/rpc/blockchain.cpp.o
FAILED: src/CMakeFiles/server.dir/rpc/blockchain.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_AC_USE_STD_ATOMIC -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SP_USE_STD_ATOMIC -DBOOST_THREAD_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/rpc/blockchain.cpp.o -MF src/CMakeFiles/server.dir/rpc/blockchain.cpp.o.d -o src/CMakeFiles/server.dir/rpc/blockchain.cpp.o -c ../../src/rpc/blockchain.cpp
In file included from ../../src/rpc/blockchain.cpp:23:
../../src/./net_processing.h:65:20: error: parameter 'pindex' not found in the function declaration [-Werror,-Wdocumentation]
     * @param[in]  pindex   The block index
                   ^~~~~~
../../src/./net_processing.h:65:20: note: did you mean 'block_index'?
     * @param[in]  pindex   The block index
                   ^~~~~~
                   block_index
1 error generated.
[405/529] Building CXX object src/CMakeFiles/server.dir/init.cpp.o
FAILED: src/CMakeFiles/server.dir/init.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_AC_USE_STD_ATOMIC -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SP_USE_STD_ATOMIC -DBOOST_THREAD_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/init.cpp.o -MF src/CMakeFiles/server.dir/init.cpp.o.d -o src/CMakeFiles/server.dir/init.cpp.o -c ../../src/init.cpp
In file included from ../../src/init.cpp:41:
../../src/./net_processing.h:65:20: error: parameter 'pindex' not found in the function declaration [-Werror,-Wdocumentation]
     * @param[in]  pindex   The block index
                   ^~~~~~
../../src/./net_processing.h:65:20: note: did you mean 'block_index'?
     * @param[in]  pindex   The block index
                   ^~~~~~
                   block_index
1 error generated.
[406/529] Building CXX object src/CMakeFiles/server.dir/net_processing.cpp.o
FAILED: src/CMakeFiles/server.dir/net_processing.cpp.o 
/usr/bin/ccache /usr/bin/clang++ -DBOOST_AC_USE_STD_ATOMIC -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_SP_USE_STD_ATOMIC -DBOOST_THREAD_DYN_LINK -DBUILD_BITCOIN_INTERNAL -DENABLE_AVX2 -DENABLE_SHANI -DENABLE_SSE41 -DHAVE_BUILD_INFO -DHAVE_CONFIG_H -DHAVE_CONSENSUS_LIB -DLEVELDB_ATOMIC_PRESENT -DLEVELDB_PLATFORM_POSIX -DOS_LINUX -I../../src/leveldb/helpers/memenv -I../../src/. -Isrc -I../../src/univalue/include -Isrc/crypto/.. -I../../src/secp256k1/include -I../../src/leveldb/include -isystem /usr/include/jemalloc -isystem /usr/include/miniupnpc -Werror -g -O2 -fPIC -fvisibility=hidden -fstack-protector-all -Wstack-protector -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -Wformat -Wgnu -Wvla -Wcast-align -Wunused-parameter -Wmissing-braces -Wthread-safety -Wrange-loop-analysis -Wredundant-decls -Wunreachable-code-loop-increment -Wsign-compare -Wconditional-uninitialized -Wdocumentation -Wformat-security -Wredundant-move -Woverloaded-virtual -Wshadow -Wshadow-field -Wno-unused-parameter -Wno-implicit-fallthrough -pthread -std=gnu++17 -MD -MT src/CMakeFiles/server.dir/net_processing.cpp.o -MF src/CMakeFiles/server.dir/net_processing.cpp.o.d -o src/CMakeFiles/server.dir/net_processing.cpp.o -c ../../src/net_processing.cpp
In file included from ../../src/net_processing.cpp:6:
../../src/./net_processing.h:65:20: error: parameter 'pindex' not found in the function declaration [-Werror,-Wdocumentation]
     * @param[in]  pindex   The block index
                   ^~~~~~
../../src/./net_processing.h:65:20: note: did you mean 'block_index'?
     * @param[in]  pindex   The block index
                   ^~~~~~
                   block_index
1 error generated.
[407/529] Building CXX object src/CMakeFiles/server.dir/validation.cpp.o
ninja: build stopped: cannot make progress due to previous errors.
Build build-clang failed with exit code 1

fix parameter name in doxygen

Fabien requested changes to this revision.Dec 1 2022, 14:41
Fabien added a subscriber: Fabien.
Fabien added inline comments.
src/net_processing.cpp
2085 ↗(On Diff #36880)

const

2087–2103 ↗(On Diff #36880)

that structure is horrible

src/net_processing.h
63 ↗(On Diff #36880)

nit: align

test/functional/rpc_getblockfrompeer.py
18 ↗(On Diff #36880)

Please add a comment like:
Don't connect the nodes initially

This revision now requires changes to proceed.Dec 1 2022, 14:41
Fabien added inline comments.
src/net_processing.h
63 ↗(On Diff #36892)

still misaligned

This revision is now accepted and ready to land.Dec 1 2022, 17:15
This revision was automatically updated to reflect the committed changes.