Skip to content

Commit

Permalink
Merge #2155: [Miner] Rewrite miner code with proper encapsulation + t…
Browse files Browse the repository at this point in the history
…est coverage

0d55bcf blockassembler: do not lock cs_main and mempool cs for the entire block, only where are needed. (furszy)
70e6430 miner_tests fix locking issues, cs_main and mempool.cs cannot (and don't need) to be locked for the entire test. Only in the places that the locks are really needed. (furszy)
c4e3754 [test] functional miner_test, reworked and updated it to make it fully work with our blockchain and consensus rules. (furszy)
1cd3943 [Miner] New blockassembler introduction and connection with the sources. (furszy)

Pull request description:

  Have rewritten the miner code sources, dividing the miner thread from the block assembling process, encapsulating the block creation state inside a new `BlockAssembler` class (adapting bitcoin#7598).

  Cleaned several mempool redundant checks inside the assembly process (adaptation of bitcoin#6898):
  > The mempool is explicitly assumed to be responsible for maintaining consistency of transactions with respect to not spending non-existent outputs, not double spending, script validity and coinbase maturity. Only finality of transactions is checked before assembling a block.

  Another point added here is the rework of the previously non-functional `miner_tests` unit test. Which.. have essentially made it work, adding coverage for the miner process, updating it to a fairly recent point down upstream's path + adapting it to our blockchain and consensus rules.

  The result is a large speed up in the block assembly process, a much better and cleaner code architecture and enable an easier add of new algorithms for block filling in the future.

  ------------

  A good work path on top of this would be to add unit test coverage for PoS, cold staking and Sapling block creation (among others). At the moment, most of the block creation tests are functional ones which are slow and require to setup entire nodes etc.

ACKs for top commit:
  random-zebra:
    utACK 0d55bcf after rebase
  Fuzzbawls:
    ACK 0d55bcf

Tree-SHA512: ab0ff3832bceeb28233871a64ee9593cee695843396b95f9471485bf1d9e684614db783342252bcfb49cb3df40c444697d24e3dab1f8a5226b2478bc191822d2
  • Loading branch information
Fuzzbawls committed Feb 3, 2021
2 parents 99af033 + 0d55bcf commit a88b6ea
Show file tree
Hide file tree
Showing 11 changed files with 727 additions and 568 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ set(SERVER_SOURCES
./src/legacy/validation_zerocoin_legacy.cpp
./src/merkleblock.cpp
./src/miner.cpp
./src/blockassembler.cpp
./src/net.cpp
./src/net_processing.cpp
./src/noui.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ BITCOIN_CORE_H = \
masternodeconfig.h \
merkleblock.h \
messagesigner.h \
blockassembler.h \
miner.h \
moneysupply.h \
net.h \
Expand Down Expand Up @@ -328,6 +329,7 @@ libbitcoin_server_a_SOURCES = \
legacy/validation_zerocoin_legacy.cpp \
sapling/sapling_validation.cpp \
merkleblock.cpp \
blockassembler.cpp \
miner.cpp \
net.cpp \
net_processing.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ BITCOIN_TESTS =\
test/mempool_tests.cpp \
test/merkle_tests.cpp \
test/multisig_tests.cpp \
test/miner_tests.cpp \
test/net_tests.cpp \
test/netbase_tests.cpp \
test/pmt_tests.cpp \
Expand Down
Loading

0 comments on commit a88b6ea

Please sign in to comment.