Skip to content

Commit

Permalink
Merge pull request #2889 from Taraxa-project/block_size
Browse files Browse the repository at this point in the history
feat: add size to the blocks in eth rpc
  • Loading branch information
kstdl authored Nov 11, 2024
2 parents 3ab7678 + 38bb5b4 commit 6b763a2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
15 changes: 8 additions & 7 deletions libraries/core_libs/consensus/include/final_chain/data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
#include <libdevcore/Log.h>
#include <libdevcore/SHA3.h>

#include <algorithm>
#include <memory>

#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 {
Expand Down Expand Up @@ -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<BlockHeader> from_rlp(const dev::RLP& rlp);

void ethereum_rlp(dev::RLPStream& encoding) const;
};
Expand Down
20 changes: 16 additions & 4 deletions libraries/core_libs/consensus/src/final_chain/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@

#include <libdevcore/CommonJS.h>

#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> BlockHeader::from_rlp(const dev::RLP& rlp) {
auto ret = std::make_shared<BlockHeader>();
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,7 @@ const SharedTransactions FinalChainImpl::get_transactions(std::optional<EthBlock

std::shared_ptr<const BlockHeader> 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<BlockHeader>();
ret->rlp(dev::RLP(raw));
return ret;
return BlockHeader::from_rlp(dev::RLP(raw));
}
return {};
}
Expand Down
1 change: 1 addition & 0 deletions libraries/core_libs/network/rpc/eth/Eth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6b763a2

Please sign in to comment.