Skip to content

Commit

Permalink
Merge pull request #2819 from Taraxa-project/hotfix/fix_extra_data_pa…
Browse files Browse the repository at this point in the history
…rsing

do not parse extra data in case it is empty
  • Loading branch information
rattrap authored Jul 31, 2024
2 parents 9c3314f + 49ad9c0 commit 3517f00
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<blk_hash_t>& pillar_block_hash);
PbftBlockExtraData(const bytes& data);

static std::optional<PbftBlockExtraData> fromBytes(const bytes& data);

/**
* @brief Get rlp
Expand Down
4 changes: 1 addition & 3 deletions libraries/types/pbft_block/src/pbft_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <iostream>

#include "common/jsoncpp.hpp"

namespace taraxa {

PbftBlock::PbftBlock(bytes const& b) : PbftBlock(dev::RLP(b)) {}
Expand All @@ -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_);
Expand Down
18 changes: 11 additions & 7 deletions libraries/types/pbft_block/src/pbft_block_extra_data.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "pbft/pbft_block_extra_data.hpp"

#include <iostream>

#include "common/jsoncpp.hpp"

namespace taraxa {

PbftBlockExtraData::PbftBlockExtraData(const uint16_t major_version, const uint16_t minor_version,
Expand All @@ -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> 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 {
Expand Down

0 comments on commit 3517f00

Please sign in to comment.