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

Relayer test PRNet #2790

Merged
merged 22 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
551664e
new testnet genesis
MatusKysel Jun 26, 2024
c2d73b8
Merge branch 'develop' into release/v1.9.0-rc
MatusKysel Jun 27, 2024
f0686bb
chore: fixes configuration exception
rattrap Jun 27, 2024
55d3827
chore: fixes taraxa-sign
rattrap Jun 27, 2024
217355a
chore: adjust testnet genesis
kstdl Jun 28, 2024
52a5c0e
chore: update testnet genesis & config. bump path version
kstdl Jul 1, 2024
ecc42cb
fix: null block vote
mfrankovi Jul 2, 2024
3fa9c21
Merge pull request #2799 from Taraxa-project/null_vote_fork
MatusKysel Jul 3, 2024
ee03a8e
chore: fix regossiping for pillarvotes
MatusKysel Jul 3, 2024
d9a242f
Merge pull request #2801 from Taraxa-project/fix-regossiping
MatusKysel Jul 3, 2024
357be88
fix pillar vote logs on startup
MatusKysel Jul 3, 2024
44aeae4
Merge pull request #2802 from Taraxa-project/fix-logs-on-startup
MatusKysel Jul 3, 2024
0a31ee3
chore: increase the version
MatusKysel Jul 3, 2024
2f575d3
Merge pull request #2807 from Taraxa-project/develop
JakubFornadel Jul 17, 2024
917251a
test 16 blocks pillar interval
JakubFornadel Jun 26, 2024
35a7140
fix all edsge case that could make pbdt chain stall
JakubFornadel Jul 11, 2024
818bdc0
adjust pillar votes period
JakubFornadel Jul 11, 2024
5a79874
refactor pillar votes syncing test
JakubFornadel Jul 11, 2024
599e4eb
small fixes
JakubFornadel Jul 11, 2024
d9e926e
use old state (-5 blocks) in pillar blocks
JakubFornadel Jul 18, 2024
9ed9ee8
chore: fix unit tests
mfrankovi Jul 18, 2024
a0b3901
save pillar votes in period data instead of pillar block data. Refact…
JakubFornadel Jul 18, 2024
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20)
# Set current version of the project
set(TARAXA_MAJOR_VERSION 1)
set(TARAXA_MINOR_VERSION 9)
set(TARAXA_PATCH_VERSION 0)
set(TARAXA_PATCH_VERSION 3)
set(TARAXA_VERSION ${TARAXA_MAJOR_VERSION}.${TARAXA_MINOR_VERSION}.${TARAXA_PATCH_VERSION})

