Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master -> develop #2903

Merged
merged 8 commits into from
Dec 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add size to the blocks in the rpc
  • Loading branch information
kstdl committed Nov 11, 2024
commit 38bb5b412d7e079f6ef23818193dca1eea597930
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
@@ -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 {
@@ -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;
};
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
@@ -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)

Original file line number Diff line number Diff line change
@@ -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 {};
}
1 change: 1 addition & 0 deletions libraries/core_libs/network/rpc/eth/Eth.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

Loading