Skip to content

Commit

Permalink
Merge pull request #2690 from Taraxa-project/issue-2688/pillar_block_…
Browse files Browse the repository at this point in the history
…in_pbft_block

anchor pillar block hash into the pbft block
  • Loading branch information
JakubFornadel authored Feb 9, 2024
2 parents 7c3398c + 7b0b245 commit 23f247c
Show file tree
Hide file tree
Showing 16 changed files with 258 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0x84595161401484a000000"
},
"vrf_key": "05fe580fd2d461ee5f762a33bbe669403bb04a851f2e9ed8d2579a9c9b77c3ec",
"bls_key": ""
"vrf_key": "05fe580fd2d461ee5f762a33bbe669403bb04a851f2e9ed8d2579a9c9b77c3ec"
},
{
"address": "0x56e0de6933d9d0453d0363caf42b136eb5854e4e",
Expand All @@ -42,8 +41,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0x84595161401484a000000"
},
"vrf_key": "70d34c86787e5f7bd0f266cad291cb521e23176fa37c6efc034858a1620ac69e",
"bls_key": ""
"vrf_key": "70d34c86787e5f7bd0f266cad291cb521e23176fa37c6efc034858a1620ac69e"
},
{
"address": "0x71bdcbec7e3642782447b0fbf31eed068dfbdbb1",
Expand All @@ -54,8 +52,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0x84595161401484a000000"
},
"vrf_key": "f8d5c00ce9fa3058341e051b36a1e6ccf69df81fb865568b2bf1507d085691e2",
"bls_key": ""
"vrf_key": "f8d5c00ce9fa3058341e051b36a1e6ccf69df81fb865568b2bf1507d085691e2"
}
]
},
Expand Down Expand Up @@ -118,8 +115,8 @@
},
"ficus_hf" : {
"block_num" : 0,
"pillar_block_periods" : 100,
"signatures_check_periods" : 25
"pillar_block_periods" : 25,
"signatures_check_periods" : 10
}
}
}
54 changes: 18 additions & 36 deletions libraries/cli/include/cli/config_jsons/devnet/devnet_genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "05fe580fd2d461ee5f762a33bbe669403bb04a851f2e9ed8d2579a9c9b77c3ec",
"bls_key": ""
"vrf_key": "05fe580fd2d461ee5f762a33bbe669403bb04a851f2e9ed8d2579a9c9b77c3ec"
},
{
"address": "0x56e0de6933d9d0453d0363caf42b136eb5854e4e",
Expand All @@ -42,8 +41,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "70d34c86787e5f7bd0f266cad291cb521e23176fa37c6efc034858a1620ac69e",
"bls_key": ""
"vrf_key": "70d34c86787e5f7bd0f266cad291cb521e23176fa37c6efc034858a1620ac69e"
},
{
"address": "0x71bdcbec7e3642782447b0fbf31eed068dfbdbb1",
Expand All @@ -54,8 +52,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "f8d5c00ce9fa3058341e051b36a1e6ccf69df81fb865568b2bf1507d085691e2",
"bls_key": ""
"vrf_key": "f8d5c00ce9fa3058341e051b36a1e6ccf69df81fb865568b2bf1507d085691e2"
},
{
"address": "0xac24bc60a491bd0c29414e5f34aa6bbd8d4aa499",
Expand All @@ -66,8 +63,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "aa12507d00c992b95e65d80b21fd2db5b48c4f7ff4393064828d1adc930710b4",
"bls_key": ""
"vrf_key": "aa12507d00c992b95e65d80b21fd2db5b48c4f7ff4393064828d1adc930710b4"
},
{
"address": "0x635d3831ad5d1252a2a07f09b8d3539b3af34df8",
Expand All @@ -78,8 +74,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "bd34898ae0080187c408b5724f05682855c4425fda61d332f5f9d746d4eb753a",
"bls_key": ""
"vrf_key": "bd34898ae0080187c408b5724f05682855c4425fda61d332f5f9d746d4eb753a"
},
{
"address": "0x43af71034ed7fd0b54496a30ba4a5889a94e7088",
Expand All @@ -90,8 +85,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "25d35fed93989c40b4e8685d9d7ee02213230221ea9efcbe8cfccfc788670dba",
"bls_key": ""
"vrf_key": "25d35fed93989c40b4e8685d9d7ee02213230221ea9efcbe8cfccfc788670dba"
},
{
"address": "0x4546f088bf636ed4652d1635c98ef5422805dfa3",
Expand All @@ -102,8 +96,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "55c0bd1af84fb793a5dd7b960e330248d8a0acde566922b3e210f43592700dad",
"bls_key": ""
"vrf_key": "55c0bd1af84fb793a5dd7b960e330248d8a0acde566922b3e210f43592700dad"
},
{
"address": "0x8ca042649a263272442bee8b7209fa19426e54c4",
Expand All @@ -114,8 +107,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "33131367e7279ee51c0f26c6f9b6627848f822d134abef21a88be467dfbaae7b",
"bls_key": ""
"vrf_key": "33131367e7279ee51c0f26c6f9b6627848f822d134abef21a88be467dfbaae7b"
},
{
"address": "0x7d7319df8950546850a01a0d793ee602f6eb390f",
Expand All @@ -126,8 +118,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "da63de37c69a59cb3ebbcfb79ef8d561b18b448b544a14438c62cd56bc0a29f5",
"bls_key": ""
"vrf_key": "da63de37c69a59cb3ebbcfb79ef8d561b18b448b544a14438c62cd56bc0a29f5"
},
{
"address": "0x64c171b9845c15c4555f7a4489895f0e687c496c",
Expand All @@ -138,8 +129,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "337178752602a5ca38928bf0d8d434ec653505c92b280b0edab6c39d5e79f4fd",
"bls_key": ""
"vrf_key": "337178752602a5ca38928bf0d8d434ec653505c92b280b0edab6c39d5e79f4fd"
},
{
"address": "0x614c85fad6f17f03949f735e05b1a24c5155b726",
Expand All @@ -150,8 +140,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "ac08e4ca5f1bcdd61dbefa7551ab839bdd4545e59ee8a4ab5d3aabb71104ab73",
"bls_key": ""
"vrf_key": "ac08e4ca5f1bcdd61dbefa7551ab839bdd4545e59ee8a4ab5d3aabb71104ab73"
},
{
"address": "0xeff3dd2b0a6c29146c46ca01764aae0691ee1744",
Expand All @@ -162,8 +151,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "189b05cca0a816a36f977f0541ef7585218b2087f04b23444ab58d0c755adecc",
"bls_key": ""
"vrf_key": "189b05cca0a816a36f977f0541ef7585218b2087f04b23444ab58d0c755adecc"
},
{
"address": "0xe543a20db4fa1820cc9f00144fc402bb1f31aa29",
Expand All @@ -174,8 +162,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "8e95172f90b68ee753132bf6342ee00b398e2417312f610d58c34729ab0608ee",
"bls_key": ""
"vrf_key": "8e95172f90b68ee753132bf6342ee00b398e2417312f610d58c34729ab0608ee"
},
{
"address": "0x211a5ec33fec843b14319bcd62ab30c2a064745e",
Expand All @@ -186,8 +173,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "959551740ff948d9714f15a2bfb2183c4ead897dd79775a0a18488aa8936e2ba",
"bls_key": ""
"vrf_key": "959551740ff948d9714f15a2bfb2183c4ead897dd79775a0a18488aa8936e2ba"
},
{
"address": "0x5354adf587cad5fe74e4912d4b6c1f754538891d",
Expand All @@ -198,8 +184,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "56b7831cb3e35c1d6d1e3f661de2068d6feeaa54074b3e02709a87d7f0d6c72a",
"bls_key": ""
"vrf_key": "56b7831cb3e35c1d6d1e3f661de2068d6feeaa54074b3e02709a87d7f0d6c72a"
},
{
"address": "0x1473a6c154655fdc1f19d98e5823d3bb3f09a895",
Expand All @@ -210,8 +195,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "e774c519814cbc04008aa958932e7adb82ebbbd6ca69089c0a1458ea34fb4299",
"bls_key": ""
"vrf_key": "e774c519814cbc04008aa958932e7adb82ebbbd6ca69089c0a1458ea34fb4299"
},
{
"address": "0x9588f6457d67792f141424983a93978f44331054",
Expand All @@ -222,8 +206,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "1b15b7bef6a1dbe9aeb2792f2e38d6222d31f8c6c15cff1152f258013d70d933",
"bls_key": ""
"vrf_key": "1b15b7bef6a1dbe9aeb2792f2e38d6222d31f8c6c15cff1152f258013d70d933"
},
{
"address": "0xb48da366e19f141f5647dcdb0960eb88719e1c8d",
Expand All @@ -234,8 +217,7 @@
"delegations": {
"0x7e4aa664f71de4e9d0b4a6473d796372639bdcde": "0xd3c21bcecceda1000000"
},
"vrf_key": "37bf145ac98e7de7db6e5b933e72737fbf190fd4fb1d193b15cf8b00db30ba30",
"bls_key": ""
"vrf_key": "37bf145ac98e7de7db6e5b933e72737fbf190fd4fb1d193b15cf8b00db30ba30"
}
]
},
Expand Down
6 changes: 4 additions & 2 deletions libraries/config/src/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ RLP_FIELDS_DEFINE(FicusHardforkConfig, block_num, pillar_block_periods, pillar_c
Json::Value enc_json(const HardforksConfig& obj) {
Json::Value json(Json::objectValue);
json["fix_redelegate_block_num"] = dev::toJS(obj.fix_redelegate_block_num);
json["phalaenopsis_hf_block_num"] = dev::toJS(obj.phalaenopsis_hf_block_num);
json["initial_validators"] = Json::Value(Json::arrayValue);
for (const auto& v : obj.redelegations) {
json["redelegations"].append(enc_json(v));
Expand All @@ -87,6 +88,7 @@ Json::Value enc_json(const HardforksConfig& obj) {
void dec_json(const Json::Value& json, HardforksConfig& obj) {
obj.fix_redelegate_block_num =
json["fix_redelegate_block_num"].isUInt64() ? dev::getUInt(json["fix_redelegate_block_num"]) : uint64_t(-1);
obj.phalaenopsis_hf_block_num = dev::getUInt(json["phalaenopsis_hf_block_num"]);

const auto& redelegations_json = json["redelegations"];
obj.redelegations = std::vector<Redelegation>(redelegations_json.size());
Expand All @@ -108,5 +110,5 @@ void dec_json(const Json::Value& json, HardforksConfig& obj) {
dec_json(json["ficus_hf"], obj.ficus_hf);
}

RLP_FIELDS_DEFINE(HardforksConfig, fix_redelegate_block_num, redelegations, rewards_distribution_frequency, magnolia_hf,
aspen_hf, ficus_hf)
RLP_FIELDS_DEFINE(HardforksConfig, fix_redelegate_block_num, phalaenopsis_hf_block_num, redelegations,
rewards_distribution_frequency, magnolia_hf, aspen_hf)
17 changes: 10 additions & 7 deletions libraries/core_libs/consensus/include/pbft/pbft_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ class PbftManager {
public:
using time_point = std::chrono::system_clock::time_point;

PbftManager(const PbftConfig &conf, const blk_hash_t &dag_genesis_block_hash, addr_t node_addr,
std::shared_ptr<DbStorage> db, std::shared_ptr<PbftChain> pbft_chain,
std::shared_ptr<VoteManager> vote_mgr, std::shared_ptr<DagManager> dag_mgr,
std::shared_ptr<TransactionManager> trx_mgr, std::shared_ptr<FinalChain> final_chain, secret_t node_sk);
PbftManager(const GenesisConfig &genesis_config, addr_t node_addr, std::shared_ptr<DbStorage> db,
std::shared_ptr<PbftChain> pbft_chain, std::shared_ptr<VoteManager> vote_mgr,
std::shared_ptr<DagManager> dag_mgr, std::shared_ptr<TransactionManager> trx_mgr,
std::shared_ptr<FinalChain> final_chain,
std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_mgr, secret_t node_sk);
~PbftManager();
PbftManager(const PbftManager &) = delete;
PbftManager(PbftManager &&) = delete;
Expand Down Expand Up @@ -141,11 +142,12 @@ class PbftManager {
* @param prev_blk_hash previous PBFT block hash
* @param anchor_hash proposed DAG pivot block hash for finalization
* @param order_hash the hash of all DAG blocks include in the PBFT block
* @param pillar_block_hash optional anchored pillar block hash
* @return optional<pair<PBFT block, PBFT block reward votes>>
*/
std::optional<std::pair<std::shared_ptr<PbftBlock>, std::vector<std::shared_ptr<PbftVote>>>> generatePbftBlock(
PbftPeriod propose_period, const blk_hash_t &prev_blk_hash, const blk_hash_t &anchor_hash,
const blk_hash_t &order_hash);
const blk_hash_t &order_hash, const std::optional<blk_hash_t> pillar_block_hash);

/**
* @brief Get current total DPOS votes count
Expand Down Expand Up @@ -252,7 +254,7 @@ class PbftManager {
* @brief Get PBFT committee size
* @return PBFT committee size
*/
size_t getPbftCommitteeSize() const { return config_.committee_size; }
size_t getPbftCommitteeSize() const { return kGenesisConfig.pbft.committee_size; }

/**
* @brief Test/enforce broadcastVotes() to actually send votes
Expand Down Expand Up @@ -525,6 +527,7 @@ class PbftManager {
std::weak_ptr<Network> network_;
std::shared_ptr<TransactionManager> trx_mgr_;
std::shared_ptr<FinalChain> final_chain_;
std::shared_ptr<pillar_chain::PillarChainManager> pillar_chain_mgr_;

const addr_t node_addr_;
const secret_t node_sk_;
Expand Down Expand Up @@ -567,7 +570,7 @@ class PbftManager {

const blk_hash_t dag_genesis_block_hash_;

const PbftConfig &config_;
const GenesisConfig &kGenesisConfig;

std::condition_variable stop_cv_;
std::mutex stop_mtx_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class PillarChainManager {
*/
void createPillarBlock(const std::shared_ptr<final_chain::FinalizationResult>& block_data);

/**
* @brief Generate and place pillar vote for provided pillar_block_hash in case the whole pillar block is present and
* valid
*
* @param pillar_block_hash
* @param node_sk
* @return true if vote placed, otherwise false
*/
bool genAndPlacePillarVote(const PillarBlock::Hash& pillar_block_hash, const secret_t& node_sk);

/**
* @brief Check if pillar chain is synced - node has all previous pillar blocks(+votes) and there is 2t+1
* votes for latest pillar block. If not, request them
Expand Down Expand Up @@ -87,6 +97,11 @@ class PillarChainManager {
*/
bool pushPillarBlock(const PillarBlockData& pillarBlockData);

/**
* @return current pillar block
*/
std::shared_ptr<PillarBlock> getCurrentPillarBlock() const;

/**
* @brief Get all pillar votes for specified pillar block
*
Expand Down
Loading

0 comments on commit 23f247c

Please sign in to comment.