diff --git a/libraries/core_libs/consensus/include/final_chain/data.hpp b/libraries/core_libs/consensus/include/final_chain/data.hpp index 8c9c1f1105..2ec581b685 100644 --- a/libraries/core_libs/consensus/include/final_chain/data.hpp +++ b/libraries/core_libs/consensus/include/final_chain/data.hpp @@ -5,12 +5,10 @@ #include #include -#include +#include -#include "common/constants.hpp" #include "common/encoding_rlp.hpp" #include "common/types.hpp" -#include "final_chain/state_api_data.hpp" #include "transaction/transaction.hpp" namespace taraxa { @@ -41,16 +39,19 @@ struct BlockHeader { uint64_t timestamp = 0; Address author; u256 total_reward; + uint64_t size = 0; HAS_RLP_FIELDS - static h256 const& uncles_hash(); + static const h256& uncles_hash(); - static Nonce const& nonce(); + static const Nonce& nonce(); - static u256 const& difficulty(); + static const u256& difficulty(); - static h256 const& mix_hash(); + static const h256& mix_hash(); + + static std::shared_ptr from_rlp(const dev::RLP& rlp); void ethereum_rlp(dev::RLPStream& encoding) const; }; diff --git a/libraries/core_libs/consensus/src/final_chain/data.cpp b/libraries/core_libs/consensus/src/final_chain/data.cpp index 73b2525ece..5747ea9ad9 100644 --- a/libraries/core_libs/consensus/src/final_chain/data.cpp +++ b/libraries/core_libs/consensus/src/final_chain/data.cpp @@ -2,16 +2,28 @@ #include +#include "common/constants.hpp" + namespace taraxa::final_chain { -h256 const& BlockHeader::uncles_hash() { return EmptyRLPListSHA3(); } +const h256& BlockHeader::uncles_hash() { return EmptyRLPListSHA3(); } + +const Nonce& BlockHeader::nonce() { return EmptyNonce(); } -Nonce const& BlockHeader::nonce() { return EmptyNonce(); } +const u256& BlockHeader::difficulty() { return ZeroU256(); } -u256 const& BlockHeader::difficulty() { return ZeroU256(); } +const h256& BlockHeader::mix_hash() { return ZeroHash(); } -h256 const& BlockHeader::mix_hash() { return ZeroHash(); } +std::shared_ptr BlockHeader::from_rlp(const dev::RLP& rlp) { + auto ret = std::make_shared(); + ret->rlp(rlp); + dev::RLPStream encoding; + ret->ethereum_rlp(encoding); + ret->size = encoding.out().size(); + return ret; +} +// TODO[2888]: remove hash field to not store it in the db RLP_FIELDS_DEFINE(BlockHeader, hash, parent_hash, author, state_root, transactions_root, receipts_root, log_bloom, number, gas_limit, gas_used, timestamp, total_reward, extra_data) diff --git a/libraries/core_libs/consensus/src/final_chain/final_chai_impl.cpp b/libraries/core_libs/consensus/src/final_chain/final_chai_impl.cpp index 4c77e95324..6e623da3d1 100644 --- a/libraries/core_libs/consensus/src/final_chain/final_chai_impl.cpp +++ b/libraries/core_libs/consensus/src/final_chain/final_chai_impl.cpp @@ -525,9 +525,7 @@ const SharedTransactions FinalChainImpl::get_transactions(std::optional FinalChainImpl::get_block_header(EthBlockNumber n) const { if (auto raw = db_->lookup(n, DB::Columns::final_chain_blk_by_number); !raw.empty()) { - auto ret = std::make_shared(); - ret->rlp(dev::RLP(raw)); - return ret; + return BlockHeader::from_rlp(dev::RLP(raw)); } return {}; } diff --git a/libraries/core_libs/network/rpc/eth/Eth.cpp b/libraries/core_libs/network/rpc/eth/Eth.cpp index 517b7b1fa1..7fcbdc5bc8 100644 --- a/libraries/core_libs/network/rpc/eth/Eth.cpp +++ b/libraries/core_libs/network/rpc/eth/Eth.cpp @@ -68,6 +68,7 @@ Json::Value toJson(const BlockHeader& obj) { res["difficulty"] = "0x0"; res["totalDifficulty"] = "0x0"; res["totalReward"] = toJS(obj.total_reward); + res["size"] = toJS(obj.size); return res; }