From 430af47624121ab925780e42895406482c6a6269 Mon Sep 17 00:00:00 2001 From: Leonard Mocanu Date: Thu, 17 Oct 2024 16:14:13 +0300 Subject: [PATCH 1/3] chore: adds snapshot flag to helm chart --- charts/taraxa-node/Chart.yaml | 2 +- charts/taraxa-node/templates/consensus-node-configmap.yaml | 6 ++++++ .../templates/consensus-node-light-configmap.yaml | 6 ++++++ charts/taraxa-node/templates/taraxa-node-configmap.yaml | 6 ++++++ charts/taraxa-node/values.yaml | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/charts/taraxa-node/Chart.yaml b/charts/taraxa-node/Chart.yaml index 71c559c11b..5e3058df41 100644 --- a/charts/taraxa-node/Chart.yaml +++ b/charts/taraxa-node/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "1.0" description: Kubernetes helm chart for Taraxa blockchain full node implementation. name: taraxa-node -version: 0.3.13 +version: 0.3.14 keywords: - blockchain - taraxa diff --git a/charts/taraxa-node/templates/consensus-node-configmap.yaml b/charts/taraxa-node/templates/consensus-node-configmap.yaml index ba7b05621f..c0715dd1b2 100644 --- a/charts/taraxa-node/templates/consensus-node-configmap.yaml +++ b/charts/taraxa-node/templates/consensus-node-configmap.yaml @@ -167,6 +167,12 @@ data: {{- end }} {{- end }} + {{ if .Values.config.snapshots.enabled }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 1' | jq '.db_config.db_snapshot_each_n_pbft_block = 10000' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- else }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 0' | jq '.db_config.db_snapshot_each_n_pbft_block = 0' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- end }} + echo "***** $CONFIG_PATH *****" cat $CONFIG_PATH echo "***** $CONFIG_PATH *****" diff --git a/charts/taraxa-node/templates/consensus-node-light-configmap.yaml b/charts/taraxa-node/templates/consensus-node-light-configmap.yaml index 7d4adc594c..29d480ac96 100644 --- a/charts/taraxa-node/templates/consensus-node-light-configmap.yaml +++ b/charts/taraxa-node/templates/consensus-node-light-configmap.yaml @@ -167,6 +167,12 @@ data: {{- end }} {{- end }} + {{ if .Values.config.snapshots.enabled }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 1' | jq '.db_config.db_snapshot_each_n_pbft_block = 10000' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- else }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 0' | jq '.db_config.db_snapshot_each_n_pbft_block = 0' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- end }} + echo "***** $CONFIG_PATH *****" cat $CONFIG_PATH echo "***** $CONFIG_PATH *****" diff --git a/charts/taraxa-node/templates/taraxa-node-configmap.yaml b/charts/taraxa-node/templates/taraxa-node-configmap.yaml index e7713f0329..a4a5b7751a 100644 --- a/charts/taraxa-node/templates/taraxa-node-configmap.yaml +++ b/charts/taraxa-node/templates/taraxa-node-configmap.yaml @@ -154,6 +154,12 @@ data: {{- end }} {{- end }} + {{ if .Values.config.snapshots.enabled }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 1' | jq '.db_config.db_snapshot_each_n_pbft_block = 10000' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- else }} + cat $CONFIG_PATH | jq '.db_config.db_max_snapshots = 0' | jq '.db_config.db_snapshot_each_n_pbft_block = 0' > $CONFIG_PATH.tmp && mv $CONFIG_PATH.tmp $CONFIG_PATH + {{- end }} + echo "***** $CONFIG_PATH *****" cat $CONFIG_PATH echo "***** $CONFIG_PATH *****" diff --git a/charts/taraxa-node/values.yaml b/charts/taraxa-node/values.yaml index 6d1fcd19ed..15eaf9f15b 100644 --- a/charts/taraxa-node/values.yaml +++ b/charts/taraxa-node/values.yaml @@ -20,6 +20,8 @@ config: # 100 for default helm test network: "100" extraArgs: [] + snapshots: + enabled: true # Default keys, VRFs and address for kube testing node: From 38bb5b412d7e079f6ef23818193dca1eea597930 Mon Sep 17 00:00:00 2001 From: kstdl Date: Mon, 11 Nov 2024 11:05:04 +0100 Subject: [PATCH 2/3] feat: add size to the blocks in the rpc --- .../consensus/include/final_chain/data.hpp | 15 +++++++------- .../consensus/src/final_chain/data.cpp | 20 +++++++++++++++---- .../src/final_chain/final_chai_impl.cpp | 4 +--- libraries/core_libs/network/rpc/eth/Eth.cpp | 1 + 4 files changed, 26 insertions(+), 14 deletions(-) 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; } From 0855c6e616d28ac152ae7c21275ddbd60123d929 Mon Sep 17 00:00:00 2001 From: kstdl Date: Mon, 2 Dec 2024 12:35:41 +0100 Subject: [PATCH 3/3] fix: bug after the merge --- libraries/core_libs/consensus/src/final_chain/final_chain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/core_libs/consensus/src/final_chain/final_chain.cpp b/libraries/core_libs/consensus/src/final_chain/final_chain.cpp index d94541b49c..1c07801b9f 100644 --- a/libraries/core_libs/consensus/src/final_chain/final_chain.cpp +++ b/libraries/core_libs/consensus/src/final_chain/final_chain.cpp @@ -572,7 +572,7 @@ std::shared_ptr FinalChain::getBlockHeader(EthBlockNumber n) if (!pbft) { return {}; } - return BlockHeader::fromRLP(dev::RLP(raw)); + return std::make_shared(std::move(raw), *pbft, kBlockGasLimit); } return {}; }