diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f38b0ace3..143d6a6324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -62,6 +62,7 @@ if(FULLNODE) include(ProjectGroupSig) include(ProjectPaillier) include(ProjectBLST) + include(ProjectTOMLPP) add_subdirectory(bcos-sealer) add_subdirectory(bcos-security) diff --git a/bcos-crypto/test/CMakeLists.txt b/bcos-crypto/test/CMakeLists.txt index 57373dda93..c8cd233f60 100644 --- a/bcos-crypto/test/CMakeLists.txt +++ b/bcos-crypto/test/CMakeLists.txt @@ -26,4 +26,6 @@ find_package(ZLIB REQUIRED) add_executable(${TEST_BINARY_NAME} ${SOURCES}) target_include_directories(${TEST_BINARY_NAME} PRIVATE ..) target_link_libraries(${TEST_BINARY_NAME} Boost::unit_test_framework bcos-utilities bcos-crypto ZLIB::ZLIB) +set_source_files_properties("unittests/main.cpp" "unittests/testMerkle.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-crypto WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/bcos-crypto/test/unittests/testMerkle.cpp b/bcos-crypto/test/unittests/testMerkle.cpp index 25c885a1c7..0f24d5bd40 100644 --- a/bcos-crypto/test/unittests/testMerkle.cpp +++ b/bcos-crypto/test/unittests/testMerkle.cpp @@ -10,8 +10,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/bcos-executor/src/executive/LedgerCache.h b/bcos-executor/src/executive/LedgerCache.h index 0b7ca44d7f..8cef564544 100644 --- a/bcos-executor/src/executive/LedgerCache.h +++ b/bcos-executor/src/executive/LedgerCache.h @@ -23,20 +23,35 @@ #include "../Common.h" #include "bcos-framework/ledger/LedgerInterface.h" +#include "bcos-framework/ledger/LedgerMethods.h" #include #include -#include #include +#include namespace bcos::executor { -class LedgerCache : public bcos::tool::LedgerConfigFetcher +class LedgerCache { +private: + ledger::LedgerInterface::Ptr m_ledger; + ledger::LedgerConfig::Ptr m_ledgerConfig; + std::optional m_chainID; + + std::map> m_blockNumber2Hash; + mutable bcos::SharedMutex x_blockNumber2Hash; + public: using Ptr = std::shared_ptr; - LedgerCache(bcos::ledger::LedgerInterface::Ptr ledger) : bcos::tool::LedgerConfigFetcher(ledger) + LedgerCache(bcos::ledger::LedgerInterface::Ptr ledger) + : m_ledger(std::move(ledger)), m_ledgerConfig(std::make_shared()) {} - virtual ~LedgerCache() = default; + + const ledger::LedgerConfig& ledgerConfig() const { return *m_ledgerConfig; } + void updateLedgerConfig() + { + task::syncWait(ledger::getLedgerConfig(*m_ledger, *m_ledgerConfig)); + } void setBlockNumber2Hash(int64_t blockNumber, h256 blockHash) { @@ -52,7 +67,7 @@ class LedgerCache : public bcos::tool::LedgerConfigFetcher [blockNumber](const auto& item) { return item.first < blockNumber; }); } - bcos::crypto::HashType fetchBlockHash(bcos::protocol::BlockNumber _blockNumber) override + bcos::crypto::HashType fetchBlockHash(bcos::protocol::BlockNumber _blockNumber) { EXECUTOR_LOG(TRACE) << LOG_BADGE("LedgerCache") << "fetchBlockHash start" << LOG_KV("blockNumber", _blockNumber); @@ -68,7 +83,7 @@ class LedgerCache : public bcos::tool::LedgerConfigFetcher } } - auto hash = bcos::tool::LedgerConfigFetcher::fetchBlockHash(_blockNumber); + auto hash = task::syncWait(ledger::getBlockHash(*m_ledger, _blockNumber)); EXECUTOR_LOG(TRACE) << LOG_BADGE("LedgerCache") << "fetchBlockHash return by fetching from ledger" << LOG_KV("blockNumber", _blockNumber) @@ -106,16 +121,21 @@ class LedgerCache : public bcos::tool::LedgerConfigFetcher evmc_uint256be chainId() { - if (ledgerConfig()->chainId().has_value()) + if (m_chainID) { - return ledgerConfig()->chainId().value(); + return *m_chainID; } - fetchChainId(); - return ledgerConfig()->chainId().value(); - } -private: - std::map> m_blockNumber2Hash; - mutable bcos::SharedMutex x_blockNumber2Hash; + if (auto value = task::syncWait( + ledger::getSystemConfig(*m_ledger, ledger::SYSTEM_KEY_WEB3_CHAIN_ID))) + { + auto numChainID = boost::lexical_cast(std::get<0>(*value)); + m_chainID.emplace(bcos::toEvmC(numChainID)); + EXECUTOR_LOG(INFO) << LOG_DESC("fetchChainId success") << LOG_KV("chainId", numChainID); + return *m_chainID; + } + + return {}; + } }; } // namespace bcos::executor diff --git a/bcos-executor/src/executor/TransactionExecutor.cpp b/bcos-executor/src/executor/TransactionExecutor.cpp index ff18bafe2c..0a418ae9a9 100644 --- a/bcos-executor/src/executor/TransactionExecutor.cpp +++ b/bcos-executor/src/executor/TransactionExecutor.cpp @@ -150,8 +150,8 @@ TransactionExecutor::TransactionExecutor(bcos::ledger::LedgerInterface::Ptr ledg m_vmFactory(std::move(vmFactory)) { assert(m_backendStorage); - m_ledgerCache->fetchCompatibilityVersion(); - m_ledgerCache->fetchBlockNumberAndHash(); + + m_ledgerCache->updateLedgerConfig(); GlobalHashImpl::g_hashImpl = m_hashImpl; m_abiCache = make_shared>(32); #ifdef WITH_WASM @@ -159,14 +159,13 @@ TransactionExecutor::TransactionExecutor(bcos::ledger::LedgerInterface::Ptr ledg #endif m_threadPool = std::make_shared(name, std::thread::hardware_concurrency()); - setBlockVersion(m_ledgerCache->ledgerConfig()->compatibilityVersion()); - if (m_ledgerCache->ledgerConfig()->compatibilityVersion() >= BlockVersion::V3_3_VERSION) + setBlockVersion(m_ledgerCache->ledgerConfig().compatibilityVersion()); + if (m_ledgerCache->ledgerConfig().compatibilityVersion() >= BlockVersion::V3_3_VERSION) { - m_ledgerCache->fetchAuthCheckStatus(); - if (m_ledgerCache->ledgerConfig()->authCheckStatus() != UINT32_MAX) + if (m_ledgerCache->ledgerConfig().authCheckStatus() != UINT32_MAX) { // cannot get auth check status, use config value - m_isAuthCheck = !m_isWasm && m_ledgerCache->ledgerConfig()->authCheckStatus() != 0; + m_isAuthCheck = !m_isWasm && m_ledgerCache->ledgerConfig().authCheckStatus() != 0; } } if (m_isWasm) @@ -311,7 +310,7 @@ void TransactionExecutor::initEvmEnvironment() set builtIn = {CRYPTO_ADDRESS, GROUP_SIG_ADDRESS, RING_SIG_ADDRESS, CAST_ADDRESS}; m_staticPrecompiled = std::make_shared>(builtIn); if (m_blockVersion <=> BlockVersion::V3_1_VERSION == 0 && - m_ledgerCache->ledgerConfig()->blockNumber() > 0) + m_ledgerCache->ledgerConfig().blockNumber() > 0) { // Only 3.1 goes here, here is a bug, ignore init test precompiled } @@ -374,7 +373,7 @@ void TransactionExecutor::initWasmEnvironment() m_staticPrecompiled = std::make_shared>(builtIn); if (m_blockVersion <=> BlockVersion::V3_1_VERSION == 0 && - m_ledgerCache->ledgerConfig()->blockNumber() > 0) + m_ledgerCache->ledgerConfig().blockNumber() > 0) { // Only 3.1 goes here, here is a bug, ignore init test precompiled } @@ -1885,16 +1884,15 @@ void TransactionExecutor::commit( EXECUTOR_NAME_LOG(DEBUG) << BLOCK_NUMBER(blockNumber) << "Commit success"; m_lastCommittedBlockNumber = blockNumber; - m_ledgerCache->fetchCompatibilityVersion(); - auto version = m_ledgerCache->ledgerConfig()->compatibilityVersion(); + m_ledgerCache->updateLedgerConfig(); + auto version = m_ledgerCache->ledgerConfig().compatibilityVersion(); setBlockVersion(version); if (version >= BlockVersion::V3_3_VERSION) { - m_ledgerCache->fetchAuthCheckStatus(); - if (m_ledgerCache->ledgerConfig()->authCheckStatus() != UINT32_MAX) + if (m_ledgerCache->ledgerConfig().authCheckStatus() != UINT32_MAX) { // cannot get auth check status, not update value - m_isAuthCheck = !m_isWasm && m_ledgerCache->ledgerConfig()->authCheckStatus() != 0; + m_isAuthCheck = !m_isWasm && m_ledgerCache->ledgerConfig().authCheckStatus() != 0; } } removeCommittedState(); diff --git a/bcos-executor/src/executor/TransactionExecutorFactory.h b/bcos-executor/src/executor/TransactionExecutorFactory.h index 3c50438622..a685f9a215 100644 --- a/bcos-executor/src/executor/TransactionExecutorFactory.h +++ b/bcos-executor/src/executor/TransactionExecutorFactory.h @@ -23,9 +23,9 @@ #include "ShardingTransactionExecutor.h" #include "TransactionExecutor.h" #include "bcos-framework/storage/StorageInterface.h" -#include "bcos-ledger/src/libledger/utilities/Common.h" #include #include +#include namespace bcos::executor { @@ -59,7 +59,7 @@ class TransactionExecutorFactory m_ledger(std::move(ledger)), m_txpool(std::move(txpool)), m_cacheFactory(std::move(cacheFactory)), - m_stateStorageFactory(stateStorageFactory), + m_stateStorageFactory(std::move(stateStorageFactory)), m_storage(std::move(storage)), m_executionMessageFactory(std::move(executionMessageFactory)), m_hashImpl(std::move(hashImpl)), diff --git a/bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp b/bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp index d888296f66..11db3d573c 100644 --- a/bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp +++ b/bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include diff --git a/bcos-executor/test/unittest/CMakeLists.txt b/bcos-executor/test/unittest/CMakeLists.txt index abb4c7053f..82743a4fc4 100644 --- a/bcos-executor/test/unittest/CMakeLists.txt +++ b/bcos-executor/test/unittest/CMakeLists.txt @@ -13,12 +13,13 @@ find_package(Boost REQUIRED unit_test_framework) find_package(TBB CONFIG REQUIRED) include(SearchTestCases) -target_link_libraries(${TEST_BINARY_NAME} ${EXECUTOR_TARGET} ${CRYPTO_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework Boost::serialization Boost::unit_test_framework) +target_link_libraries(${TEST_BINARY_NAME} ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${CRYPTO_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework Boost::serialization Boost::unit_test_framework) target_compile_options(${TEST_BINARY_NAME} PRIVATE -fno-var-tracking -Wno-unused-parameter) +set_source_files_properties("main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") #add_test(NAME test-executor WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND $) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "") - # for code coverage #if (COVERAGE) # include(Coverage) diff --git a/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp index df7d67faab..c1cc50b169 100644 --- a/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp @@ -38,15 +38,6 @@ using namespace bcos::ledger; using namespace bcos::crypto; using namespace bcos::codec; -#ifndef WITH_WASM -namespace bcos::wasm -{ -class GasInjector -{ -}; -} // namespace bcos::wasm -#endif - namespace bcos::test { class CryptoPrecompiledFixture : public PrecompiledFixture diff --git a/bcos-executor/test/unittest/libprecompiled/GroupSigPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/GroupSigPrecompiledTest.cpp index faa86ed7f2..1101d3d14e 100644 --- a/bcos-executor/test/unittest/libprecompiled/GroupSigPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/GroupSigPrecompiledTest.cpp @@ -31,15 +31,6 @@ using namespace bcos::precompiled; using namespace bcos::executor; using namespace bcos::storage; -#ifndef WITH_WASM -namespace bcos::wasm -{ -class GasInjector -{ -}; -} // namespace bcos::wasm -#endif - namespace bcos::test { struct GroupSigPrecompiledFixture diff --git a/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h b/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h index 0112292f08..1f865bfb62 100644 --- a/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h +++ b/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h @@ -19,6 +19,7 @@ */ #pragma once +#include "bcos-crypto/interfaces/crypto/CommonType.h" #include "executive/BlockContext.h" #include "executive/TransactionExecutive.h" #include "executor/TransactionExecutorFactory.h" diff --git a/bcos-executor/test/unittest/libprecompiled/RingSigPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/RingSigPrecompiledTest.cpp index 0e7bfda9cd..220bcd34b7 100644 --- a/bcos-executor/test/unittest/libprecompiled/RingSigPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/RingSigPrecompiledTest.cpp @@ -31,15 +31,6 @@ using namespace bcos::precompiled; using namespace bcos::executor; using namespace bcos::storage; -#ifndef WITH_WASM -namespace bcos::wasm -{ -class GasInjector -{ -}; -} // namespace bcos::wasm -#endif - namespace bcos::test { struct RingSigPrecompiledFixture diff --git a/bcos-executor/test/unittest/libprecompiled/VRFPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/VRFPrecompiledTest.cpp index b60eea9f15..152049d77b 100644 --- a/bcos-executor/test/unittest/libprecompiled/VRFPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/VRFPrecompiledTest.cpp @@ -38,15 +38,6 @@ using namespace bcos::precompiled; using namespace bcos::executor; using namespace bcos::storage; -#ifndef WITH_WASM -namespace bcos::wasm -{ -class GasInjector -{ -}; -} // namespace bcos::wasm -#endif - namespace bcos::test { class VRFPrecompiledFixture diff --git a/bcos-executor/test/unittest/mock/MockLedger.h b/bcos-executor/test/unittest/mock/MockLedger.h index 575625d884..7c7ad0e442 100644 --- a/bcos-executor/test/unittest/mock/MockLedger.h +++ b/bcos-executor/test/unittest/mock/MockLedger.h @@ -10,6 +10,15 @@ #include #include +#ifndef WITH_WASM +namespace bcos::wasm +{ +class GasInjector +{ +}; +} // namespace bcos::wasm +#endif + namespace bcos::test { class MockLedger : public bcos::ledger::LedgerInterface @@ -157,15 +166,14 @@ class MockLedger : public bcos::ledger::LedgerInterface return; } - - BOOST_CHECK(false); // Need implementations + _onGetConfig(nullptr, "0", 0); }; void asyncGetNodeListByType(std::string_view const& _type, std::function _onGetConfig) override { - BOOST_CHECK(false); // Need implementations + _onGetConfig(nullptr, std::make_shared()); }; void asyncGetNonceList(protocol::BlockNumber _startNumber, int64_t _offset, diff --git a/bcos-executor/tools/CMakeLists.txt b/bcos-executor/tools/CMakeLists.txt index f56e091de0..53bcdbae6e 100644 --- a/bcos-executor/tools/CMakeLists.txt +++ b/bcos-executor/tools/CMakeLists.txt @@ -2,4 +2,4 @@ add_executable(injector inject_meter.cpp) target_include_directories(injector PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../src/) -target_link_libraries(injector PUBLIC ${EXECUTOR_TARGET} ${TOOL_TARGET} wabt) +target_link_libraries(injector PUBLIC ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${TOOL_TARGET} wabt) diff --git a/bcos-framework/bcos-framework/executor/NativeExecutionMessage.h b/bcos-framework/bcos-framework/executor/NativeExecutionMessage.h index d7db363426..9aee6f602d 100644 --- a/bcos-framework/bcos-framework/executor/NativeExecutionMessage.h +++ b/bcos-framework/bcos-framework/executor/NativeExecutionMessage.h @@ -18,8 +18,8 @@ class NativeExecutionMessage : public protocol::ExecutionMessage Type type() const override { return m_type; } void setType(Type type) override { m_type = type; } - crypto::HashType transactionHash() const override { return m_transactionHash; } - void setTransactionHash(crypto::HashType hash) override { m_transactionHash = hash; } + bcos::crypto::HashType transactionHash() const override { return m_transactionHash; } + void setTransactionHash(bcos::crypto::HashType hash) override { m_transactionHash = hash; } int64_t contextID() const override { return m_contextID; } void setContextID(int64_t contextID) override { m_contextID = contextID; } diff --git a/bcos-framework/bcos-framework/ledger/LedgerTypeDef.h b/bcos-framework/bcos-framework/ledger/LedgerTypeDef.h index b134ead686..8a175ac6d3 100644 --- a/bcos-framework/bcos-framework/ledger/LedgerTypeDef.h +++ b/bcos-framework/bcos-framework/ledger/LedgerTypeDef.h @@ -22,6 +22,7 @@ #include "../protocol/ProtocolTypeDef.h" #include "SystemConfigs.h" #include +#include namespace bcos::ledger { @@ -123,4 +124,28 @@ struct CurrentState int64_t totalTransactionCount; int64_t totalFailedTransactionCount; }; + +// parent=>children +using Parent2ChildListMap = std::map>; +// child=>parent +using Child2ParentMap = tbb::concurrent_unordered_map; + +constexpr static const char* const SYS_VALUE = "value"; +constexpr static const char* const SYS_CONFIG_ENABLE_BLOCK_NUMBER = "enable_number"; +constexpr static const char* const SYS_VALUE_AND_ENABLE_BLOCK_NUMBER = "value,enable_number"; + +enum LedgerError : int32_t +{ + SUCCESS = 0, + OpenTableFailed = 3001, + CallbackError = 3002, + ErrorArgument = 3003, + DecodeError = 3004, + ErrorCommitBlock = 3005, + CollectAsyncCallbackError = 3006, + LedgerLockError = 3007, + GetStorageError = 3008, + EmptyEntry = 3009, + UnknownError = 3010, +}; } // namespace bcos::ledger diff --git a/bcos-framework/test/CMakeLists.txt b/bcos-framework/test/CMakeLists.txt index 3a06454a25..ea0ec1149d 100644 --- a/bcos-framework/test/CMakeLists.txt +++ b/bcos-framework/test/CMakeLists.txt @@ -25,4 +25,6 @@ add_executable(${TEST_BINARY_NAME} ${SOURCES}) find_package(Boost REQUIRED serialization unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} PRIVATE ${UTILITIES_TARGET} bcos-framework Boost::serialization Boost::unit_test_framework) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-framework WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-gateway/test/CMakeLists.txt b/bcos-gateway/test/CMakeLists.txt index 1b67ad622f..d3d27f7c13 100644 --- a/bcos-gateway/test/CMakeLists.txt +++ b/bcos-gateway/test/CMakeLists.txt @@ -36,5 +36,7 @@ target_compile_options(${TEST_BINARY_NAME} PRIVATE -Wno-unused-variable) find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} ${GATEWAY_TARGET} ${TOOL_TARGET} ${TARS_PROTOCOL_TARGET} ${FRONT_TARGET} bcos-crypto Boost::unit_test_framework) +set_source_files_properties("unittests/GatewayMessageTest.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") # add_test(NAME test-gateway WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) add_test(NAME ${TEST_BINARY_NAME} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bcos-gateway/test/unittests COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/bcos-ledger/src/libledger/Ledger.cpp b/bcos-ledger/src/libledger/Ledger.cpp index 7b9092020f..f76a656095 100644 --- a/bcos-ledger/src/libledger/Ledger.cpp +++ b/bcos-ledger/src/libledger/Ledger.cpp @@ -29,7 +29,6 @@ #include "bcos-tool/NodeConfig.h" #include "bcos-tool/VersionConverter.h" #include "bcos-utilities/Common.h" -#include "utilities/Common.h" #include #include #include diff --git a/bcos-ledger/src/libledger/Ledger.h b/bcos-ledger/src/libledger/Ledger.h index 07e97d0ac9..388c08733b 100644 --- a/bcos-ledger/src/libledger/Ledger.h +++ b/bcos-ledger/src/libledger/Ledger.h @@ -24,7 +24,6 @@ #include "bcos-framework/protocol/BlockFactory.h" #include "bcos-framework/protocol/ProtocolTypeDef.h" #include "bcos-framework/storage/StorageInterface.h" -#include "utilities/Common.h" #include #include #include diff --git a/bcos-ledger/src/libledger/LedgerMethods.cpp b/bcos-ledger/src/libledger/LedgerMethods.cpp index 75e8ad1412..7cd2c072e8 100644 --- a/bcos-ledger/src/libledger/LedgerMethods.cpp +++ b/bcos-ledger/src/libledger/LedgerMethods.cpp @@ -1,7 +1,6 @@ #include "bcos-framework/ledger/LedgerMethods.h" #include "bcos-framework/ledger/LedgerConfig.h" #include "bcos-tool/VersionConverter.h" -#include "utilities/Common.h" #include #include #include diff --git a/bcos-ledger/src/libledger/utilities/Common.h b/bcos-ledger/src/libledger/utilities/Common.h deleted file mode 100644 index 91922ded86..0000000000 --- a/bcos-ledger/src/libledger/utilities/Common.h +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (C) 2021 FISCO BCOS. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @file Common.h - * @author: kyonRay - * @date 2021-04-13 - */ -#pragma once -#include -#include -#include -#include - -#define LEDGER_LOG(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE("LEDGER") - -namespace bcos::ledger -{ -// parent=>children -using Parent2ChildListMap = std::map>; -// child=>parent -using Child2ParentMap = tbb::concurrent_unordered_map; - -constexpr static const char* const SYS_VALUE = "value"; -constexpr static const char* const SYS_CONFIG_ENABLE_BLOCK_NUMBER = "enable_number"; -constexpr static const char* const SYS_VALUE_AND_ENABLE_BLOCK_NUMBER = "value,enable_number"; - -enum LedgerError : int32_t -{ - SUCCESS = 0, - OpenTableFailed = 3001, - CallbackError = 3002, - ErrorArgument = 3003, - DecodeError = 3004, - ErrorCommitBlock = 3005, - CollectAsyncCallbackError = 3006, - LedgerLockError = 3007, - GetStorageError = 3008, - EmptyEntry = 3009, - UnknownError = 3010, -}; - -} // namespace bcos::ledger diff --git a/bcos-ledger/test/mock/MockStorage.h b/bcos-ledger/test/mock/MockStorage.h index 0787bc314b..fe8ed9c192 100644 --- a/bcos-ledger/test/mock/MockStorage.h +++ b/bcos-ledger/test/mock/MockStorage.h @@ -23,7 +23,6 @@ #include "bcos-framework/storage/Common.h" #include "bcos-framework/storage/StorageInterface.h" #include "bcos-framework/storage/Table.h" -#include "bcos-ledger/libledger/utilities/Common.h" #include #define SLEEP_MILLI_SECONDS 10 diff --git a/bcos-ledger/test/mock/MockTable.h b/bcos-ledger/test/mock/MockTable.h deleted file mode 100644 index 707b4ffa75..0000000000 --- a/bcos-ledger/test/mock/MockTable.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright (C) 2021 FISCO BCOS. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @file MockTable.h - * @author: kyonRay - * @date 2021-05-07 - */ -#pragma once - -#include "bcos-framework/storage/Common.h" -#include "bcos-framework/storage/Table.h" -#include "bcos-ledger/libledger/utilities/Common.h" -#include - -using namespace bcos::storage; -using namespace bcos::ledger; - -namespace bcos::test -{ -class MockTable : public Table -{ -public: - using Ptr = std::shared_ptr; - - explicit MockTable(std::string const& _tableName) - : Table(nullptr, nullptr, 0), m_tableName(_tableName) - {} - - std::shared_ptr getRow(const std::string& _key) override - { - auto entry = m_fakeStorage[_key]; - if (entry) - { - return entry; - } - return nullptr; - } - - bool setRow(const std::string& _key, const std::shared_ptr& _entry) override - { - m_fakeStorage[_key] = _entry; - return true; - } - - std::vector getPrimaryKeys(const Condition::Ptr&) const override - { - std::vector keys; - keys.reserve(m_fakeStorage.size()); - std::transform(m_fakeStorage.begin(), m_fakeStorage.end(), keys.begin(), - [](auto pair) { return pair.first; }); - return keys; - } - -private: - std::string m_tableName; - std::unordered_map m_fakeStorage; -}; - -class MockErrorTableFactory : public TableStorage -{ -public: - explicit MockErrorTableFactory(storage::StorageInterface::Ptr _db) - : TableStorage(_db, nullptr, -1) - { - m_sysTables.emplace_back(TableStorage::SYS_TABLES); - } - std::shared_ptr openTable(const std::string& _tableName) override - { - if (std::find(m_sysTables.begin(), m_sysTables.end(), _tableName) != m_sysTables.end()) - { - return TableFactory::openTable(_tableName); - } - else - { - return nullptr; - } - } - bool createTable(const std::string& _tableName, const std::string& _keyField, - const std::string& _valueFields) override - { - if (_tableName.at(0) == '/') - m_sysTables.emplace_back(_tableName); - return TableFactory::createTable(_tableName, _keyField, _valueFields); - } - std::pair commit() override { return {0, BCOS_ERROR_PTR(-1, "")}; } - - std::vector m_sysTables; -}; -} // namespace bcos::test diff --git a/bcos-ledger/test/unittests/ledger/LedgerTest.cpp b/bcos-ledger/test/unittests/ledger/LedgerTest.cpp index 7dcf26d111..6e35128f32 100644 --- a/bcos-ledger/test/unittests/ledger/LedgerTest.cpp +++ b/bcos-ledger/test/unittests/ledger/LedgerTest.cpp @@ -35,7 +35,6 @@ #include "bcos-framework/storage/LegacyStorageMethods.h" #include "bcos-framework/transaction-executor/StateKey.h" #include "bcos-framework/transaction-executor/TransactionExecutor.h" -#include "bcos-ledger/src/libledger/utilities/Common.h" #include "bcos-task/Wait.h" #include "bcos-tool/BfsFileFactory.h" #include "bcos-tool/ConsensusNode.h" diff --git a/bcos-pbft/test/CMakeLists.txt b/bcos-pbft/test/CMakeLists.txt index 0ff2cd5dc7..64a3a0f990 100644 --- a/bcos-pbft/test/CMakeLists.txt +++ b/bcos-pbft/test/CMakeLists.txt @@ -27,4 +27,6 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}) find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} ${PBFT_TARGET} ${RPBFT_TARGET} ${TOOL_TARGET} ${LEDGER_TARGET} ${TABLE_TARGET} bcos-crypto ${TARS_PROTOCOL_TARGET} protobuf::libprotobuf Boost::unit_test_framework) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-pbft WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/bcos-rpc/CMakeLists.txt b/bcos-rpc/CMakeLists.txt index 5ea6038dec..70f36c4230 100644 --- a/bcos-rpc/CMakeLists.txt +++ b/bcos-rpc/CMakeLists.txt @@ -29,7 +29,7 @@ file(GLOB_RECURSE SRCS bcos-rpc/*.cpp) find_package(tarscpp REQUIRED) add_library(${RPC_TARGET} ${SRCS} ${HEADERS}) -target_link_libraries(${RPC_TARGET} PUBLIC bcos-boostssl ${LEDGER_TARGET} ${CRYPTO_TARGET} ${TARS_PROTOCOL_TARGET} jsoncpp_static tarscpp::tarsservant tarscpp::tarsutil) +target_link_libraries(${RPC_TARGET} PUBLIC bcos-boostssl ${CODEC_TARGET} ${CRYPTO_TARGET} ${TARS_PROTOCOL_TARGET} jsoncpp_static tarscpp::tarsservant tarscpp::tarsutil) set_target_properties(${RPC_TARGET} PROPERTIES UNITY_BUILD "ON") if (TESTS) diff --git a/bcos-rpc/test/CMakeLists.txt b/bcos-rpc/test/CMakeLists.txt index b647c52e33..360cc91b16 100644 --- a/bcos-rpc/test/CMakeLists.txt +++ b/bcos-rpc/test/CMakeLists.txt @@ -27,5 +27,7 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE .) target_compile_options(${TEST_BINARY_NAME} PRIVATE -Wno-unused-variable) target_link_libraries(${TEST_BINARY_NAME} ${TXPOOL_TARGET} ${LEDGER_TARGET} ${RPC_TARGET} ${TOOL_TARGET} Boost::unit_test_framework) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") #add_test(NAME ${TEST_BINARY_NAME} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "") \ No newline at end of file diff --git a/bcos-rpc/test/unittests/rpc/RpcTest.cpp b/bcos-rpc/test/unittests/rpc/RpcTest.cpp index ecf8d29599..5069ad283f 100644 --- a/bcos-rpc/test/unittests/rpc/RpcTest.cpp +++ b/bcos-rpc/test/unittests/rpc/RpcTest.cpp @@ -43,7 +43,7 @@ using namespace bcos::rpc; using namespace bcos::crypto; namespace bcos::test { -BOOST_FIXTURE_TEST_SUITE(testValidator, RPCFixture) +BOOST_FIXTURE_TEST_SUITE(testRPC, RPCFixture) BOOST_AUTO_TEST_CASE(buildTest) { auto rpc = factory->buildRpc("gateway", "rpc", nullptr); diff --git a/bcos-scheduler/test/CMakeLists.txt b/bcos-scheduler/test/CMakeLists.txt index 595ac27311..1797db5fa0 100644 --- a/bcos-scheduler/test/CMakeLists.txt +++ b/bcos-scheduler/test/CMakeLists.txt @@ -11,6 +11,8 @@ find_package(Boost REQUIRED unit_test_framework serialization) target_link_libraries(${TEST_BINARY_NAME} ${SCHEDULER_TARGET} ${LEDGER_TARGET} ${CRYPTO_TARGET} Boost::unit_test_framework ${TARS_PROTOCOL_TARGET} Boost::serialization ${STORAGE_TARGET} ${SECURITY_TARGET}) +set_source_files_properties("main.cpp" "testDmcExecutor.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-scheduler WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) # include(SearchTestCases) diff --git a/bcos-scheduler/test/mock/MockLedger3.h b/bcos-scheduler/test/mock/MockLedger3.h index d1c5056c92..998962cef2 100644 --- a/bcos-scheduler/test/mock/MockLedger3.h +++ b/bcos-scheduler/test/mock/MockLedger3.h @@ -9,7 +9,6 @@ #include "bcos-framework/protocol/Transaction.h" #include "bcos-framework/protocol/TransactionReceipt.h" #include "bcos-framework/storage/StorageInterface.h" -#include "bcos-ledger/src/libledger/utilities/Common.h" #include #include #include diff --git a/bcos-sdk/tests/CMakeLists.txt b/bcos-sdk/tests/CMakeLists.txt index 89dda36783..3d2b2458ec 100644 --- a/bcos-sdk/tests/CMakeLists.txt +++ b/bcos-sdk/tests/CMakeLists.txt @@ -26,5 +26,7 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}) find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} ${BCOS_CPP_SDK_TARGET} ${TABLE_TARGET} bcos-utilities ${TARS_PROTOCOL_TARGET} Boost::unit_test_framework) +set_source_files_properties("unittests/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") #add_test(NAME ${TEST_BINARY_NAME} COMMAND ${TEST_BINARY_NAME}) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "") \ No newline at end of file diff --git a/bcos-storage/test/unittest/CMakeLists.txt b/bcos-storage/test/unittest/CMakeLists.txt index a9dea3dd63..cdfe1acad9 100644 --- a/bcos-storage/test/unittest/CMakeLists.txt +++ b/bcos-storage/test/unittest/CMakeLists.txt @@ -34,6 +34,8 @@ find_package(Boost REQUIRED unit_test_framework log) find_package(fmt REQUIRED) target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${STORAGE_TARGET} Boost::unit_test_framework Boost::log fmt::fmt-header-only) +set_source_files_properties("main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") include(SearchTestCases) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "${EXCLUDE_SUITES}") # add_test(NAME test-storage WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-storage/test/unittest/TestRocksDBStorage.cpp b/bcos-storage/test/unittest/TestRocksDBStorage.cpp index 45b0a9ceb4..038854478d 100644 --- a/bcos-storage/test/unittest/TestRocksDBStorage.cpp +++ b/bcos-storage/test/unittest/TestRocksDBStorage.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include @@ -28,7 +27,7 @@ using namespace std; // return os; // } -namespace bcos::test +namespace bcos::test::rocksdb_test { class Header256Hash : public bcos::crypto::Hash { @@ -693,4 +692,4 @@ BOOST_AUTO_TEST_CASE(commitAndCheck) } BOOST_AUTO_TEST_SUITE_END() -} // namespace bcos::test \ No newline at end of file +} // namespace bcos::test::rocksdb_test \ No newline at end of file diff --git a/bcos-sync/bcos-sync/BlockSync.cpp b/bcos-sync/bcos-sync/BlockSync.cpp index bf1cde4bb3..5acfe0ef7a 100644 --- a/bcos-sync/bcos-sync/BlockSync.cpp +++ b/bcos-sync/bcos-sync/BlockSync.cpp @@ -26,7 +26,6 @@ #include "bcos-framework/ledger/LedgerTypeDef.h" #include "bcos-framework/protocol/CommonError.h" #include "bcos-framework/protocol/ProtocolTypeDef.h" -#include #include #include #include diff --git a/bcos-sync/test/CMakeLists.txt b/bcos-sync/test/CMakeLists.txt index 7cfe30dd0d..a1d7c194dd 100644 --- a/bcos-sync/test/CMakeLists.txt +++ b/bcos-sync/test/CMakeLists.txt @@ -27,4 +27,6 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE . ../src ${CMAKE_SOURCE_D find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${PBPROTOCOL_TARGET} ${SYNC_TARGET} ${LEDGER_TARGET} ${TXPOOL_TARGET} ${CRYPTO_TARGET} ${TARS_PROTOCOL_TARGET} protobuf::libprotobuf Boost::unit_test_framework) +set_source_files_properties("main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-sync WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-table/test/CMakeLists.txt b/bcos-table/test/CMakeLists.txt index 867b1ce078..8a521bf76d 100644 --- a/bcos-table/test/CMakeLists.txt +++ b/bcos-table/test/CMakeLists.txt @@ -26,6 +26,8 @@ target_include_directories(${TEST_BINARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}) find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} ${TABLE_TARGET} Boost::unit_test_framework) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") include(SearchTestCases) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "${EXCLUDE_SUITES}") # add_test(NAME test-table WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-table/test/unittests/libtable/Hash.h b/bcos-table/test/unittests/libtable/Hash.h index 91570022ba..82668f887e 100644 --- a/bcos-table/test/unittests/libtable/Hash.h +++ b/bcos-table/test/unittests/libtable/Hash.h @@ -17,10 +17,40 @@ * @file Header256Hash.h */ +#pragma once +#include "bcos-framework/storage/Entry.h" +#include "bcos-framework/storage/Table.h" #include #include #include +namespace std +{ +inline ostream& operator<<(ostream& os, const std::optional& entry) +{ + os << entry.has_value(); + return os; +} + +inline ostream& operator<<(ostream& os, const std::optional& table) +{ + os << table.has_value(); + return os; +} + +inline ostream& operator<<(ostream& os, const std::unique_ptr& error) +{ + os << error->what(); + return os; +} + +inline ostream& operator<<(ostream& os, const std::tuple& pair) +{ + os << std::get<0>(pair) << " " << std::get<1>(pair).hex(); + return os; +} +} // namespace std + namespace bcos { namespace crypto diff --git a/bcos-table/test/unittests/libtable/Table.cpp b/bcos-table/test/unittests/libtable/Table.cpp index 2280cd5245..eada38d099 100644 --- a/bcos-table/test/unittests/libtable/Table.cpp +++ b/bcos-table/test/unittests/libtable/Table.cpp @@ -35,27 +35,6 @@ using namespace bcos; using namespace bcos::storage; using namespace bcos::crypto; -namespace std -{ -inline ostream& operator<<(ostream& os, const tuple& item) -{ - os << get<0>(item) << " " << get<1>(item); - return os; -} - -inline ostream& operator<<(ostream& os, const std::optional& table) -{ - os << table.has_value(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::unique_ptr& error) -{ - os << error->what(); - return os; -} -} // namespace std - namespace bcos { namespace test diff --git a/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp b/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp index 8162da3f96..65ecdc3904 100644 --- a/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp +++ b/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp @@ -49,34 +49,6 @@ using namespace bcos::crypto; #if defined(__APPLE__) #undef __APPLE__ #endif - -namespace std -{ -inline ostream& operator<<(ostream& os, const std::optional& entry) -{ - os << entry.has_value(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::optional
& table) -{ - os << table.has_value(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::unique_ptr& error) -{ - os << error->what(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::tuple& pair) -{ - os << std::get<0>(pair) << " " << std::get<1>(pair).hex(); - return os; -} -} // namespace std - namespace bcos::test { struct KeyPageStorageFixture diff --git a/bcos-table/test/unittests/libtable/TestStateStorage.cpp b/bcos-table/test/unittests/libtable/TestStateStorage.cpp index e1f8484502..6266347104 100644 --- a/bcos-table/test/unittests/libtable/TestStateStorage.cpp +++ b/bcos-table/test/unittests/libtable/TestStateStorage.cpp @@ -42,34 +42,6 @@ using namespace bcos::crypto; #if defined(__APPLE__) #undef __APPLE__ #endif - -namespace std -{ -inline ostream& operator<<(ostream& os, const std::optional& entry) -{ - os << entry.has_value(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::optional
& table) -{ - os << table.has_value(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::unique_ptr& error) -{ - os << error->what(); - return os; -} - -inline ostream& operator<<(ostream& os, const std::tuple& pair) -{ - os << std::get<0>(pair) << " " << std::get<1>(pair).hex(); - return os; -} -} // namespace std - namespace bcos { namespace test diff --git a/bcos-tars-protocol/test/CMakeLists.txt b/bcos-tars-protocol/test/CMakeLists.txt index bb7c823390..04c6d3240a 100644 --- a/bcos-tars-protocol/test/CMakeLists.txt +++ b/bcos-tars-protocol/test/CMakeLists.txt @@ -28,4 +28,6 @@ find_package(jsoncpp REQUIRED) target_compile_options(${TEST_BINARY_NAME} PRIVATE -Wno-unused-variable) target_link_libraries(${TEST_BINARY_NAME} PRIVATE ${TARS_PROTOCOL_TARGET} ${CRYPTO_TARGET} Boost::unit_test_framework jsoncpp_static) +set_source_files_properties("main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME test-tars-protocol WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-tool/bcos-tool/LedgerConfigFetcher.cpp b/bcos-tool/bcos-tool/LedgerConfigFetcher.cpp deleted file mode 100644 index 714f11bf83..0000000000 --- a/bcos-tool/bcos-tool/LedgerConfigFetcher.cpp +++ /dev/null @@ -1,346 +0,0 @@ -/** - * Copyright (C) 2021 FISCO BCOS. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @brief Public function to get information from Ledger - * @file LedgerConfigFetcher.cpp - * @author: yujiechen - * @date 2021-05-19 - */ -#include "LedgerConfigFetcher.h" -#include "Exceptions.h" -#include "VersionConverter.h" -#include -#include -#include -#include -#include -using namespace bcos::protocol; -using namespace bcos::crypto; -using namespace bcos::consensus; -using namespace bcos::tool; -using namespace bcos::ledger; - -void LedgerConfigFetcher::fetchAll() -{ - // should not change fetch order - fetchBlockNumberAndHash(); - fetchCompatibilityVersion(); - fetchFeatures(); - fetchConsensusNodeList(); - fetchObserverNodeList(); - fetchCandidateSealerList(); - fetchBlockTxCountLimit(); - fetchGenesisHash(); - fetchConsensusLeaderPeriod(); - fetchAuthCheckStatus(); - fetchEpochSealerNum(); - fetchEpochBlockNum(); - fetchNotifyRotateFlagInfo(); -} - -void LedgerConfigFetcher::fetchBlockNumber() -{ - std::promise> blockNumberPromise; - m_ledger->asyncGetBlockNumber([&blockNumberPromise](Error::Ptr _error, BlockNumber _number) { - blockNumberPromise.set_value(std::make_pair(_error, _number)); - }); - auto ret = blockNumberPromise.get_future().get(); - auto error = ret.first; - if (error) - { - TOOL_LOG(WARNING) << LOG_DESC("LedgerConfigFetcher: fetchBlockNumber failed") - << LOG_KV("code", error->errorCode()) - << LOG_KV("message", error->errorMessage()); - BOOST_THROW_EXCEPTION(LedgerConfigFetcherException() - << errinfo_comment("LedgerConfigFetcher: fetchBlockNumber failed ")); - } - auto blockNumber = ret.second; - m_ledgerConfig->setBlockNumber(blockNumber); - TOOL_LOG(INFO) << LOG_DESC("LedgerConfigFetcher: fetchBlockNumber success") - << LOG_KV("blockNumber", blockNumber); -} - -void LedgerConfigFetcher::fetchBlockNumberAndHash() -{ - fetchBlockNumber(); - auto blockNumber = m_ledgerConfig->blockNumber(); - // fetch blockHash - auto hash = fetchBlockHash(blockNumber); - TOOL_LOG(INFO) << LOG_DESC("LedgerConfigFetcher: fetchBlockHash success") - << LOG_KV("blockNumber", blockNumber) << LOG_KV("hash", hash.abridged()); - m_ledgerConfig->setHash(hash); -} - -void LedgerConfigFetcher::fetchGenesisHash() -{ - m_genesisHash = fetchBlockHash(0); - TOOL_LOG(INFO) << LOG_DESC("fetchGenesisHash success") - << LOG_KV("genesisHash", m_genesisHash.abridged()); -} - -HashType LedgerConfigFetcher::fetchBlockHash(BlockNumber _blockNumber) -{ - std::promise> hashPromise; - m_ledger->asyncGetBlockHashByNumber( - _blockNumber, [&hashPromise](Error::Ptr _error, HashType _hash) { - hashPromise.set_value(std::make_pair(_error, _hash)); - }); - auto result = hashPromise.get_future().get(); - auto error = result.first; - if (error) - { - TOOL_LOG(WARNING) << LOG_DESC("LedgerConfigFetcher: fetchBlockHash failed") - << LOG_KV("code", error->errorCode()) - << LOG_KV("message", error->errorMessage()) - << LOG_KV("number", _blockNumber); - BOOST_THROW_EXCEPTION(LedgerConfigFetcherException() - << errinfo_comment("LedgerConfigFetcher: fetchBlockHash failed ")); - } - return result.second; -} - - -std::string LedgerConfigFetcher::fetchSystemConfig(std::string_view _key) -{ - std::promise> systemConfigPromise; - m_ledger->asyncGetSystemConfigByKey(_key, - [&systemConfigPromise](Error::Ptr _error, std::string _sysValue, BlockNumber _blockNumber) { - systemConfigPromise.set_value(std::tuple(_error, _sysValue, _blockNumber)); - }); - auto ret = systemConfigPromise.get_future().get(); - auto error = std::get<0>(ret); - if (error) - { - TOOL_LOG(INFO) << LOG_DESC("fetchSystemConfig failed") << LOG_KV("code", error->errorCode()) - << LOG_KV("message", error->errorMessage()) << LOG_KV("key", _key); - BOOST_THROW_EXCEPTION( - LedgerConfigFetcherException() << errinfo_comment( - "LedgerConfigFetcher: fetchSystemConfig for " + std::string{_key} + " failed")); - } - return std::get<1>(ret); -} - -bcos::ledger::SystemConfigEntry LedgerConfigFetcher::fetchSystemConfigNoException( - std::string_view _key, bcos::ledger::SystemConfigEntry _defaultValue) noexcept -{ - std::promise> systemConfigPromise; - m_ledger->asyncGetSystemConfigByKey(_key, [&systemConfigPromise](const Error::Ptr& _error, - std::string _sysValue, BlockNumber _blockNumber) { - systemConfigPromise.set_value({_error, {std::move(_sysValue), _blockNumber}}); - }); - auto ret = systemConfigPromise.get_future().get(); - auto error = std::get<0>(ret); - if (error) - { - TOOL_LOG(INFO) << LOG_DESC("fetchSystemConfig failed, use default value") - << LOG_KV("code", error->errorCode()) << LOG_KV("msg", error->errorMessage()) - << LOG_KV("key", _key) << LOG_KV("defaultValue", std::get<0>(_defaultValue)); - return _defaultValue; - } - return std::get(ret); -} - -ConsensusNodeListPtr LedgerConfigFetcher::fetchNodeListByNodeType(std::string_view _type) -{ - std::promise> nodeListPromise; - m_ledger->asyncGetNodeListByType( - _type, [&nodeListPromise](Error::Ptr _error, ConsensusNodeListPtr _nodes) { - nodeListPromise.set_value({std::move(_error), std::move(_nodes)}); - }); - auto ret = nodeListPromise.get_future().get(); - auto error = ret.first; - if (error) - { - TOOL_LOG(WARNING) << LOG_DESC("fetchNodeListByNodeType failed") << LOG_KV("type", _type) - << LOG_KV("code", error->errorCode()) - << LOG_KV("msg", error->errorMessage()); - BOOST_THROW_EXCEPTION(LedgerConfigFetcherException() << errinfo_comment( - "LedgerConfigFetcher: fetchNodeListByNodeType of type " + - std::string{_type} + " failed")); - } - return ret.second; -} - -void LedgerConfigFetcher::fetchConsensusNodeList() -{ - auto consensusNodeList = fetchNodeListByNodeType(CONSENSUS_SEALER); - TOOL_LOG(INFO) << LOG_DESC("fetchConsensusNodeList success") - << LOG_KV("size", consensusNodeList->size()); - m_ledgerConfig->setConsensusNodeList(*consensusNodeList); -} - -void LedgerConfigFetcher::fetchObserverNodeList() -{ - auto observerList = fetchNodeListByNodeType(CONSENSUS_OBSERVER); - TOOL_LOG(INFO) << LOG_DESC("fetchObserverNodeList success") - << LOG_KV("size", observerList->size()); - m_ledgerConfig->setObserverNodeList(*observerList); -} - -void LedgerConfigFetcher::fetchConsensusLeaderPeriod() -{ - auto ret = fetchSystemConfig(SYSTEM_KEY_CONSENSUS_LEADER_PERIOD); - TOOL_LOG(INFO) << LOG_DESC("fetchConsensusLeaderPeriod success") << LOG_KV("value", ret); - m_ledgerConfig->setLeaderSwitchPeriod(boost::lexical_cast(ret)); -} - -void LedgerConfigFetcher::fetchFeatures() -{ - Features features; - for (auto const& key : Features::featureKeys()) - { - auto value = fetchSystemConfigNoException(key, {"0", 0}); - if (std::get<0>(value) == "1") - { - features.set(key); - } - } - m_ledgerConfig->setFeatures(features); -} - -void LedgerConfigFetcher::fetchCandidateSealerList() -{ - if (m_ledgerConfig->compatibilityVersion() < protocol::BlockVersion::V3_5_VERSION) - { - return; - } - auto sealerList = fetchNodeListByNodeType(CONSENSUS_CANDIDATE_SEALER); - TOOL_LOG(INFO) << LOG_DESC("fetchCandidateSealerList success") - << LOG_KV("size", sealerList->size()); - m_ledgerConfig->setCandidateSealerNodeList(*sealerList); -} - -void LedgerConfigFetcher::fetchBlockTxCountLimit() -{ - auto ret = fetchSystemConfig(SYSTEM_KEY_TX_COUNT_LIMIT); - TOOL_LOG(INFO) << LOG_DESC("fetchBlockTxCountLimit success") << LOG_KV("value", ret); - m_ledgerConfig->setBlockTxCountLimit(boost::lexical_cast(ret)); -} - -void LedgerConfigFetcher::fetchNonceList(BlockNumber _startNumber, int64_t _offset) -{ - std::promise>>> - noncePromise; - m_ledger->asyncGetNonceList(_startNumber, _offset, - [&noncePromise]( - Error::Ptr _error, std::shared_ptr> _nonceList) { - noncePromise.set_value(std::make_pair(_error, _nonceList)); - }); - auto ret = noncePromise.get_future().get(); - auto error = ret.first; - if (error) - { - TOOL_LOG(WARNING) << LOG_DESC("LedgerConfigFetcher: fetchNonceList failed") - << LOG_KV("code", error->errorCode()) - << LOG_KV("msg", error->errorMessage()) - << LOG_KV("startNumber", _startNumber) << LOG_KV("offset", _offset); - BOOST_THROW_EXCEPTION(LedgerConfigFetcherException() << errinfo_comment( - "LedgerConfigFetcher: fetchNonceList failed, start: " + - boost::lexical_cast(_startNumber) + - ", offset:" + boost::lexical_cast(_offset))); - } - m_nonceList = ret.second; -} - -void LedgerConfigFetcher::fetchCompatibilityVersion() -{ - TOOL_LOG(INFO) << LOG_DESC("fetchCompatibilityVersion"); - auto versionStr = fetchSystemConfig(SYSTEM_KEY_COMPATIBILITY_VERSION); - if (versionStr.empty()) - { - m_ledgerConfig->setCompatibilityVersion((uint32_t)(bcos::protocol::DEFAULT_VERSION)); - TOOL_LOG(INFO) << LOG_DESC("fetchCompatibilityVersion: empty version, use " + - bcos::protocol::DEFAULT_VERSION_STR + " as default version."); - return; - } - auto version = toVersionNumber(versionStr); - m_ledgerConfig->setCompatibilityVersion(version); - TOOL_LOG(INFO) << LOG_DESC("fetchCompatibilityVersion success") << LOG_KV("version", versionStr) - << LOG_KV("versionNumber", version) - << LOG_KV("minSupportedVersion", g_BCOSConfig.minSupportedVersion()) - << LOG_KV("maxSupportedVersion", g_BCOSConfig.maxSupportedVersion()); -} - -void LedgerConfigFetcher::fetchAuthCheckStatus() -{ - if (versionCompareTo(m_ledgerConfig->compatibilityVersion(), BlockVersion::V3_3_VERSION) < 0) - { - return; - } - try - { - auto ret = fetchSystemConfig(SYSTEM_KEY_AUTH_CHECK_STATUS); - TOOL_LOG(INFO) << LOG_DESC("fetchAuthCheckStatus success") << LOG_KV("value", ret); - m_ledgerConfig->setAuthCheckStatus(boost::lexical_cast(ret)); - } - catch (...) - { - TOOL_LOG(INFO) << LOG_DESC("fetchAuthCheckStatus failed, set default value UINT32_MAX."); - m_ledgerConfig->setAuthCheckStatus(UINT32_MAX); - } -} - -void LedgerConfigFetcher::fetchEpochBlockNum() -{ - if (m_ledgerConfig->compatibilityVersion() < BlockVersion::V3_5_VERSION) - { - return; - } - auto ret = fetchSystemConfigNoException(ledger::SYSTEM_KEY_RPBFT_EPOCH_BLOCK_NUM, {"1000", 0}); - TOOL_LOG(INFO) << LOG_DESC("fetchEpochBlockNum success") << LOG_KV("value", std::get<0>(ret)); - m_ledgerConfig->setEpochBlockNum({boost::lexical_cast(std::get<0>(ret)), - boost::lexical_cast(std::get<1>(ret))}); -} - -void LedgerConfigFetcher::fetchEpochSealerNum() -{ - if (m_ledgerConfig->compatibilityVersion() < BlockVersion::V3_5_VERSION) - { - return; - } - auto ret = fetchSystemConfigNoException(ledger::SYSTEM_KEY_RPBFT_EPOCH_SEALER_NUM, {"4", 0}); - TOOL_LOG(INFO) << LOG_DESC("fetchEpochSealerNum success") << LOG_KV("value", std::get<0>(ret)); - m_ledgerConfig->setEpochSealerNum({boost::lexical_cast(std::get<0>(ret)), - boost::lexical_cast(std::get<1>(ret))}); -} - -void LedgerConfigFetcher::fetchNotifyRotateFlagInfo() -{ - if (m_ledgerConfig->compatibilityVersion() < BlockVersion::V3_5_VERSION) - { - return; - } - auto ret = fetchSystemConfigNoException(ledger::INTERNAL_SYSTEM_KEY_NOTIFY_ROTATE, {"0", 0}); - TOOL_LOG(INFO) << LOG_DESC("fetchNotifyRotateFlagInfo success") - << LOG_KV("value", std::get<0>(ret)); - m_ledgerConfig->setNotifyRotateFlagInfo(boost::lexical_cast(std::get<0>(ret))); -} - -void LedgerConfigFetcher::fetchChainId() -{ - auto [chainIdStr, _] = fetchSystemConfigNoException(SYSTEM_KEY_WEB3_CHAIN_ID, {"0", 0}); - try - { - auto chainId = boost::lexical_cast(chainIdStr); - TOOL_LOG(INFO) << LOG_DESC("fetchChainId success") << LOG_KV("chainId", chainIdStr); - m_ledgerConfig->setChainId(bcos::toEvmC(chainId)); - } - catch (...) - { - TOOL_LOG(TRACE) << LOG_DESC("fetchChainId failed") << LOG_KV("chainId", chainIdStr); - evmc_uint256be chainId{}; - m_ledgerConfig->setChainId(std::move(chainId)); - } -} \ No newline at end of file diff --git a/bcos-tool/bcos-tool/LedgerConfigFetcher.h b/bcos-tool/bcos-tool/LedgerConfigFetcher.h deleted file mode 100644 index 62bddb72c6..0000000000 --- a/bcos-tool/bcos-tool/LedgerConfigFetcher.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (C) 2021 FISCO BCOS. - * SPDX-License-Identifier: Apache-2.0 - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * @brief Public function to get information from Ledger - * @file LedgerConfigFetcher.h - * @author: yujiechen - * @date 2021-05-19 - */ -#pragma once -#include "bcos-framework/ledger/LedgerConfig.h" -#include "bcos-framework/ledger/LedgerInterface.h" -#include - -#include - -#define TOOL_LOG(LEVEL) BCOS_LOG(LEVEL) << LOG_BADGE("TOOL") - -namespace bcos::tool -{ -class LedgerConfigFetcher : public std::enable_shared_from_this -{ -public: - using Ptr = std::shared_ptr; - explicit LedgerConfigFetcher(bcos::ledger::LedgerInterface::Ptr _ledger) - : m_ledger(std::move(_ledger)), m_ledgerConfig(std::make_shared()) - {} - - virtual ~LedgerConfigFetcher() = default; - - virtual void fetchAll(); - virtual void fetchBlockNumber(); - virtual void fetchBlockNumberAndHash(); - virtual void fetchConsensusNodeList(); - virtual void fetchObserverNodeList(); - virtual void fetchCandidateSealerList(); - virtual void fetchBlockTxCountLimit(); - virtual void fetchGenesisHash(); - virtual void fetchNonceList(protocol::BlockNumber _startNumber, int64_t _offset); - virtual void fetchConsensusLeaderPeriod(); - virtual void fetchFeatures(); - virtual void fetchCompatibilityVersion(); - virtual void fetchAuthCheckStatus(); - virtual void fetchEpochSealerNum(); - virtual void fetchEpochBlockNum(); - virtual void fetchNotifyRotateFlagInfo(); - virtual bcos::crypto::HashType fetchBlockHash(bcos::protocol::BlockNumber _blockNumber); - virtual void fetchChainId(); - - // consensus_leader_period - virtual bcos::ledger::LedgerConfig::Ptr ledgerConfig() { return m_ledgerConfig; } - virtual std::shared_ptr> nonceList() - { - return m_nonceList; - } - - virtual bcos::crypto::HashType const& genesisHash() const { return m_genesisHash; } - - -protected: - virtual std::string fetchSystemConfig(std::string_view _key); - virtual ledger::SystemConfigEntry fetchSystemConfigNoException( - std::string_view _key, ledger::SystemConfigEntry _defaultValue) noexcept; - virtual bcos::consensus::ConsensusNodeListPtr fetchNodeListByNodeType(std::string_view _type); - - bcos::ledger::LedgerInterface::Ptr m_ledger; - bcos::ledger::LedgerConfig::Ptr m_ledgerConfig; - std::shared_ptr> m_nonceList; - bcos::crypto::HashType m_genesisHash; -}; -} // namespace bcos::tool \ No newline at end of file diff --git a/bcos-tool/test/CMakeLists.txt b/bcos-tool/test/CMakeLists.txt index 49422c74f5..a37e5b115b 100644 --- a/bcos-tool/test/CMakeLists.txt +++ b/bcos-tool/test/CMakeLists.txt @@ -23,6 +23,8 @@ find_package(Boost REQUIRED unit_test_framework) add_executable(${TEST_BINARY_NAME} ${SOURCES}) target_include_directories(${TEST_BINARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") target_link_libraries(${TEST_BINARY_NAME} PUBLIC ${TOOL_TARGET} ${CRYPTO_TARGET} Boost::unit_test_framework) add_test(NAME ${TEST_BINARY_NAME} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) \ No newline at end of file diff --git a/bcos-txpool/test/CMakeLists.txt b/bcos-txpool/test/CMakeLists.txt index d74237bd57..151d442a0e 100644 --- a/bcos-txpool/test/CMakeLists.txt +++ b/bcos-txpool/test/CMakeLists.txt @@ -30,5 +30,7 @@ find_package(Boost REQUIRED unit_test_framework) target_link_libraries(${TEST_BINARY_NAME} ${TXPOOL_TARGET} ${LEDGER_TARGET} bcos-crypto ${TARS_PROTOCOL_TARGET} Boost::unit_test_framework) target_link_libraries(${DEMO_BINARY_NAME} ${TXPOOL_TARGET} ${LEDGER_TARGET} bcos-crypto ${TARS_PROTOCOL_TARGET} Boost::unit_test_framework) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") #add_test(NAME test-txpool WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) config_test_cases("" "${SOURCES}" ${TEST_BINARY_NAME} "") \ No newline at end of file diff --git a/bcos-utilities/test/CMakeLists.txt b/bcos-utilities/test/CMakeLists.txt index d4df30b52a..9168c10ac0 100644 --- a/bcos-utilities/test/CMakeLists.txt +++ b/bcos-utilities/test/CMakeLists.txt @@ -22,9 +22,10 @@ set(TEST_BINARY_NAME test-bcos-utilities) find_package(Boost REQUIRED COMPONENTS unit_test_framework) find_package(TBB REQUIRED) - add_executable(${TEST_BINARY_NAME} ${SOURCES}) target_include_directories(${TEST_BINARY_NAME} PRIVATE . ${CMAKE_SOURCE_DIR}) target_link_libraries(${TEST_BINARY_NAME} bcos-utilities Boost::unit_test_framework TBB::tbb) +set_source_files_properties("unittests/main/main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_target_properties(${TEST_BINARY_NAME} PROPERTIES UNITY_BUILD "ON") add_test(NAME ${TEST_BINARY_NAME} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND ${TEST_BINARY_NAME}) diff --git a/bcos-utilities/testutils/TestPromptFixture.h b/bcos-utilities/testutils/TestPromptFixture.h index 40e9978fc7..9a7859f9ca 100644 --- a/bcos-utilities/testutils/TestPromptFixture.h +++ b/bcos-utilities/testutils/TestPromptFixture.h @@ -23,9 +23,8 @@ #include #include -namespace bcos -{ -namespace test + +namespace bcos::test { inline bcos::bytes operator""_bytes(const char* s) noexcept { @@ -98,5 +97,4 @@ class TestPromptFixture // release test-suite fixture ~TestPromptFixture() { TestPrompt::get().finishTest(); } }; -} // namespace test -} // namespace bcos +} // namespace bcos::test diff --git a/cmake/ProjectTOMLPP.cmake b/cmake/ProjectTOMLPP.cmake new file mode 100644 index 0000000000..1e6b324a2c --- /dev/null +++ b/cmake/ProjectTOMLPP.cmake @@ -0,0 +1,15 @@ +include(ExternalProject) + +ExternalProject_Add(tomlplusplus_project + PREFIX ${CMAKE_SOURCE_DIR}/deps + DOWNLOAD_NO_PROGRESS 1 + GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git + GIT_TAG 30172438cee64926dc41fdd9c11fb3ba5b2ba9de + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= +) + +ExternalProject_Get_Property(tomlplusplus_project INSTALL_DIR) +add_library(tomlplusplus INTERFACE IMPORTED GLOBAL) +set_property(TARGET tomlplusplus PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) +add_dependencies(tomlplusplus tomlplusplus_project) +unset(INSTALL_DIR) \ No newline at end of file diff --git a/fisco-bcos-tars-service/RpcService/main/CMakeLists.txt b/fisco-bcos-tars-service/RpcService/main/CMakeLists.txt index b81b6cbb0c..dca902845b 100644 --- a/fisco-bcos-tars-service/RpcService/main/CMakeLists.txt +++ b/fisco-bcos-tars-service/RpcService/main/CMakeLists.txt @@ -8,7 +8,7 @@ find_package(Boost REQUIRED program_options) aux_source_directory(../ SRC_LIST) add_executable(${RPC_BINARY_NAME} ${SRC_LIST}) if(WITH_TIKV) - target_link_libraries(${RPC_BINARY_NAME} ${PROTOCOL_INIT_LIB} ${RPC_TARGET} ${TOOL_TARGET} ${PROTOCOL_INIT_LIB} ${COMMAND_HELPER_LIB} ${LEADER_ELECTION_TARGET}) + target_link_libraries(${RPC_BINARY_NAME} ${PROTOCOL_INIT_LIB} ${RPC_TARGET} ${LEDGER_TARGET} ${TOOL_TARGET} ${PROTOCOL_INIT_LIB} ${COMMAND_HELPER_LIB} ${LEADER_ELECTION_TARGET}) else() - target_link_libraries(${RPC_BINARY_NAME} ${PROTOCOL_INIT_LIB} ${RPC_TARGET} ${TOOL_TARGET} ${PROTOCOL_INIT_LIB} ${COMMAND_HELPER_LIB}) + target_link_libraries(${RPC_BINARY_NAME} ${PROTOCOL_INIT_LIB} ${RPC_TARGET} ${LEDGER_TARGET} ${TOOL_TARGET} ${PROTOCOL_INIT_LIB} ${COMMAND_HELPER_LIB}) endif() \ No newline at end of file diff --git a/libinitializer/CMakeLists.txt b/libinitializer/CMakeLists.txt index 7f464e1d2d..ff9e108cdb 100644 --- a/libinitializer/CMakeLists.txt +++ b/libinitializer/CMakeLists.txt @@ -20,19 +20,12 @@ endif() add_library(${TXPOOL_INIT_LIB} TxPoolInitializer.cpp) target_link_libraries(${TXPOOL_INIT_LIB} PUBLIC ${PROTOCOL_INIT_LIB} ${TOOL_TARGET} ${TXPOOL_TARGET}) -include(FetchContent) -FetchContent_Declare( - tomlplusplus - URL https://github.com/marzer/tomlplusplus/archive/refs/tags/v3.4.0.tar.gz - URL_HASH MD5=c1f32ced14311fe949b9ce7cc3f7a867 -) -FetchContent_MakeAvailable(tomlplusplus) add_library(baseline_init BaselineSchedulerInitializer.cpp) target_link_libraries(baseline_init transaction-scheduler transaction-executor ${STORAGE_TARGET}) add_library(${INIT_LIB} Initializer.cpp) -list(APPEND INIT_LIB_DEPENDS ${PROTOCOL_INIT_LIB} baseline_init ${FRONTSERVICE_INIT_LIB} ${TXPOOL_INIT_LIB} ${SCHEDULER_TARGET} ${STORAGE_TARGET} ${EXECUTOR_TARGET} ${RPC_TARGET} bcos-boostssl tomlplusplus::tomlplusplus) +list(APPEND INIT_LIB_DEPENDS ${PROTOCOL_INIT_LIB} baseline_init ${FRONTSERVICE_INIT_LIB} ${TXPOOL_INIT_LIB} ${SCHEDULER_TARGET} ${STORAGE_TARGET} ${EXECUTOR_TARGET} ${RPC_TARGET} bcos-boostssl tomlplusplus) if(WITH_TIKV) list(APPEND INIT_LIB_DEPENDS ${LEADER_ELECTION_TARGET}) endif() @@ -42,5 +35,6 @@ if(WITH_LIGHTNODE) list(APPEND INIT_LIB_DEPENDS lightnodeinit bcos-concepts) endif() target_link_libraries(${INIT_LIB} PUBLIC ${INIT_LIB_DEPENDS}) + set_target_properties(${INIT_LIB} PROPERTIES UNITY_BUILD "ON") add_dependencies(${INIT_LIB} BuildInfo.h) diff --git a/tools/archive-tool/archiveTool.cpp b/tools/archive-tool/archiveTool.cpp index 4e2df94b65..c1f289f99a 100644 --- a/tools/archive-tool/archiveTool.cpp +++ b/tools/archive-tool/archiveTool.cpp @@ -22,7 +22,6 @@ #include "bcos-framework/ledger/LedgerTypeDef.h" #include "bcos-framework/storage/StorageInterface.h" #include "bcos-ledger/src/libledger/Ledger.h" -#include "bcos-ledger/src/libledger/utilities/Common.h" #include "bcos-rpc/jsonrpc/JsonRpcImpl_2_0.h" #include "bcos-storage/bcos-storage/TiKVStorage.h" #include "bcos-tars-protocol/bcos-tars-protocol/protocol/TransactionImpl.h" @@ -350,8 +349,7 @@ void archiveBlocks(auto archiveStorage, auto ledger, [](const std::string& str) { return std::string_view{str}; }), receiptValues | RANGES::views::transform( [](const std::string& str) { return std::string_view{str}; })); - std::cout << "\r" - << "write block " << i << " size: " << size << std::flush; + std::cout << "\r" << "write block " << i << " size: " << size << std::flush; } std::cout << std::endl << "write to archive database, block range [" << startBlockNumber << "," @@ -548,8 +546,8 @@ void reimportBlocks(auto archiveStorage, TransactionalStorageInterface::Ptr loca }); // write receipt to local storage localBlockStorage->setRows(ledger::SYS_HASH_2_RECEIPT, txHashes, receiptsView); - std::cout << "\r" - << "reimport block " << blockNumber << " size: " << txHashes.size() << std::flush; + std::cout << "\r" << "reimport block " << blockNumber << " size: " << txHashes.size() + << std::flush; } // }); std::cout << std::endl diff --git a/tools/storage-tool/storageTool.cpp b/tools/storage-tool/storageTool.cpp index 789361de24..09b772edeb 100644 --- a/tools/storage-tool/storageTool.cpp +++ b/tools/storage-tool/storageTool.cpp @@ -21,7 +21,6 @@ #include "bcos-framework/ledger/LedgerTypeDef.h" #include "bcos-framework/storage/StorageInterface.h" -#include "bcos-ledger/src/libledger/utilities/Common.h" #include "bcos-tars-protocol/protocol/TransactionImpl.h" #include "bcos-tool/bcos-tool/BfsFileFactory.h" #include "bcos-utilities/BoostLogInitializer.h" @@ -156,8 +155,8 @@ StateStorageInterface::Ptr createKeyPageStorage( void print( std::string_view tableName, std::string_view key, std::string_view value, bool hex = false) { - cout << "[tableName=" << tableName << "]" - << " [key=" << key << "] [value=" << (hex ? toHex(value) : value) << "]" << endl; + cout << "[tableName=" << tableName << "]" << " [key=" << key + << "] [value=" << (hex ? toHex(value) : value) << "]" << endl; } void writeKV(std::ofstream& output, std::string_view key, std::string_view value, bool hex = false) diff --git a/transaction-executor/benchmark/CMakeLists.txt b/transaction-executor/benchmark/CMakeLists.txt index ee76dbfc76..2b79169d4a 100644 --- a/transaction-executor/benchmark/CMakeLists.txt +++ b/transaction-executor/benchmark/CMakeLists.txt @@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCES "*.cpp") add_executable(benchmark-transaction-executor ${SOURCES}) find_package(benchmark REQUIRED) -target_link_libraries(benchmark-transaction-executor transaction-executor - ${TARS_PROTOCOL_TARGET} bcos-framework evmone benchmark::benchmark benchmark::benchmark_main) \ No newline at end of file +target_link_libraries(benchmark-transaction-executor transaction-executor ${EXECUTOR_TARGET} + ${TARS_PROTOCOL_TARGET} ${LEDGER_TARGET} bcos-framework evmone benchmark::benchmark benchmark::benchmark_main) \ No newline at end of file diff --git a/transaction-executor/tests/CMakeLists.txt b/transaction-executor/tests/CMakeLists.txt index 234f27ef1b..069ff4ba87 100644 --- a/transaction-executor/tests/CMakeLists.txt +++ b/transaction-executor/tests/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(test-transaction-executor ${SOURCES}) find_package(Boost REQUIRED serialization unit_test_framework) -target_link_libraries(test-transaction-executor transaction-executor ${LEDGER_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework evmone Boost::unit_test_framework) +target_link_libraries(test-transaction-executor transaction-executor ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework evmone Boost::unit_test_framework) set_source_files_properties("main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) set_target_properties(test-transaction-executor PROPERTIES UNITY_BUILD "ON") add_test(NAME test-transaction-executor WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND test-transaction-executor) \ No newline at end of file diff --git a/transaction-scheduler/benchmark/CMakeLists.txt b/transaction-scheduler/benchmark/CMakeLists.txt index 80106a595f..cfd8842247 100644 --- a/transaction-scheduler/benchmark/CMakeLists.txt +++ b/transaction-scheduler/benchmark/CMakeLists.txt @@ -1,7 +1,7 @@ find_package(benchmark REQUIRED) add_executable(benchmark-multilayer-storage benchmarkMultiLayerStorage.cpp) -target_link_libraries(benchmark-multilayer-storage transaction-scheduler transaction-executor ${TARS_PROTOCOL_TARGET} bcos-framework benchmark::benchmark benchmark::benchmark_main) +target_link_libraries(benchmark-multilayer-storage PRIVATE transaction-scheduler transaction-executor ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework benchmark::benchmark benchmark::benchmark_main) add_executable(benchmark-scheduler benchmarkScheduler.cpp) -target_link_libraries(benchmark-scheduler transaction-scheduler transaction-executor ${STORAGE_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework benchmark::benchmark benchmark::benchmark_main) \ No newline at end of file +target_link_libraries(benchmark-scheduler PRIVATE transaction-scheduler transaction-executor ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${STORAGE_TARGET} ${TARS_PROTOCOL_TARGET} bcos-framework benchmark::benchmark benchmark::benchmark_main) \ No newline at end of file diff --git a/transaction-scheduler/tests/CMakeLists.txt b/transaction-scheduler/tests/CMakeLists.txt index e5ab2461bb..9316bdff81 100644 --- a/transaction-scheduler/tests/CMakeLists.txt +++ b/transaction-scheduler/tests/CMakeLists.txt @@ -3,7 +3,7 @@ file(GLOB_RECURSE SOURCES "*.cpp") add_executable(test-transaction-scheduler ${SOURCES}) find_package(Boost REQUIRED serialization unit_test_framework) -target_link_libraries(test-transaction-scheduler transaction-scheduler ${EXECUTOR_TARGET} ${TARS_PROTOCOL_TARGET} ${TABLE_TARGET} bcos-framework Boost::unit_test_framework) +target_link_libraries(test-transaction-scheduler transaction-scheduler ${EXECUTOR_TARGET} ${LEDGER_TARGET} ${TARS_PROTOCOL_TARGET} ${TABLE_TARGET} bcos-framework Boost::unit_test_framework) set_source_files_properties("main.cpp" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) set_target_properties(test-transaction-scheduler PROPERTIES UNITY_BUILD "ON") add_test(NAME test-transaction-scheduler WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} COMMAND test-transaction-scheduler)