# Any time a change in the network protocol is introduced this version should be increased
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@
"generated_rewards": "0x0"
},
"ficus_hf": {
"block_num": 200,
"pillar_blocks_interval": 100,
"pillar_chain_sync_interval": 25,
"pbft_inclusion_delay": 6,
"block_num": 20,
"pillar_blocks_interval": 10,
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@
"ficus_hf": {
"block_num": 1000,
"pillar_blocks_interval": 100,
"pillar_chain_sync_interval": 25,
"pbft_inclusion_delay": 6,
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1652,8 +1652,6 @@
"ficus_hf": {
"block_num": -1,
"pillar_blocks_interval": 100,
"pillar_chain_sync_interval": 25,
"pbft_inclusion_delay": 6,
"bridge_contract_address": "0x0000000000000000000000000000000000000000"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"data_path": "",
"is_light_node": false,
"final_chain_cache_in_blocks": 5,
"report_malicious_behaviour" : true,
"report_malicious_behaviour": true,
"network": {
"rpc": {
"http_port": 7777,
Expand Down Expand Up @@ -38,17 +38,17 @@
"boot_nodes": [
{
"id": "f36f467529fe91a750dfdc8086fd0d2f30bad9f55a5800b6b4aa603c7787501db78dc4ac1bf3cf16e42af7c2ebb53648653013c3da1987494960d751871d598a",
"ip": "boot-node-0.testnet.taraxa.io",
"ip": "boot-node-3.testnet.taraxa.io",
"port": 10002
},
{
"id": "d2d445fc3276bdbf2a07628a484baabf45ccb91d6aa078a0dc3aefc11f1941899a923312ec0e664b8e57b63b774c47a006d9d1d16befd2135dcf76067736c688",
"ip": "boot-node-1.testnet.taraxa.io",
"ip": "boot-node-4.testnet.taraxa.io",
"port": 10002
},
{
"id": "c6e7263f44d88c0d6cc3b0d5ebdc31cf891908e8fa7e545e137d3ed0bfec1810fa24c1379228afbb53df0d59e716e17138115fd096782a84261718ab77665171",
"ip": "boot-node-2.testnet.taraxa.io",
"ip": "boot-node-5.testnet.taraxa.io",
"port": 10002
}
]
Expand Down Expand Up @@ -174,4 +174,4 @@
}
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"level": "0x0",
"pivot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"sig": "0xb7e22d46c1ba94d5e8347b01d137b5c428fcbbeaf0a77fb024cbbf1517656ff00d04f7f25be608c321b0d7483c402c294ff46c49b265305d046a52236c0a363701",
"timestamp": "0x658C3F5E",
"timestamp": "0x66827F92",
"tips": [],
"transactions": []
},
Expand Down Expand Up @@ -105,13 +105,13 @@
"dag_blocks_size": "0x32",
"ghost_path_move_back": "0x0",
"lambda_ms": "0x5DC",
"gas_limit": "0x12C684C0"
"gas_limit": "0x7d2b7500"
},
"dag": {
"block_proposer": {
"shard": 1
},
"gas_limit": "0x1E0A6E0"
"gas_limit": "0x1908B100"
},
"sortition": {
"changes_count_for_average": 10,
Expand Down Expand Up @@ -150,11 +150,9 @@
"generated_rewards": "0x0"
},
"ficus_hf": {
"block_num": -1,
"block_num": 1000,
"pillar_blocks_interval": 100,
"pillar_chain_sync_interval": 25,
"pbft_inclusion_delay": 6,
"bridge_contract_address": "0x0000000000000000000000000000000000000000"
"bridge_contract_address": "0xcAF2b453FE8382a4B8110356DF0508f6d71F22BF"
}
}
}
8 changes: 2 additions & 6 deletions libraries/config/include/config/hardfork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ Json::Value enc_json(const AspenHardfork& obj);
void dec_json(const Json::Value& json, AspenHardfork& obj);

