diff --git a/CMakeLists.txt b/CMakeLists.txt index f768281ce2..c92644a850 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.20) # Set current version of the project set(TARAXA_MAJOR_VERSION 1) -set(TARAXA_MINOR_VERSION 10) +set(TARAXA_MINOR_VERSION 11) set(TARAXA_PATCH_VERSION 0) set(TARAXA_VERSION ${TARAXA_MAJOR_VERSION}.${TARAXA_MINOR_VERSION}.${TARAXA_PATCH_VERSION}) diff --git a/libraries/types/pbft_block/include/pbft/pbft_block_extra_data.hpp b/libraries/types/pbft_block/include/pbft/pbft_block_extra_data.hpp index ba1bd9e4d7..765069b45d 100644 --- a/libraries/types/pbft_block/include/pbft/pbft_block_extra_data.hpp +++ b/libraries/types/pbft_block/include/pbft/pbft_block_extra_data.hpp @@ -21,7 +21,8 @@ class PbftBlockExtraData { PbftBlockExtraData(const uint16_t major_version, const uint16_t minor_version, const uint16_t patch_version, const uint16_t net_version, const std::string node_implementation, const std::optional& pillar_block_hash); - PbftBlockExtraData(const bytes& data); + + static std::optional fromBytes(const bytes& data); /** * @brief Get rlp diff --git a/libraries/types/pbft_block/src/pbft_block.cpp b/libraries/types/pbft_block/src/pbft_block.cpp index 54dadeca97..e0deec66e0 100644 --- a/libraries/types/pbft_block/src/pbft_block.cpp +++ b/libraries/types/pbft_block/src/pbft_block.cpp @@ -4,8 +4,6 @@ #include -#include "common/jsoncpp.hpp" - namespace taraxa { PbftBlock::PbftBlock(bytes const& b) : PbftBlock(dev::RLP(b)) {} @@ -15,7 +13,7 @@ PbftBlock::PbftBlock(dev::RLP const& rlp) { dev::bytes extra_data_bytes; util::rlp_tuple(util::RLPDecoderRef(rlp, true), prev_block_hash_, dag_block_hash_as_pivot_, order_hash_, prev_state_root_hash_, period_, timestamp_, reward_votes_, extra_data_bytes, signature_); - extra_data_ = PbftBlockExtraData(extra_data_bytes); + extra_data_ = PbftBlockExtraData::fromBytes(extra_data_bytes); } else { util::rlp_tuple(util::RLPDecoderRef(rlp, true), prev_block_hash_, dag_block_hash_as_pivot_, order_hash_, prev_state_root_hash_, period_, timestamp_, reward_votes_, signature_); diff --git a/libraries/types/pbft_block/src/pbft_block_extra_data.cpp b/libraries/types/pbft_block/src/pbft_block_extra_data.cpp index 215dab37cb..6a14c99c61 100644 --- a/libraries/types/pbft_block/src/pbft_block_extra_data.cpp +++ b/libraries/types/pbft_block/src/pbft_block_extra_data.cpp @@ -1,9 +1,5 @@ #include "pbft/pbft_block_extra_data.hpp" -#include - -#include "common/jsoncpp.hpp" - namespace taraxa { PbftBlockExtraData::PbftBlockExtraData(const uint16_t major_version, const uint16_t minor_version, @@ -17,14 +13,22 @@ PbftBlockExtraData::PbftBlockExtraData(const uint16_t major_version, const uint1 node_implementation_(node_implementation), pillar_block_hash_(pillar_block_hash) {} -PbftBlockExtraData::PbftBlockExtraData(const bytes& data) { +std::optional PbftBlockExtraData::fromBytes(const bytes& data) { if (data.size() > kExtraDataMaxSize) { throw std::runtime_error("Pbft block invalid, extra data size over the limit"); } dev::RLP rlp(data); - util::rlp_tuple(util::RLPDecoderRef(rlp, true), major_version_, minor_version_, patch_version_, net_version_, - node_implementation_, pillar_block_hash_); + PbftBlockExtraData extra_data; + try { + util::rlp_tuple(util::RLPDecoderRef(rlp, true), extra_data.major_version_, extra_data.minor_version_, + extra_data.patch_version_, extra_data.net_version_, extra_data.node_implementation_, + extra_data.pillar_block_hash_); + } catch (const dev::RLPException& e) { + return std::nullopt; + } + + return extra_data; } bytes PbftBlockExtraData::rlp() const {