diff --git a/CMakeModules/cpp_graphql_gen.cmake b/CMakeModules/cpp_graphql_gen.cmake index 1ee15d1f86..74fbabdcf3 100644 --- a/CMakeModules/cpp_graphql_gen.cmake +++ b/CMakeModules/cpp_graphql_gen.cmake @@ -6,7 +6,7 @@ set(Boost_NO_WARN_NEW_VERSIONS 1) FetchContent_Declare( cppgraphqlgen GIT_REPOSITORY https://github.com/microsoft/cppgraphqlgen.git - GIT_TAG 8c1623acc42392ef2a1bc0336482621386f98c77 # v4.5.0 + GIT_TAG 1d659227bfc51fb7d9bb5dc9862234e7cfd1b1e3 # v4.5.4 ) set(GRAPHQL_BUILD_TESTS OFF) set(GRAPHQL_UPDATE_VERSION OFF) diff --git a/libraries/core_libs/network/graphql/include/graphql/types/dag_block.hpp b/libraries/core_libs/network/graphql/include/graphql/types/dag_block.hpp index 6ef037d513..3bb2f1a6a8 100644 --- a/libraries/core_libs/network/graphql/include/graphql/types/dag_block.hpp +++ b/libraries/core_libs/network/graphql/include/graphql/types/dag_block.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include "DagBlockObject.h" #include "final_chain/final_chain.hpp" #include "pbft/pbft_manager.hpp" @@ -34,6 +36,7 @@ class DagBlock { std::shared_ptr<::taraxa::TransactionManager> transaction_manager_; std::function(::taraxa::EthBlockNumber)> get_block_by_num_; + mutable std::mutex mu_; mutable std::optional period_; }; diff --git a/libraries/core_libs/network/graphql/src/query.cpp b/libraries/core_libs/network/graphql/src/query.cpp index 9afae748f1..a64245a567 100644 --- a/libraries/core_libs/network/graphql/src/query.cpp +++ b/libraries/core_libs/network/graphql/src/query.cpp @@ -43,8 +43,14 @@ std::shared_ptr Query::getBlock(std::optional&& } if (hash) { block_number = final_chain_->block_number(dev::h256(hash->get())); + if (!block_number) { + return nullptr; + } } auto block_header = final_chain_->block_header(block_number); + if (!block_header) { + return nullptr; + } auto pbft_block = db_->getPbftBlock(block_header->number); if (!pbft_block) { diff --git a/libraries/core_libs/network/graphql/src/types/dag_block.cpp b/libraries/core_libs/network/graphql/src/types/dag_block.cpp index a9b1c78a81..0d6d9d9721 100644 --- a/libraries/core_libs/network/graphql/src/types/dag_block.cpp +++ b/libraries/core_libs/network/graphql/src/types/dag_block.cpp @@ -37,6 +37,7 @@ response::Value DagBlock::getLevel() const noexcept { } std::optional DagBlock::getPbftPeriod() const noexcept { + std::lock_guard lock{mu_}; if (period_) { return response::Value(static_cast(*period_)); } @@ -49,6 +50,7 @@ std::optional DagBlock::getPbftPeriod() const noexcept { } std::shared_ptr DagBlock::getAuthor() const noexcept { + std::lock_guard lock{mu_}; if (!period_) { const auto [has_period, period] = pbft_manager_->getDagBlockPeriod(::taraxa::blk_hash_t(dag_block_->getHash())); if (has_period) {