From 5447d85383aafa9be6f9587fbadc178de518ec5b Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Wed, 31 Jul 2024 08:48:12 -0700 Subject: [PATCH 1/3] do not parse extra data in case it is empty --- libraries/types/pbft_block/src/pbft_block.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/types/pbft_block/src/pbft_block.cpp b/libraries/types/pbft_block/src/pbft_block.cpp index 54dadeca97..a3f38f8540 100644 --- a/libraries/types/pbft_block/src/pbft_block.cpp +++ b/libraries/types/pbft_block/src/pbft_block.cpp @@ -15,7 +15,9 @@ 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); + if (!extra_data_bytes.empty()) { + extra_data_ = PbftBlockExtraData(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_); From 38f7f925f855dc5fac881d5f33055781e52b592d Mon Sep 17 00:00:00 2001 From: Jakub Fornadel Date: Wed, 31 Jul 2024 08:55:10 -0700 Subject: [PATCH 2/3] increase minor version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}) From 49ad9c09d3f9726c0ed531c9a53073e7d4d17507 Mon Sep 17 00:00:00 2001 From: kstdl Date: Wed, 31 Jul 2024 18:56:15 +0200 Subject: [PATCH 3/3] fix: make empty extra data on RLP exception --- .../include/pbft/pbft_block_extra_data.hpp | 3 ++- libraries/types/pbft_block/src/pbft_block.cpp | 6 +----- .../pbft_block/src/pbft_block_extra_data.cpp | 18 +++++++++++------- 3 files changed, 14 insertions(+), 13 deletions(-) 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 a3f38f8540..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,9 +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_); - if (!extra_data_bytes.empty()) { - 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 {