struct FicusHardforkConfig {
uint64_t block_num{0};
uint64_t pillar_blocks_interval{100}; // [periods] how often is the new pillar block created
uint64_t pillar_chain_sync_interval{25}; // [periods] how often is pillar chain checked if it is in sync (has all
// previous pillar blocks and 2t+1 signatures for latest pillar block)
uint64_t pbft_inclusion_delay{
6}; // [periods] how many periods after the pillar block is created it is included in pbft block
uint64_t block_num{10};
uint64_t pillar_blocks_interval{10}; // [periods] how often is the new pillar block created
taraxa::addr_t bridge_contract_address; // [address] of the bridge contract

bool isFicusHardfork(taraxa::PbftPeriod period) const;
Expand Down
26 changes: 9 additions & 17 deletions libraries/config/src/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ bool FicusHardforkConfig::isPillarBlockPeriod(taraxa::PbftPeriod period, bool sk
}

bool FicusHardforkConfig::isPbftWithPillarBlockPeriod(taraxa::PbftPeriod period) const {
return period >= firstPillarBlockPeriod() && period % pillar_blocks_interval == pbft_inclusion_delay;
// Pillar block hash is included in the next pbft block with period +1
return period >= firstPillarBlockPeriod() && period % pillar_blocks_interval == 1;
}

// Returns first pillar block period
Expand All @@ -73,43 +74,34 @@ void FicusHardforkConfig::validate(uint32_t delegation_delay) const {
return;
}

if (block_num % pillar_blocks_interval) {
throw taraxa::ConfigException("ficus_hf.block_num % ficus_hf.pillar_blocks_interval must == 0");
}

if (pillar_blocks_interval <= pillar_chain_sync_interval) {
throw taraxa::ConfigException("ficus_hf.pillar_blocks_interval must be > ficus_hf.pillar_chain_sync_interval");
if (block_num < delegation_delay) {
throw taraxa::ConfigException("ficus_hf.block_num must be >= dpos.delegation_delay");
}

if (pillar_chain_sync_interval <= pbft_inclusion_delay) {
throw taraxa::ConfigException("ficus_hf.pillar_chain_sync_interval must be > ficus_hf.pbft_inclusion_delay");
if (pillar_blocks_interval <= 1) {
throw taraxa::ConfigException("ficus_hf.pillar_blocks_interval must be > 1");
}

if (pbft_inclusion_delay < 1 || pbft_inclusion_delay <= delegation_delay) {
throw taraxa::ConfigException("ficus_hf.pbft_inclusion_delay must be >= 1 && > dpos.delegation_delay");
if (block_num % pillar_blocks_interval) {
throw taraxa::ConfigException("ficus_hf.block_num % ficus_hf.pillar_blocks_interval must == 0");
}
}

Json::Value enc_json(const FicusHardforkConfig& obj) {
Json::Value json(Json::objectValue);
json["block_num"] = dev::toJS(obj.block_num);
json["pillar_blocks_interval"] = dev::toJS(obj.pillar_blocks_interval);
json["pillar_chain_sync_interval"] = dev::toJS(obj.pillar_chain_sync_interval);
json["pbft_inclusion_delay"] = dev::toJS(obj.pbft_inclusion_delay);
json["bridge_contract_address"] = dev::toJS(obj.bridge_contract_address);
return json;
}

void dec_json(const Json::Value& json, FicusHardforkConfig& obj) {
obj.block_num = json["block_num"].isUInt64() ? dev::getUInt(json["block_num"]) : uint64_t(-1);
obj.pillar_blocks_interval = dev::getUInt(json["pillar_blocks_interval"]);
obj.pillar_chain_sync_interval = dev::getUInt(json["pillar_chain_sync_interval"]);
obj.pbft_inclusion_delay = dev::getUInt(json["pbft_inclusion_delay"]);
obj.bridge_contract_address = taraxa::addr_t(json["bridge_contract_address"].asString());
}

RLP_FIELDS_DEFINE(FicusHardforkConfig, block_num, pillar_blocks_interval, pillar_chain_sync_interval,
pbft_inclusion_delay, bridge_contract_address)
RLP_FIELDS_DEFINE(FicusHardforkConfig, block_num, pillar_blocks_interval, bridge_contract_address)

// Json::Value enc_json(const BambooRedelegation& obj) {
// Json::Value json(Json::objectValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FinalChain {
* @param precommit_ext
* @return finalization result
*/
virtual std::future<std::shared_ptr<FinalizationResult const>> finalize(
virtual std::future<std::shared_ptr<const FinalizationResult>> finalize(
PeriodData&& period_data, std::vector<h256>&& finalized_dag_blk_hashes,
std::shared_ptr<DagBlock>&& anchor = nullptr) = 0;

Expand Down Expand Up @@ -270,13 +270,10 @@ class FinalChain {
}
};

std::shared_ptr<FinalChain> NewFinalChain(const std::shared_ptr<DB>& db, const taraxa::FullNodeConfig& config,
const addr_t& node_addr = {});
/** @} */

} // namespace taraxa::final_chain

namespace taraxa {
using final_chain::FinalChain;
using final_chain::NewFinalChain;
} // namespace taraxa
109 changes: 109 additions & 0 deletions libraries/core_libs/consensus/include/final_chain/final_chain_impl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#pragma once

#include "final_chain/cache.hpp"
#include "final_chain/final_chain.hpp"
#include "rewards/rewards_stats.hpp"

namespace taraxa::final_chain {

class FinalChainImpl final : public FinalChain {
std::shared_ptr<DB> db_;
const uint64_t kBlockGasLimit;
StateAPI state_api_;
const bool kLightNode = false;
const uint32_t kMaxLevelsPerPeriod;
rewards::Stats rewards_;

// It is not prepared to use more then 1 thread. Examine it if you want to change threads count
boost::asio::thread_pool executor_thread_{1};

std::atomic<uint64_t> num_executed_dag_blk_ = 0;
std::atomic<uint64_t> num_executed_trx_ = 0;

EthBlockNumber delegation_delay_;

ValueByBlockCache<std::shared_ptr<const BlockHeader>> block_headers_cache_;
ValueByBlockCache<std::optional<const h256>> block_hashes_cache_;
ValueByBlockCache<const SharedTransactions> transactions_cache_;
ValueByBlockCache<std::shared_ptr<const TransactionHashes>> transaction_hashes_cache_;
MapByBlockCache<addr_t, std::optional<const state_api::Account>> accounts_cache_;

ValueByBlockCache<uint64_t> total_vote_count_cache_;
MapByBlockCache<addr_t, uint64_t> dpos_vote_count_cache_;
MapByBlockCache<addr_t, uint64_t> dpos_is_eligible_cache_;

std::condition_variable finalized_cv_;
std::mutex finalized_mtx_;

std::atomic<EthBlockNumber> last_block_number_;

const HardforksConfig& kHardforksConfig;
LOG_OBJECTS_DEFINE

public:
FinalChainImpl(const std::shared_ptr<DB>& db, const taraxa::FullNodeConfig& config, const addr_t& node_addr);

void stop() override;
std::future<std::shared_ptr<const FinalizationResult>> finalize(
PeriodData&& new_blk, std::vector<h256>&& finalized_dag_blk_hashes,
std::shared_ptr<DagBlock>&& anchor = nullptr) override;
EthBlockNumber delegation_delay() const override;
SharedTransaction make_bridge_finalization_transaction();
bool isNeedToFinalize(EthBlockNumber blk_num) const;
std::vector<SharedTransaction> makeSystemTransactions(PbftPeriod blk_num);
std::shared_ptr<const FinalizationResult> finalize_(PeriodData&& new_blk,
std::vector<h256>&& finalized_dag_blk_hashes,
std::shared_ptr<DagBlock>&& anchor);
void prune(EthBlockNumber blk_n) override;
std::shared_ptr<BlockHeader> append_block(DB::Batch& batch, const addr_t& author, uint64_t timestamp,
uint64_t gas_limit, const h256& state_root, u256 total_reward,
const SharedTransactions& transactions = {},
const TransactionReceipts& receipts = {}, const bytes& extra_data = {});
EthBlockNumber last_block_number() const override;
std::optional<EthBlockNumber> block_number(const h256& h) const override;
std::optional<h256> block_hash(std::optional<EthBlockNumber> n = {}) const override;
std::shared_ptr<const BlockHeader> block_header(std::optional<EthBlockNumber> n = {}) const override;
std::optional<TransactionLocation> transaction_location(const h256& trx_hash) const override;
std::optional<TransactionReceipt> transaction_receipt(const h256& trx_h) const override;
uint64_t transactionCount(std::optional<EthBlockNumber> n = {}) const override;
std::shared_ptr<const TransactionHashes> transaction_hashes(std::optional<EthBlockNumber> n = {}) const override;
const SharedTransactions transactions(std::optional<EthBlockNumber> n = {}) const override;
std::vector<EthBlockNumber> withBlockBloom(const LogBloom& b, EthBlockNumber from, EthBlockNumber to) const override;
std::optional<state_api::Account> get_account(const addr_t& addr,
std::optional<EthBlockNumber> blk_n = {}) const override;
void update_state_config(const state_api::Config& new_config) override;
h256 get_account_storage(const addr_t& addr, const u256& key,
std::optional<EthBlockNumber> blk_n = {}) const override;
bytes get_code(const addr_t& addr, std::optional<EthBlockNumber> blk_n = {}) const override;
state_api::ExecutionResult call(const state_api::EVMTransaction& trx,
std::optional<EthBlockNumber> blk_n = {}) const override;
std::string trace(std::vector<state_api::EVMTransaction> trxs, EthBlockNumber blk_n,
std::optional<state_api::Tracing> params = {}) const override;
uint64_t dpos_eligible_total_vote_count(EthBlockNumber blk_num) const override;
uint64_t dpos_eligible_vote_count(EthBlockNumber blk_num, const addr_t& addr) const override;
bool dpos_is_eligible(EthBlockNumber blk_num, const addr_t& addr) const override;
vrf_wrapper::vrf_pk_t dpos_get_vrf_key(EthBlockNumber blk_n, const addr_t& addr) const override;
std::vector<state_api::ValidatorStake> dpos_validators_total_stakes(EthBlockNumber blk_num) const override;
virtual uint256_t dpos_total_amount_delegated(EthBlockNumber blk_num) const override;
std::vector<state_api::ValidatorVoteCount> dpos_validators_vote_counts(EthBlockNumber blk_num) const override;
void wait_for_finalized() override;
uint64_t dpos_yield(EthBlockNumber blk_num) const override;
u256 dpos_total_supply(EthBlockNumber blk_num) const override;
h256 get_bridge_root(EthBlockNumber blk_num) const override;
h256 get_bridge_epoch(EthBlockNumber blk_num) const override;

private:
std::shared_ptr<TransactionHashes> get_transaction_hashes(std::optional<EthBlockNumber> n = {}) const;
const SharedTransactions get_transactions(std::optional<EthBlockNumber> n = {}) const;
std::shared_ptr<const BlockHeader> get_block_header(EthBlockNumber n) const;
std::optional<h256> get_block_hash(EthBlockNumber n) const;
EthBlockNumber last_if_absent(const std::optional<EthBlockNumber>& client_blk_n) const;
static state_api::EVMTransaction to_evm_transaction(const SharedTransaction& trx);
static void append_evm_transactions(std::vector<state_api::EVMTransaction>& evm_trxs, const SharedTransactions& trxs);
BlocksBlooms block_blooms(const h256& chunk_id) const;
static h256 block_blooms_chunk_id(EthBlockNumber level, EthBlockNumber index);
std::vector<EthBlockNumber> withBlockBloom(const LogBloom& b, EthBlockNumber from, EthBlockNumber to,
EthBlockNumber level, EthBlockNumber index) const;
};

} // namespace taraxa::final_chain
8 changes: 8 additions & 0 deletions libraries/core_libs/consensus/include/pbft/pbft_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,13 @@ class PbftManager {
*/
void printVotingSummary() const;

/**
* @brief Creates pillar block (and pillar vote in case node is eligible to vote & is not syncing)
*
* @param period
*/
void processPillarBlock(PbftPeriod period);

std::atomic<bool> stopped_ = true;

// Multiple proposed pbft blocks could have same dag block anchor at same period so this cache improves retrieval of
Expand Down Expand Up @@ -598,6 +605,7 @@ class PbftManager {
bool already_next_voted_null_block_hash_ = false;
bool go_finish_state_ = false;
bool loop_back_finish_state_ = false;
PbftPeriod last_placed_pillar_vote_period_ = 0;

// Used to avoid cyclic logging in voting steps that are called repeatedly
bool printSecondFinishStepInfo_ = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct PillarBlockData {
std::shared_ptr<PillarBlock> block_;
std::vector<std::shared_ptr<PillarVote>> pillar_votes_;

PillarBlockData(std::shared_ptr<PillarBlock> block, std::vector<std::shared_ptr<PillarVote>>&& pillar_votes);
PillarBlockData(std::shared_ptr<PillarBlock> block, const std::vector<std::shared_ptr<PillarVote>>& pillar_votes);
PillarBlockData(const dev::RLP& rlp);
dev::bytes getRlp() const;
Json::Value getJson(bool include_signatures) const;
Expand Down
Loading
Loading