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: diff --git a/libraries/core_libs/consensus/include/final_chain/data.hpp b/libraries/core_libs/consensus/include/final_chain/data.hpp index d6abfd76d0..5e71c3c4c9 100644 --- a/libraries/core_libs/consensus/include/final_chain/data.hpp +++ b/libraries/core_libs/consensus/include/final_chain/data.hpp @@ -31,6 +31,7 @@ struct BlockHeaderData { LogBloom log_bloom; uint64_t gas_used = 0; u256 total_reward; + uint64_t size = 0; dev::bytes serializeForDB() const; @@ -46,12 +47,15 @@ struct BlockHeader : BlockHeaderData { static h256 const& unclesHash(); - static Nonce const& nonce(); + static const Nonce& nonce(); - static u256 const& difficulty(); + static const u256& difficulty(); static h256 const& mixHash(); + static std::shared_ptr fromRLP(const dev::RLP& rlp); + + void ethereumRlp(dev::RLPStream& encoding) const; dev::bytes ethereumRlp() const; h256 hash; @@ -60,6 +64,8 @@ struct BlockHeader : BlockHeaderData { uint64_t timestamp = 0; EthBlockNumber number = 0; bytes extra_data; + + HAS_RLP_FIELDS }; static constexpr auto c_bloomIndexSize = 16; diff --git a/libraries/core_libs/consensus/src/final_chain/data.cpp b/libraries/core_libs/consensus/src/final_chain/data.cpp index 14c62fde62..8fc6cd1876 100644 --- a/libraries/core_libs/consensus/src/final_chain/data.cpp +++ b/libraries/core_libs/consensus/src/final_chain/data.cpp @@ -32,20 +32,37 @@ void BlockHeader::setFromPbft(const PbftBlock& pbft) { h256 const& BlockHeader::unclesHash() { return EmptyRLPListSHA3(); } -Nonce const& BlockHeader::nonce() { return EmptyNonce(); } +const Nonce& BlockHeader::nonce() { return EmptyNonce(); } -u256 const& BlockHeader::difficulty() { return ZeroU256(); } +const u256& BlockHeader::difficulty() { return ZeroU256(); } -h256 const& BlockHeader::mixHash() { return ZeroHash(); } +const h256& BlockHeader::mixHash() { return ZeroHash(); } -dev::bytes BlockHeader::ethereumRlp() const { - dev::RLPStream rlp_strm; - util::rlp_tuple(rlp_strm, parent_hash, BlockHeader::unclesHash(), author, state_root, transactions_root, +std::shared_ptr BlockHeader::fromRLP(const dev::RLP& rlp) { + auto ret = std::make_shared(); + ret->rlp(rlp); + dev::RLPStream encoding; + ret->ethereumRlp(encoding); + ret->size = encoding.out().size(); + return ret; +} + +void BlockHeader::ethereumRlp(dev::RLPStream& encoding) const { + util::rlp_tuple(encoding, parent_hash, BlockHeader::unclesHash(), author, state_root, transactions_root, receipts_root, log_bloom, BlockHeader::difficulty(), number, gas_limit, gas_used, timestamp, extra_data, BlockHeader::mixHash(), BlockHeader::nonce()); - return rlp_strm.invalidate(); } +dev::bytes BlockHeader::ethereumRlp() const { + dev::RLPStream encoding; + ethereumRlp(encoding); + return encoding.invalidate(); +} + +// 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) + RLP_FIELDS_DEFINE(LogEntry, address, topics, data) LogBloom LogEntry::bloom() const { diff --git a/libraries/core_libs/network/rpc/eth/Eth.cpp b/libraries/core_libs/network/rpc/eth/Eth.cpp index dcd9a24496..e5f57c2be9 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; }